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.52k stars 4.6k forks source link

Unable to Update Tags for Secondary EventHub Namespace via Terraform, Discrepency with Portal Functionality #25005

Open mhrreddy2312 opened 6 months ago

mhrreddy2312 commented 6 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.3.9

AzureRM Provider Version

3.92.0

Affected Resource(s)/Data Source(s)

azurerm_eventhub_namespace

Terraform Configuration Files

resource "azurerm_resource_group" "rg_west" {
  name     = "example-resources"
  location = "West Europe"
}
resource "azurerm_resource_group" "rg_north" {
  name     = "example-resources"
  location = "West Europe"
}
resource "azurerm_eventhub_namespace" "ehs" {
  name                = "eventhub-em41"
  resource_group_name = azurerm_resource_group.rg_west.name
  location            = "westeurope"
  sku                 = "Standard"
  zone_redundant      = true

  tags = {
    Tag1 = "value1"
    Tag2 = "value2"
    Tag3 = "value3"
    Tag4 = "value4"
    Tag5 = "value5"
  }
}

resource "azurerm_eventhub_namespace" "ehs_secondary" {
  name                = "eventhub-em21"
  resource_group_name = azurerm_resource_group.rg_north.name
  location            = "northeurope"
  sku                 = "Standard"
  zone_redundant      = true
  tags = {
    Tag1 = "value1"
    Tag2 = "value2"
    Tag3 = "value8"
    Tag4 = "value5"
    Tag5 = "value6"
  }
}

resource "azurerm_eventhub_namespace_disaster_recovery_config" "ehs_disaster_recovery" {
  name                 = "disaster_recovery_config"
  resource_group_name  = azurerm_resource_group.rg_west.name
  namespace_name       = azurerm_eventhub_namespace.ehs.name
  partner_namespace_id = azurerm_eventhub_namespace.ehs_secondary.id

  depends_on = [
    azurerm_eventhub_namespace.ehs,
    azurerm_eventhub_namespace.ehs_secondary
  ]
}

Debug Output/Panic Output

Error: updating Namespace (Subscription: "xxxxx-xxxx-xxx-xxx-xxx-xxxx"
Resource Group Name: "example-resources"
Namespace Name: "eventhub-em21"): unexpected status 400 with error: MetadataDRSecondaryNamespaceInvalidUpdateBadRequest: Cannot update a namespace which is secondary. For more information visit https://aka.ms/eventhubsarmexceptions.

  with azurerm_eventhub_namespace.ehs_secondary,
  on github.tf line 27, in resource "azurerm_eventhub_namespace" "ehs_secondary":
  27: resource "azurerm_eventhub_namespace" "ehs_secondary" {

Expected Behaviour

Terraform should allow updating tags/values on the secondary event hub namespace even after enabling Geo Disaster Recovery, similar to the functionality available through the Azure portal.

Actual Behaviour

Currently, when attempting to modify tags/values on the secondary event hub namespace using Terraform, the changes do not reflect as expected and the pipeline fails with error message -unexpected status 400 with error: MetadataDRSecondaryNamespaceInvalidUpdateBadRequest: Cannot update a namespace which is secondary. For more information visit [https://aka.ms/eventhubsarmexceptions](https://aka.ms/eventhubsarmexceptions.).

However, these changes are successfully applied when performed through the Azure portal

Steps to Reproduce

  1. Enable Geo Disaster Recovery for the event hub namespace.
  2. Attempt to update tags/values on the secondary namespace using Terraform.
  3. Observe that the changes are not reflected as expected.

Important Factoids

No response

References

No response

xiaxyi commented 6 months ago

Thanks @mhrreddy2312 for raising this issue, let me check the feature and update once I have any more information.

mhrreddy2312 commented 6 months ago

Thanks @mhrreddy2312 for raising this issue, let me check the feature and update once I have any more information.

Thanks for your response @xiaxyi , let me know if you need any other details on the issue

AhalimZaki commented 6 months ago

@mhrreddy2312 I'm doing a similar setup for Geo-Red however since there are some shared resources that can be shared!

variables.tf

variable "geoZones" {
  type    = map(any)
  default = {
    east= "East US"
    west="West US"
  }
}

locals {
  tags = {
    Tag1 = "value1"
    Tag2 = "value2"
    Tag3 = "value3"
    Tag4 = "value4"
    Tag5 = "value5"
  }
}
resource "azurerm_resource_group" "main" {
  name     = "sharedRG"
  location = "eastus"
  tags = local.tags

}
resource "azurerm_resource_group" "geo_redundancy" {
  for_each = var.geoZones

  name     = join("-", ["shareRG", each.key])
  location = each.value
  tags = local.tags

}

Geo creation with all tags in place

resource "azurerm_eventhub_namespace" "main" {
  for_each = azurerm_resource_group.geo_redundancy

  name                = join("-", ["eventHubGeo", each.key])
  resource_group_name = each.value.name
  location            = each.value.location
  sku                 = "Standard"
  capacity            = 1

  tags = local.tags

  lifecycle {
    ignore_changes = all
  }

}
mhrreddy2312 commented 6 months ago

@AhalimZaki - Thanks for your response. I'm looking to update different tags/values on Primary and Secondary Eventhub name space. I can't achieve this requirement via Terraform but can be done using the Azure Portal

AhalimZaki commented 6 months ago

@mhrreddy2312 you can follow the same concept and the tags value should be replaced based on key and value of the for loop aswell. I think if you would do it if it's east then you will take these tags, and vice versa. If I have time tomorrow I will try to assemble something.

mhrreddy2312 commented 5 months ago

@mhrreddy2312 you can follow the same concept and the tags value should be replaced based on key and value of the for loop aswell. I think if you would do it if it's east then you will take these tags, and vice versa. If I have time tomorrow I will try to assemble something.

@AhalimZaki - I can achieve this only if I use the ignore_changes block but my requirement doesn't allow me to use the ignore_changes block. Please let me know if my understanding is incorrect

mhrreddy2312 commented 5 months ago

Thanks @mhrreddy2312 for raising this issue, let me check the feature and update once I have any more information.

@xiaxyi - Please let me know if you have further updates on this issue

mhrreddy2312 commented 4 months ago

@xiaxyi - Could you please advise if you have further updates on this case