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

post upgrade to azurerm 3.26.0 (from 2.72.0), azurerm_monitor_diagnostic_setting getting forced replaced because of "resourceGroups" != "resourcegroups" in target_resource_id #18698

Open achupryn opened 2 years ago

achupryn commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.1.4

AzureRM Provider Version

3.26.0

Affected Resource(s)/Data Source(s)

azurerm_monitor_diagnostic_setting

Terraform Configuration Files

resource "azurerm_monitor_diagnostic_setting" "aks-logging" {
  count                      = var.enable_aks_logging ? 1 : 0
  name                       = "diagnostic_aksl"
  target_resource_id         = azurerm_kubernetes_cluster.k8s.id
  log_analytics_workspace_id = azurerm_log_analytics_workspace.k8s_logs.id
  ...
}

Debug Output/Panic Output

# plan
Terraform will perform the following actions:
  # azurerm_monitor_diagnostic_setting.aks-logging[0] must be replaced
-/+ resource "azurerm_monitor_diagnostic_setting" "aks-logging" {
      ~ id                         = "/subscriptions/<subscriptions_id>/resourcegroups/rgrp-aks-application-cluster/providers/Microsoft.ContainerService/managedClusters/aks-application-cluster|diagnostic_aksl" -> (known after apply)
        name                       = "diagnostic_aksl"
      ~ target_resource_id         = "/subscriptions/<subscriptions_id>/resourcegroups/rgrp-aks-application-cluster/providers/Microsoft.ContainerService/managedClusters/aks-application-cluster" -> "/subscriptions/<subscriptions_id>/resourceGroups/rgrp-aks-application-cluster/providers/Microsoft.ContainerService/managedClusters/aks-application-cluster" # forces replacement

# the difference is "resource**G**roups" != "resourcegroups" in target_resource_id

Expected Behaviour

azurerm_monitor_diagnostic_setting.aks-logging not changed

Actual Behaviour

azurerm_monitor_diagnostic_setting.aks-logging[0] must be replaced

The issue is ID casing - "resourceGroups" != "resourcegroups" in target_resource_id

Similar problem - #18467

Steps to Reproduce

No response

Important Factoids

No response

References

18467

achupryn commented 2 years ago

The same behavior in case update to v2.99

teowa commented 2 years ago

Hi @achupryn , thanks for submitting this, seems this issue is caused by PR https://github.com/hashicorp/terraform-provider-azurerm/pull/14241, which changes the resourcegroup case in the ID of azurerm_kubernetes_cluster resource (released in v2.88.0). I am working on a PR to fix this.

Simondebb commented 2 years ago

Hello @teowa,

I have a similaire issue with azurerm_api_management
azurerm version 2.99

azurerm_api_management.this will be updated in-place
  ~ resource "azurerm_api_management" "this" {
      ~ virtual_network_configuration {
          ~ subnet_id = "/subscriptions/***/resourcegroups/rg-myrg/providers/microsoft.network/virtualnetworks/vnet-myvnet/subnets/snet-mysnet" -> "/subscriptions/***/resourceGroups/rg-myrg/providers/Microsoft.Network/virtualNetworks/vnet-myvnet/subnets/snet-mysnet"
        }
        (8 unchanged blocks hidden)
}

resourcegroups != resourceGroups , microsoft.network != Microsoft.Network and virtualnetworks != virtualNetworks

Can you have look into this ? thanks a lot.

teowa commented 2 years ago

Hi @Simondebb , thanks for the reply, seems the issue is related to https://github.com/hashicorp/terraform-provider-azurerm/issues/18399. And the solution is in progress.

achupryn commented 1 year ago

v3.32.0 - issue is still present

hypery2k commented 1 year ago

@teowa any update on that one or workaround?

teowa commented 1 year ago

Hi @hypery2k, We are working on a more general solution, which can cope with more situations (instead of a specific resource), and it may take longer time.

And a workaround to avoid diff and force replacement is to manually change the resource ID reference using replace function, for example:

resource "azurerm_monitor_diagnostic_setting" "aks-logging" {
   target_resource_id         = replace(azurerm_kubernetes_cluster.k8s.id, "resourceGroups", "resourcegroups")
}

Hope this may help.

hypery2k commented 1 year ago

thx for the hint, that worked

aadesola commented 1 year ago

Hi @teowa , I have a similar issue and tried to use the replace function but didn't work. Although it's not an ID. resource_group_name = replace(var.someresourcegroup, "resourcegroups", "resourceGroups") any pointers on what I'm missing?

teowa commented 1 year ago

@aadesola , it is case by case, you should use the replace function to replace the ID segment where you want to avoid unintentional change. Could you please provide more details on your Terraform plan result? Maybe you should replace some property with ID format but not the resource_group_name.