okta / terraform-provider-okta

A Terraform provider to manage Okta resources, enabling infrastructure-as-code provisioning and management of users, groups, applications, and other Okta objects.
https://registry.terraform.io/providers/okta/okta
Mozilla Public License 2.0
248 stars 201 forks source link

Allow okta_email_domain to use brand_name or brand_id #1741

Open NickSpaghetti opened 9 months ago

NickSpaghetti commented 9 months ago

I am currently working on implementing an existing brand in our okta tenants and I came across an issue with a cycle reference error when I tried to use okta_brand.foo.id inside of okta_email_domain.foo_brand_email_domain and okta_brand.foo_brand inside of okta_email_domain.foo_brand_email_domain for the brand_id. My workaround was to look up all of our brands store them in a map by the brand name and look up the key in the map. Would it be possible to allow okta_email_domain to use brand_name or brand_id?

locals {
  brand_name_by_brand_map = {for brand in data.okta_brands.all_brands.brands : brand.name => brand}
 }

data "okta_app" "foo_brand_default_app" {
  count = var.brand_default_app_name != "" ? 1 : 0
  label = var.brand_default_app_name
}

#have to look up all the brands to avoid a circular reference when a brand resource requires a brand_id and that brand also requires the resource_id
data "okta_brands" "all_brands" {
}

resource "okta_email_domain" "foo_brand_email_domain" {
  brand_id     = lookup(local.brand_name_by_brand_map,var.brand_name).id
  domain       = var.okta_brand_email_domain.domain_name
  display_name = var.okta_brand_email_domain.display_name
  user_name    = var.okta_brand_email_domain.email_user_name
}

resource "okta_brand" "foo" {
  name                           = var.brand_name
  custom_privacy_policy_url      = var.brand_custom_private_policy_url
  agree_to_custom_privacy_policy = true
  email_domain_id = okta_email_domain.foo_brand_email_domain.id
  default_app_app_instance_id = data.okta_app.foo_brand_default_app[0].id
}
duytiennguyen-okta commented 9 months ago

OKTA internal reference https://oktainc.atlassian.net/browse/OKTA-654741