Case sensitive ID matching
ID matching in resources is case sensitive, that's kinda a problem. I have created a log analytics workspace by "azurerm_log_analytics_workspace" resource and linked it to a private link scope with azapi, as there is no capable enough resource in azurerm. It all works, but when replanning without any changes, this is what I get as a plan for this resource:
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
~ update in-place
Terraform will perform the following actions:
# module.appinsight.azapi_resource.scope_association will be updated in-place
~ resource "azapi_resource" "scope_association" {
~ body = jsonencode(
~ {
~ properties = {
~ linkedResourceId = "/subscriptions/6d472a7b-a80a-44c2-815d-1a1f726eba62/resourcegroups/sandbox-monitor-rg-01/providers/microsoft.insights/components/sbx-monitor-01-appinsights" -> "/subscriptions/6d472a7b-a80a-44c2-815d-1a1f726eba62/resourceGroups/sandbox-monitor-rg-01/providers/Microsoft.Insights/components/sbx-monitor-01-appinsights"
}
}
)
id = "/subscriptions/6d472a7b-a80a-44c2-815d-1a1f726eba62/resourceGroups/sandbox-monitor-rg-01/providers/Microsoft.Insights/privateLinkScopes/sbx-monitor-01-ampls/scopedResources/sbx-monitor-01-appinsights"
name = "sbx-monitor-01-appinsights"
~ output = jsonencode({}) -> (known after apply)
tags = {}
# (5 unchanged attributes hidden)
}
# module.law.azapi_resource.scope_association will be updated in-place
~ resource "azapi_resource" "scope_association" {
~ body = jsonencode(
~ {
~ properties = {
~ linkedResourceId = "/subscriptions/6d472a7b-a80a-44c2-815d-1a1f726eba62/resourcegroups/sandbox-monitor-rg-01/providers/microsoft.operationalinsights/workspaces/sbx-monitor-01-workspace" -> "/subscriptions/6d472a7b-a80a-44c2-815d-1a1f726eba62/resourceGroups/sandbox-monitor-rg-01/providers/Microsoft.OperationalInsights/workspaces/sbx-monitor-01-workspace"
}
}
)
id = "/subscriptions/6d472a7b-a80a-44c2-815d-1a1f726eba62/resourceGroups/sandbox-monitor-rg-01/providers/Microsoft.Insights/privateLinkScopes/sbx-monitor-01-ampls/scopedResources/sbx-monitor-01-workspace"
name = "sbx-monitor-01-workspace"
~ output = jsonencode({}) -> (known after apply)
tags = {}
# (5 unchanged attributes hidden)
}
The only change is casing in ID, and this is the casing which is returned by querying the id from the LAW resource. So there should be no change reported.
I also have another casing problem relating to not matching resource id and resource type when creating child resources, it's that the returned id differs in casing (in a way similar to above plan), except here I can work around it by changing casing on the type field of a resource.
Hi @webczat ,
Thank you for taking time to report this issue!
This is an issue related to the API, it should return the casing that is set there. The azapi_resource provides a way to bypass the casing diff, you can add ignore_casing = true to the resource block and apply it to suppress the diff.
More info can be found here: https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/azapi_resource#ignore_casing
isn't it terraform kinda normalizing the id? as in the azurerm provider doing that, not the API.
Yes, I think this is the right thing, and I'll create an issue for the service team to fix the API.
verified by doing the az command directly to query the resource, confirmed as described. So it's indeed api issue.
Hi @webczat ,
I've created an issue for the API bug: https://github.com/Azure/azure-rest-api-specs/issues/20586.
I'll close this issue, but feel free to reopen it if there're more questions. Thanks!