Auth0 Terraform Provider

repository·main·Indexed 42 days ago

https://github.com/auth0/terraform-provider-auth0

The official Terraform plugin for managing Auth0 tenant configurations as code. It allows developers to manage identity and access management, including resources such as Auth0 Actions and Action Modules, using Terraform version >= 1.0.0.

Tokens
163K
Snippets
427
Records
632
Agent score
48%

What's inside Auth0 Terraform Provider

  1. Manage Rate Limit Policies with auth0_rate_limit_policy

    main

    The auth0_rate_limit_policy resource allows you to manage Rate Limit Policies for the Authentication API. This enables per-application (client-ID-based) throttling, ensuring that traffic spikes from a single application are isolated and do not exhaust the tenant's global rate limit.

    Note: This feature is currently in Early Access (EA) only.

    resource "auth0_rate_limit_policy" "noisy_app" {
      resource          = "oauth_authentication_api"
      consumer          = "client"
      consumer_selector = "client_id:abc123"
    
      configuration {
        action       = "redirect"
        limit        = 1000
        redirect_uri = "https://example.com/rate-limited"
      }
    }
  2. Manage Auth0 tenants with auth0_tenant

    main

    The auth0_tenant resource allows you to manage the configuration of an existing Auth0 tenant. You can use it to set logos, support contact information, error pages, and default tenant behaviors like session lifetimes and enabled locales.

    Important Limitation: You cannot create new tenants using this resource. It can only manage settings for a tenant that has already been created via the Auth0 dashboard.

    resource "auth0_tenant" "my_tenant" {
      friendly_name           = "Tenant Name"
      picture_url             = "http://example.com/logo.png"
      support_email           = "support@example.com"
      support_url             = "http://example.com/support"
      allowed_logout_urls     = ["http://example.com/logout"]
      session_lifetime        = 8760
      sandbox_version         = "22"
      enabled_locales         = ["en"]
      default_redirection_uri = "https://example.com/login"
    
      flags {
        disable_clickjack_protection_headers   = true
        enable_public_signup_user_exists_error = true
        use_scope_descriptions_for_consent     = true
        no_disclose_enterprise_connections     = false
        disable_management_api_sms_obfuscation = false
        disable_fields_map_fix                 = false
      }
    
      session_cookie {
        mode = "non-persistent"
      }
    
      sessions {
        oidc_logout_prompt_enabled = false
    
        # Anonymous Sessions is an Early Access feature.
        anonymous {
          lifetime_in_minutes = 43200
          activate_cookie     = true
        }
      }
    
      error_page {
        html          = "<html></html>"
        show_log_link = false
        url           = "https://example.com/error"
      }
    
      # Requires the country codes feature flag to be enabled on the tenant.
      # Remove this block entirely to disable filtering.
      country_codes {
        list = ["US", "CA"]
        mode = "allow"
      }
    }
  3. Manage individual role permissions with auth0_role_permission

    main

    The auth0_role_permission resource allows you to manage a single permission assignment for a specific role (a 1-to-1 relationship).

    Important Usage Note: This resource appends a permission to a role. It should not be used in conjunction with the auth0_role_permissions resource (which manages the entire set of permissions for a role) for the same role_id, as this can cause configuration conflicts.

    resource "auth0_role_permission" "my_role_perm" {
      for_each = toset(local.scopesList)
    
      role_id                    = auth0_role.my_role.id
      resource_server_identifier = auth0_resource_server.resource_server.identifier
      permission                 = each.value
    }
  4. Manage Auth0 Action secrets securely with secrets_wo

    main

    When managing secrets for an Auth0 action, you have two options. For better security, use secrets_wo instead of secrets.

    secrets_wo (Write-Only Secrets)

    secrets_wo allows you to provide secret values that are not stored in your Terraform state. This prevents sensitive information from being persisted in plain text.

    • Behavior: Adding, renaming, or removing an entry is applied automatically.
    • Updating Values: Because values are not tracked in state, changing only the value of an existing secret will not be detected by Terraform. To push a value-only change, you must increment the secrets_wo_version attribute.
    • Removal: To remove all secrets, delete the secrets_wo blocks and the secrets_wo_version attribute.
    • Ordering: This is an ordered list; reordering blocks is treated as a change.
    • Conflict: secrets_wo conflicts with the standard secrets block.

    secrets (Standard Secrets)

    • Warning: Secret values are persisted in Terraform state as plain text.
    • Behavior: Partial management is not supported. If the secret block is edited, the entire object is re-provisioned.
  5. Configure JWT and Refresh Token settings for CIMD clients

    main

    When using auth0_client_cimd, you can fine-tune the security and lifecycle of issued tokens using nested blocks.

    JWT Configuration (jwt_configuration)

    Controls the JSON Web Tokens issued for the client.

    • alg: Signing algorithm. Supports RS256, RS512, and PS256 (asymmetric only).
    • lifetime_in_seconds: Validity duration of the JWT.

    Refresh Token Configuration (refresh_token)

    Controls the lifecycle of refresh tokens.

    • rotation_type: Set to rotating or non-rotating.
    • expiration_type: Must be expiring for CIMD clients.
    • token_lifetime: Absolute lifetime in seconds.
    • idle_token_lifetime: Seconds after which an inactive token expires.
    • infinite_idle_token_lifetime: Must be false for CIMD clients.
    • leeway: Seconds allowed for token reuse without triggering detection.
  6. Handle sensitive values in generated Terraform config

    main

    The auto-generation process cannot export sensitive values such as secrets, keys, or API keys. In the generated auth0_generated.tf file, these properties will be set to null and marked with a # sensitive comment.

    If you intend to apply this configuration to a different tenant, you must manually replace these null values with the appropriate credentials for the target environment.

    Example of sensitive fields in auth0_generated.tf:

    resource "auth0_email_provider" "email_provider" {
      default_from_address = "mailing-daemon@travel0.com"
      enabled              = true
      name                 = "smtp"
      credentials {
        access_key_id              = null # sensitive
        api_key                    = null # sensitive
      }
    }
    # __generated__ by Terraform from "52745e4d-278c-4b6b-8cac-a27e457215d6"
    resource "auth0_email_provider" "email_provider" {
      default_from_address = "mailing-daemon@travel0.com"
      enabled              = true
      name                 = "smtp"
      credentials {
        access_key_id              = null # sensitive
        api_key                    = null # sensitive
      }
    }
  7. Configure the `auth0_email_provider` resource

    main

    The auth0_email_provider resource allows you to route Auth0 authentication workflows (like password resets and account verification) through a high-volume email service.

    Important Constraints:

    • You can manage a maximum of 1 email provider per Auth0 tenant. It is recommended not to attempt creating multiple providers on the same tenant.
    • If you are configuring a custom email provider, you must first create an auth0_action with custom-email-provider as one of its supported_triggers.
    resource "auth0_email_provider" "example" {
      name                 = "ses"
      enabled              = true
      default_from_address = "accounts@example.com"
    
      credentials {
        access_key_id     = "AKIAXXXXXXXXXXXXXXXX"
        secret_access_key = "7e8c2148xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        region            = "us-east-1"
      }
    }
  8. Manage customized prompt screens with auth0_prompt_screen_partial

    main

    The auth0_prompt_screen_partial resource allows you to customize the sign-up and login experience by injecting custom HTML content, form elements, CSS, or JavaScript into specific parts of the Auth0 Universal Login screens.

    Important Usage Note

    This resource appends a specific prompt screen to the existing list of prompt screens. It is designed for incremental customization.

    Warning: Do not use auth0_prompt_screen_partial in conjunction with the auth0_prompt_screen_partials (plural) resource when managing the same prompt, as auth0_prompt_screen_partials manages the complete set of screens and they may conflict.

    resource "auth0_prompt_screen_partial" "login" {
      prompt_type = "login"
      screen_name = "login"
      insertion_points {
        form_content_start = "<div>Form Content Start</div>"
        form_content_end   = "<div>Form Content End</div>"
      }
    }
  9. How documentation is generated for the Auth0 Terraform Provider

    main

    The provider uses an automated pipeline to generate its reference documentation in the docs/ directory. Documentation is derived from the source code schema and HCL examples.

    Key components of the generation process:

    • Schema Descriptions: The Description fields within the resource/data-source schema files (e.g., internal/auth0/<name>/resource.go) are used as the primary source for documentation text. Markdown is supported within these fields.
    • Usage Examples: The HCL files located in examples/resources/<name>/resource.tf or examples/data-sources/<name>/data-source.tf are embedded into the generated documentation as usage examples.
    • Structural Overrides: Optional structural overrides can be applied using templates located in templates/resources/<name>.md.tmpl.

    Important: Never edit files in the docs/ directory manually, as they are auto-generated and will be overwritten by the pipeline.

  10. Access nested schemas for `auth0_resource_server`

    main

    The auth0_resource_server data source provides access to complex nested objects. Key nested schemas include:

    • access_token: Configuration for issued tokens. Contains claims_mapping, which in turn contains custom_claims (each with expression and name).
    • scopes: A list of objects containing name and description for each permission.
    • proof_of_possession: Settings for PoP, including mechanism, required, and required_for.
    • subject_type_authorization: Authorization policies for different flows, containing nested anonymous_user, client, and user objects, each with a policy string.
    • token_encryption: Configuration for JWE, including format and encryption_key (which contains algorithm, kid, name, and pem).
    • authorization_details: Contains type and disable status.
  11. Configure Social Connection strategies

    main

    The auth0_connection resource supports various social identity providers. Common strategies include:

    • Google OAuth2: strategy = "google-oauth2". Requires client_id and client_secret.
    • Facebook: strategy = "facebook". Requires client_id and client_secret.
    • Apple: strategy = "apple". Requires client_id, client_secret, team_id, and key_id.
    • LinkedIn: strategy = "linkedin". Requires client_id and client_secret.
    • GitHub: strategy = "github". Requires client_id and client_secret.
    • Twitter: strategy = "twitter" (via OAuth2).

    Most social connections allow setting set_user_root_attributes (e.g., on_each_login or on_first_login) and non_persistent_attrs to manage how user profile data is stored.

    # Example: Google OAuth2
    resource "auth0_connection" "google_oauth2" {
      name     = "Google-OAuth2-Connection"
      strategy = "google-oauth2"
    
      options {
        client_id                = "<client-id>"
        client_secret            = "<client-secret>"
        allowed_audiences        = ["example.com", "api.example.com"]
        scopes                   = ["email", "profile", "gmail", "youtube"]
        set_user_root_attributes = "on_each_login"
        non_persistent_attrs     = ["ethnicity", "gender"]
      }
    }
    
    # Example: GitHub
    resource "auth0_connection" "github" {
      name     = "GitHub-Connection"
      strategy = "github"
    
      options {
        client_id     = "<client-id>"
        client_secret = "<client-secret>"
        scopes = [
          "public_profile",
          "email",
          "groups_access_member_info",
          "user_birthday"
        ]
        set_user_root_attributes = "on_each_login"
        non_persistent_attrs     = ["ethnicity", "gender"]
      }
    }