Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_dns_zone Import is Case Sensitive #28254

Open
1 task done
andrewpleasants-bjss-nhs opened this issue Dec 11, 2024 · 4 comments
Open
1 task done

azurerm_dns_zone Import is Case Sensitive #28254

andrewpleasants-bjss-nhs opened this issue Dec 11, 2024 · 4 comments

Comments

@andrewpleasants-bjss-nhs

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

1.9.5

AzureRM Provider Version

4.8.0

Affected Resource(s)/Data Source(s)

azurerm_dns_zone

Terraform Configuration Files

terraform {
  required_version = "1.9.5"

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "4.8.0"
    }
  }
}

provider "azurerm" {
  features {}

  subscription_id                 = "<id>"
  resource_provider_registrations = "none"
}

resource "azurerm_resource_group" "myGroup" {
  name     = "group1"
  location = "<location>"
}

resource "azurerm_dns_zone" "zone" {
  name                = "<zone name>"
  resource_group_name = azurerm_resource_group.myGroup.name
}

# This fails
terraform import azurerm_dns_zone.zone /subscriptions/<subscription id>/resourceGroups/gropu1/providers/Microsoft.Network/dnszones/<zone name>

# This succeeds
terraform import azurerm_dns_zone.zone /subscriptions/<subscription id>/resourceGroups/gropu1/providers/Microsoft.Network/dnsZones/<zone name>

Debug Output/Panic Output

Error: parsing "/subscriptions/<subscription id>/resourceGroups/group1/providers/Microsoft.Network/dnszones/<zone name>": parsing segment "staticDnsZones": parsing the DnsZone ID: the segment at position 6 didn't match

Expected a DnsZone ID that matched:

> /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/dnsZones/dnsZoneName

However this value was provided:

> /subscriptions/aef1b7cd-f0dc-476f-8364-608ac8d2a005/resourceGroups/group1/providers/Microsoft.Network/dnszones/<name name>

The parsed Resource ID was missing a value for the segment at position 6
(which should be the literal value "dnsZones").

Expected Behaviour

The lowercase z shouldn't impact the import process

Actual Behaviour

Had to change the z to an upper case Z to get the import to work

Steps to Reproduce

No response

Important Factoids

No response

References

No response

@wuxu92
Copy link
Contributor

wuxu92 commented Dec 12, 2024

Hi @andrewpleasants-bjss-nhs, Terraform is case-sensitive by design (unlike the HTTP API), so we must always provide a correctly cased ID to the terraform import command. This is expected behavior. Out of curiosity, was the lowercase ID copied from the Azure portal or somewhere else?

@andrewpleasants-bjss-nhs
Copy link
Author

Hi @andrewpleasants-bjss-nhs, Terraform is case-sensitive by design (unlike the HTTP API), so we must always provide a correctly cased ID to the terraform import command. This is expected behavior. Out of curiosity, was the lowercase ID copied from the Azure portal or somewhere else?

Hi @wuxu92 yes I copied the resource ID from the Azure Portal, it's also lowercase using tooling such as AZ CLI.

So if Terraform is case sensitive (which is a reasonable design decision), it should be changed from dnsZone to dnszone? As that seems to be the convention being used (not sure if that has changed over time / always been like that though)

@andrewpleasants-bjss-nhs
Copy link
Author

andrewpleasants-bjss-nhs commented Dec 12, 2024

Looking into the source code I can see that in the DNS Zone data source file, ParseDNSZoneIDInsensitively (see here) but in the resource ParseDNSZoneID is used so there's a slight inconsistency there.

Again, I'm not sure if this is a deliberate design decision in the provider / Terraform (which is fine of course)

@wuxu92
Copy link
Contributor

wuxu92 commented Dec 13, 2024

@andrewpleasants-bjss-nhs Terraform always respects the case of the API definition in Swagger, found at https://github.com/Azure/azure-rest-api-specs/blob/67c84bd51ccfca841c39f274b9147347abed3f66/specification/dns/resource-manager/Microsoft.Network/stable/2018-05-01/dns.json#L767. Therefore, I believe this is a Portal display issue rather than a provider issue. The insensitive parse function is used internally to address the API response case issue and is not designed for use in the terraform import.

    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dnsZones/{zoneName}": {
      "put": {
        "tags": [
          "Zones"
        ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants