microsoft / terraform-provider-power-platform

Power Platform Terraform Provider
https://registry.terraform.io/providers/microsoft/power-platform/latest/docs
MIT License
35 stars 13 forks source link

Error 409 Conflict - DomainNameAlreadyInUse- when using custom domain name #505

Closed Fiury00 closed 3 weeks ago

Fiury00 commented 3 weeks ago

Describe the bug

After creating a PA environment with custom domain name when you run TF for the next time it show some changes `

# module.pa_env.powerplatform_environment.main will be updated in-place
~ resource "powerplatform_environment" "main" {
  ~ billing_policy_id    = null -> (known after apply)
  ~ cadence              = "Frequent" -> (known after apply)
  ~ dataverse            = {
      ~ administration_mode_enabled  = false -> (known after apply)
      ~ background_operation_enabled = true -> (known after apply)
      + linked_app_id                = (known after apply)
      + linked_app_type              = (known after apply)
      + linked_app_url               = (known after apply)
      ~ security_group_id            = "00000000-0000-0000-0000-000000000000" -> "0000000-0000-0000-0000-000000000000"
      ~ unique_name                  = "***********************" -> (known after apply)
      ~ url                          = "https://xxxyyy.crm4.dynamics.com/" -> (known after apply)
      ~ version                      = "9.2.24095.200" -> (known after apply)
        # (4 unchanged attributes hidden)
    }
  ~ description          = null -> (known after apply)
  ~ environment_group_id = null -> (known after apply)
    id                   = "**************************"
    # (4 unchanged attributes hidden)
}`

and when you press yes it throws 409 Conflict error: Unexpected HTTP status code. Expected: [200], received: [409] 409 Conflict | {"error":{"code":"DomainNameAlreadyInUse","message":"The specified domain name with a value of 'xxxyyy' is already in use. Please select a different value. If a domain name was recently │ changed, the previous domain name will not be available for use for up to 24 hours after the change.","detailUrlType":"NotSpecified"}}

Sample Terraform Code

terraform {
  required_providers {
    powerplatform = {
      source  = "microsoft/power-platform"
    }

    azurerm = {
      source                = "hashicorp/azurerm"
      configuration_aliases = [azurerm.dtmates]
    }
  }
  required_version = ">= 1.3.2"
}

provider "powerplatform" {
  use_cli = true
}

locals {
  project_code = "xxx"
  env_type     = "yyy"
  location     = "northeurope"
}

resource "azuread_group" "pa_env_security_group" {
  display_name     = "AGM-PA-${upper(local.project_code)}${upper(local.env_type)}-Environment Access"
  security_enabled = true
}

resource "powerplatform_environment" "main" {
  display_name     = "${upper(local.project_code)}${upper(local.env_type)}"
  location = var.location
  environment_type = "Sandbox"

  dataverse = {
    language_code     = 1033 #English https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a
    currency_code     = "ALL"
    domain            = "${lower(local.project_code)}${lower(local.env_type)}"
    security_group_id = "0000000-0000-0000-0000-000000000000"

  }

}

Expected behavior

It should do nothing or just implement the changes.

System Information

Windows Server 2022 Datacenter AE, 21H2, build. 20348.2762 Terraform v1.9.8 on windows_amd64

Additional context

This is my first try with the provider. As there is no such bug I believe (not tried) it may work correctly with default environmet url. I have many environments so I use names/urls defined by myself.

Contribution

NO

mawasile commented 3 weeks ago

Thanks for reporting @Fiury00. This was already spotted few days ago in this discussion and fixed in this PR. Will be in next release.