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

azurerm_site_recovery_replicated_vm handles Resource Group in target_capacity_reservation_group_id as case-sensitive #22695

Open horvatal opened 1 year ago

horvatal commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.5.3

AzureRM Provider Version

3.65.0

Affected Resource(s)/Data Source(s)

azurerm_site_recovery_replicated_vm

Terraform Configuration Files

resource "azurerm_site_recovery_replicated_vm" "vm-replication" {
  name                                      = "vm-replication"
  resource_group_name                       = azurerm_resource_group.secondary.name
  recovery_vault_name                       = azurerm_recovery_services_vault.vault.name
  source_recovery_fabric_name               = azurerm_site_recovery_fabric.primary.name
  source_vm_id                              = azurerm_virtual_machine.vm.id
  recovery_replication_policy_id            = azurerm_site_recovery_replication_policy.policy.id
  source_recovery_protection_container_name = azurerm_site_recovery_protection_container.primary.name

  target_resource_group_id                = azurerm_resource_group.secondary.id
  target_recovery_fabric_id               = azurerm_site_recovery_fabric.secondary.id
  target_recovery_protection_container_id = azurerm_site_recovery_protection_container.secondary.id
  target_capacity_reservation_group_id    = data.azapi_resource.example_capacity_group.id

  managed_disk {
    disk_id                    = azurerm_virtual_machine.vm.storage_os_disk[0].managed_disk_id
    staging_storage_account_id = azurerm_storage_account.primary.id
    target_resource_group_id   = azurerm_resource_group.secondary.id
    target_disk_type           = "Premium_LRS"
    target_replica_disk_type   = "Premium_LRS"
  }

  network_interface {
    source_network_interface_id   = azurerm_network_interface.vm.id
    target_subnet_name            = azurerm_subnet.secondary.name
    recovery_public_ip_address_id = azurerm_public_ip.secondary.id
  }

  depends_on = [
    azurerm_site_recovery_protection_container_mapping.container-mapping,
    azurerm_site_recovery_network_mapping.network-mapping,
  ]
}

Debug Output/Panic Output

~ resource "azurerm_site_recovery_replicated_vm" "protected_vm_tf" {
        id                                        = "/subscriptions/xxxxxxxx-xxxx-xxxxxxxxxxxxxxxxxxxxx/resourceGroups/z-ach-a9999-pr01-ns1-01-asr/providers/Microsoft.RecoveryServices/vaults/zacha9999pr01ns1rsv90/replicationFabrics/primary-fabric/replicationProtectionContainers/primary-protection-container/replicationProtectedItems/zachadevtestpr01001"
        name                                      = "zachadevtestpr01001"
      ~ target_capacity_reservation_group_id      = "/subscriptions/xxxxxxxx-xxxx-xxxxxxxxxxxxxxxxxxxxx/resourceGroups/Z-ACH-A9999-PR01-NS1-01-ASR/providers/Microsoft.Compute/capacityReservationGroups/zacha9999pr01ns1asr01" -> "/subscriptions/xxxxxxxx-xxxx-xxxxxxxxxxxxxxxxxxxxx/resourceGroups/z-ach-a9999-pr01-ns1-01-asr/providers/Microsoft.Compute/capacityReservationGroups/zacha9999pr01ns1asr01"
        # (14 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Expected Behaviour

No change expected, if target_capacity_reservation_group_id only differs in letter casing (e.g. upper-case). Here this happens from Z-ACH-A9999-PR01-NS1-01-ASR to z-ach-a9999-pr01-ns1-01-asr. Azure documentation says that Resource Group names should be case-insensitive (https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules#:~:text=Always%20perform%20a%20case%2Dinsensitive%20comparison%20of%20names).

Actual Behaviour

The target CRG was set by a Recovery Plan Runbook (with Get-AzCapacityReservationGroup in upper-case format). If I have a TF run a change is detected, because the azapi (Microsoft.Compute/capacityReservationGroups@2021-11-01) delivers lower-case RG in the ID.

Steps to Reproduce

No response

Important Factoids

No response

References

https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules#:~:text=Always%20perform%20a%20case%2Dinsensitive%20comparison%20of%20names

ziyeqf commented 1 year ago

Hi @horvatal, thanks for opening the issue.

We are currently handling the casing issues by making the values read by the provider is consistent instead of ignoring the casing. Per the config file you provided, the target_capacity_reservation_group_id was from azapi provider, could you please provide the config block of that?

azapi conbiane parent_id and resource_name to get the id of the target resource, I may wondering if the parent_id specified was lower-cased.

For any further questions, please leave comments.