hashicorp / terraform-provider-azuread

Terraform provider for Azure Active Directory
https://registry.terraform.io/providers/hashicorp/azuread/latest/docs
Mozilla Public License 2.0
415 stars 280 forks source link

azuread_application_identifier_uri without verified domain not applying on first attempt #1392

Open nbaju1 opened 1 month ago

nbaju1 commented 1 month ago

Community Note

Terraform (and AzureAD Provider) Version

Terraform v1.8.1 AzureAD Provider: 2.49.0

Affected Resource(s)

Terraform Configuration Files

(Note that I use the CDKTF for Python, so the example is a manually written mock-up of the actual configuration)

resource "azuread_application" "example" {
  display_name = "example"

  lifecycle {
    ignore_changes = [
      identifier_uris,
    ]
  }
}

resource "azuread_service_principal" "example_sp" {
  client_id = azuread_application.example.client_id
}

resource "azuread_application_identifier_uri" "example_uri" {
  application_id = azuread_application.example.id
  identifier_uri = "https://non-verified-host.com"
}

Debug Output

β”‚ Error: creating Application IdentifierUri (Application ID: <redacted>", IdentifierUri ID: "<redacted>"): ApplicationsClient.BaseClient.Patch(): unexpected status 400 with OData error: HostNameNotOnVerifiedDomain: Values of identifierUris property must use a verified domain of the organization or its subdomain: 'https://non-verified-host.com'
β”‚ 
β”‚   with azuread_application_identifier_uri.example_uri,
β”‚   on cdk.tf.json line 90, in resource.azuread_application_identifier_uri.example_uri:
β”‚   90:       }
β”‚ 
β”‚ creating Application IdentifierUri (Application ID:
β”‚ "<redacted>", IdentifierUri ID:
β”‚ "<redacted>"):
β”‚ ApplicationsClient.BaseClient.Patch(): unexpected status 400 with OData
β”‚ error: HostNameNotOnVerifiedDomain: Values of identifierUris property must
β”‚ use a verified domain of the organization or its subdomain:
β”‚ 'https://non-verified-host.com'

Expected Behavior

Applies identifier URI after application creation.

Actual Behavior

Creates application, but fails on applying the identifier URI.

Steps to Reproduce

  1. terraform plan
  2. terraform apply

Workarounds

nbaju1 commented 1 month ago

Just realized that the first workaround is basically the same as the second. Creating the URI resource after the service principal is created will allow the unverified domain. Which is most likely due to identifierUris being used for both application registration identifier and SAML SSO config, where there is much more freedom in the syntax of the identifier compared to the identifier on the application registration. So I assume this won't work at all for bare application registrations.