Okta Terraform Provider

repository·master·Indexed 43 days ago

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

A Terraform plugin for full lifecycle management of Okta resources using HCL. It provides resources and data sources to manage users, policies, authorization servers, and various application types including OIDC (okta_app_oauth), SAML (okta_app_saml), SWA (okta_app_swa), and Basic Auth (okta_app_basic_auth).

Tokens
217.7K
Snippets
694
Records
980
Agent score
55%

What's inside Okta Terraform Provider

  1. Manage OAuth client secrets securely

    master

    When managing OAuth client secrets, you have three options depending on your Terraform version and security requirements:

    1. client_basic_secret (Sensitive): The standard way to provide a secret. Warning: This secret will be stored in plain text in your Terraform state file.
    2. client_basic_secret_wo (Sensitive, Write-Only): Available for Terraform 1.11+. This is the recommended approach as it does not persist the secret in the Terraform state file. You can use client_basic_secret_wo_version (a number) to trigger an update when changing the secret.
    3. omit_secret (Boolean): If set to true, the provider will not manage the client_secret value in state. This prevents the auto-generated secret from being persisted in the client_secret attribute.

    Important: You can specify either client_basic_secret or client_basic_secret_wo, but not both. If you change omit_secret from false to true, the secret is dropped from state. If you change it from true to false, the application will be recreated because a new secret must be generated to be stored in state.

  2. Manage Okta Resource Sets with okta_resource_set

    master
    The okta_resource_set resource allows you to create and manipulate Resource Sets in Okta. Resource Sets act as custom collections of resources, enabling you to group specific Okta entities for more efficient management and policy application. For detailed information on the underlying API capabilities, refer to the Okta documentation for resource set operations.
  3. Manage Profile Enrollment Policy Rules with okta_policy_rule_profile_enrollment

    master

    The okta_policy_rule_profile_enrollment resource is used to update the default rule of a Profile Enrollment Policy.

    Important Constraints:

    • Identity Engine Only: This feature is only available as part of the Okta Identity Engine (OIE).
    • Single Rule Limitation: A profile enrollment policy is limited to exactly one default rule. This resource does not create a new rule; instead, it allows you to update the existing default rule for a given policy.

    To use this resource, you must have an existing okta_policy_profile_enrollment policy ID.

    resource "okta_policy_rule_profile_enrollment" "example" {
      policy_id           = okta_policy_profile_enrollment.example.id
      inline_hook_id      = okta_inline_hook.example.id
      target_group_id     = okta_group.example.id
      unknown_user_action = "REGISTER"
      email_verification  = true
      access              = "ALLOW"
      profile_attributes {
        name     = "email"
        label    = "Email"
        required = true
      }
      profile_attributes {
        name     = "name"
        label    = "Name"
        required = true
      }
      profile_attributes {
        name     = "t-shirt"
        label    = "T-Shirt Size"
        required = false
      }
    }
  4. Configure Dynamic IdP Routing

    master

    You can configure a rule to select an IdP dynamically using Okta Expression Language. This is achieved by setting selection_type to DYNAMIC and providing a provider_expression.

    When selection_type is DYNAMIC:

    • provider_expression: An Okta Expression Language expression evaluated against the Login Context (e.g., login.identifier.substringAfter('@')).
    • property_name: The IdP property to match the evaluated expression against.
    • should_fall_back_to_okta: A boolean specifying whether to fall back to Okta if authentication with the matched IdP fails. Defaults to false.
    resource "okta_policy_rule_idp_discovery" "dynamic_example" {
      policy_id           = data.okta_policy.idp_discovery_policy.id
      name                = "dynamic-idp-routing"
      network_connection  = "ANYWHERE"
      priority            = 2
      status              = "ACTIVE"
      selection_type      = "DYNAMIC"
      provider_expression = "login.identifier.substringAfter('@')"
    }
  5. Use Okta Identity Engine (OIE) in MFA Policies

    master

    To implement an OIE-based MFA policy, set is_oie = true. This allows you to use OIE-specific authenticators such as okta_verify and custom_app.

    For custom_app, you must provide a list of maps containing the id (the custom app ID) and the enroll status. For external_idps, you can define multiple external identity providers with their respective enrollment settings.

    resource "okta_policy_mfa" "oie_example" {
      name        = "MFA Policy OIE"
      status      = "ACTIVE"
      description = "Example MFA policy that uses Okta Identity Engine (OIE) with authenticators"
      is_oie      = true
    
      okta_password = {
        enroll = "REQUIRED"
      }
    
      okta_verify = {
        enroll = "REQUIRED"
      }
    
      custom_app = [
        { "enroll" : "OPTIONAL", "id" : "aut123456789abcdef" },
        { "enroll" : "OPTIONAL", "id" : "aut123456789ghijkl" }
      ]
    
      groups_included = ["${data.okta_group.everyone.id}"]
    }
  6. Note: Managing okta_app_oauth_redirect_uri

    master
    When using okta_app_oauth_redirect_uri to decentralize redirect URI configuration, be aware that the Okta API does not allow this field to be null. You must set a redirect URI in your application and ignore changes to this attribute. The provider follows Terraform best practices by detecting configuration drift, but drift detection is limited by the API's inability to handle null values for this field.
  7. Use Password Import Inline Hooks for user creation

    master

    You can trigger a Password Import Inline Hook to handle the verification of a user's password during their first login. This is useful for importing existing passwords from another store directly into Okta.

    Requirements and Constraints:

    • When using password_inline_hook, do not specify the password field.
    • When updating a user with a password hook, the user must be in the STAGED status.
    • The password_inline_hook field accepts a string specifying the hook to be triggered.
    resource "okta_user" "test2" {
      first_name           = "John"
      last_name            = "Smith"
      login                = "example@example.com"
      email                = "example@example.com"
      password_inline_hook = "default"
    }
  8. Retrieve federated claims with okta_app_federated_claim

    master

    Use the okta_app_federated_claim data source to retrieve information about a federated claim configured for an Okta application. Federated claims allow you to add custom claims to tokens produced for an application using Okta Expression Language.

    To use this data source, you must provide the app_id of the application and the unique id of the federated claim.

    data "okta_app_federated_claim" "example" {
      app_id = "0oa1234567890abcdef"
      id     = "ofcu234567890abcdef"
    }
    
    output "claim_expression" {
      value = data.okta_app_federated_claim.example.expression
    }
  9. Manage Okta API tokens with okta_api_token

    master

    The okta_api_token resource allows you to manage existing Okta API tokens and their associated network restrictions.

    CRITICAL LIMITATION: Import-Only Resource API tokens cannot be created via Terraform because they are generated through the Okta Admin Console or the Okta API. You must use this resource to import an existing token and then manage its configuration (such as network restrictions) via Terraform.

    WARNING: Destruction Behavior When this resource is destroyed in Terraform, the API token will be revoked and will no longer work for authentication.

    resource "okta_api_token" example{
      id = "00T1fxzubpqiepH11d38"
      name = "token-api-token-test"
      user_id = "00unkw1sfbTw08c0g1d7"
      network{
        connection = "ZONE"
        exclude =["nzonkw1sfwwi79Hat2d7"]
      }
      client_name = "Okta API"
    }
  10. Manage the Post Auth Session Policy Rule

    master

    The okta_post_auth_session_policy_rule resource manages the single modifiable (non-default) rule within a Post Auth Session Policy.

    CRITICAL LIMITATION: This resource cannot be created or deleted via Terraform because the rule is pre-provisioned by Okta. You can only import the existing rule into your state and then update its configuration.

    • Create: Attempting to create this resource will result in an error providing the necessary import command.
    • Delete: Deleting the resource in Terraform removes it from your state only; the rule remains active in Okta.