hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.59k stars 4.63k forks source link

azurerm_cdn_frontdoor_profile ID contains lower case "resourcegroups" instead of camel case "resourceGroups" #26375

Open cyrtified opened 4 months ago

cyrtified commented 4 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.7.4

AzureRM Provider Version

3.108.0

Affected Resource(s)/Data Source(s)

azurerm_cdn_frontdoor_profile

Terraform Configuration Files

resource "azurerm_cdn_frontdoor_profile" "profile" {
  name                = "example-profile"
  resource_group_name = azurerm_resource_group.rg.name
  sku_name            = "Standard_AzureFrontDoor"
}

resource "azurerm_cdn_frontdoor_endpoint" "endpoint" {
  name                     = "example-endpoint"
  cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.profile.id
}

Debug Output/Panic Output

-/+ resource "azurerm_cdn_frontdoor_endpoint" "endpoint" {
      ~ cdn_frontdoor_profile_id = "/subscriptions/xxx/resourceGroups/rg-example/providers/Microsoft.Cdn/profiles/example-profile" -> "/subscriptions/xxx/resourcegroups/rg-example/providers/Microsoft.Cdn/profiles/example-profile" # forces replacement

      ~ id                       = "/subscriptions/xxx/resourceGroups/rg-example/providers/Microsoft.Cdn/profiles/example-profile/afdEndpoints/example-endpoint" -> (known after apply)
        name                     = "example-endpoint"        
        # (unchanged attributes hidden)
    }

Expected Behaviour

No changes.

Actual Behaviour

azurerm_cdn_frontdoor_profile ID contains lower case "resourcegroups" instead of camel case "resourceGroups" and forces replacement of associated resources, including:

Steps to Reproduce

No response

Important Factoids

No response

References

No response

cyrtified commented 4 months ago

My current "fix":

resource "azurerm_cdn_frontdoor_endpoint" "endpoint" {
  name                     = "example-endpoint"
  cdn_frontdoor_profile_id = replace(azurerm_cdn_frontdoor_profile.profile.id, "//resourcegroups//", "/resourceGroups/") # fix
}
nnstt1 commented 4 months ago

I also tried with the same version of Terraform/AzureRM Provider, but the ID of azurerm_cdn_frontdoor_profile was created with 'resourceGroups' still in camel case. Is there any difference between the Terraform configuration I used and your environment?

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.108.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "rg" {
  name     = "rg-example"
  location = "eastus"
}

resource "azurerm_cdn_frontdoor_profile" "profile" {
  name                = "example-profile"
  resource_group_name = azurerm_resource_group.rg.name
  sku_name            = "Standard_AzureFrontDoor"
}

resource "azurerm_cdn_frontdoor_endpoint" "endpoint" {
  name                     = "example-endpoint"
  cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.profile.id
}

Underscores _ couldn't be used in the name parameter of azurerm_cdn_frontdoor_profile and azurerm_cdn_frontdoor_endpoint, so I replaced them with hyphens -.

cyrtified commented 4 months ago

I also tried with the same version of Terraform/AzureRM Provider, but the ID of azurerm_cdn_frontdoor_profile was created with 'resourceGroups' still in camel case. Is there any difference between the Terraform configuration I used and your environment?

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.108.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "rg" {
  name     = "rg-example"
  location = "eastus"
}

resource "azurerm_cdn_frontdoor_profile" "profile" {
  name                = "example-profile"
  resource_group_name = azurerm_resource_group.rg.name
  sku_name            = "Standard_AzureFrontDoor"
}

resource "azurerm_cdn_frontdoor_endpoint" "endpoint" {
  name                     = "example-endpoint"
  cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.profile.id
}

Underscores _ couldn't be used in the name parameter of azurerm_cdn_frontdoor_profile and azurerm_cdn_frontdoor_endpoint, so I replaced them with hyphens -.

Thanks for the reply.

Apologies about the names. I redacted the original script for security purposes.

It looks like the issue occurs when you import the state, instead of creating it from scratch.

nnstt1 commented 4 months ago

Thank you for your response! I created a Front Door (Standard) in the Azure Portal, imported it, and ran terraform plan, but unfortunately, I couldn't reproduce the issue. I imported it as shown below, but do you think there might be any differences with your environment? For example, are you migrating Front Door from classic?

$ terraform import azurerm_resource_group.rg /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-example
$ terraform import azurerm_cdn_frontdoor_profile.profile /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-example/providers/Microsoft.Cdn/profiles/example-profile
$ terraform import azurerm_cdn_frontdoor_endpoint.endpoint /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-example/providers/Microsoft.Cdn/profiles/example-profile/afdEndpoints/example-endpoint
cyrtified commented 4 months ago

No, I created a new Front Door (Standard) in the Azure Portal.

I destroyed all the resources and recreated them via Terraform and it seems to be working fine now.

nnstt1 commented 4 months ago

I wonder if the "resourceGroups" was created as "resourcegroups" when Front Door was created. It seems difficult for me to investigate this further... I'm sorry.

cyrtified commented 4 months ago

Probably a Microsoft bug.

Thanks for checking anyway.

tombuildsstuff commented 4 months ago

@cyrtified in this instance it looks like the Resource ID for azurerm_cdn_frontdoor_profile.profile contains resourcegroups rather than resourceGroups, so you should be able to fix this by removing that resource from your state and re-importing it - which should remove this diff:

terraform state rm azurerm_cdn_frontdoor_profile.profile terraform import azurerm_cdn_frontdoor_profile.profile /subscriptions/xxx/resourceGroups/rg-example/providers/Microsoft.Cdn/profiles/example-profile

Would you be able to take a look and see if that works for you?