From ebdfa95d04638cc0b6a9c888ddb4cf6d3b29cb34 Mon Sep 17 00:00:00 2001 From: xuwu1 Date: Mon, 11 Dec 2023 15:24:40 +0800 Subject: [PATCH 1/5] try normalize dns target resource id to fix case issue --- internal/services/dns/dns_cname_record_resource.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/services/dns/dns_cname_record_resource.go b/internal/services/dns/dns_cname_record_resource.go index 2c9615a3759c..89e68b593d7f 100644 --- a/internal/services/dns/dns_cname_record_resource.go +++ b/internal/services/dns/dns_cname_record_resource.go @@ -192,7 +192,7 @@ func resourceDnsCNameRecordRead(d *pluginsdk.ResourceData, meta interface{}) err if props.TargetResource != nil && props.TargetResource.Id != nil { targetResourceId = *props.TargetResource.Id } - d.Set("target_resource_id", targetResourceId) + d.Set("target_resource_id", normalizeTargetResourceID(targetResourceId)) if err := tags.FlattenAndSet(d, props.Metadata); err != nil { return err @@ -219,3 +219,15 @@ func resourceDnsCNameRecordDelete(d *pluginsdk.ResourceData, meta interface{}) e return nil } + +func normalizeTargetResourceID(id string) string { + if id == "" { + return "" + } + + if parsed, err := recordsets.ParseRecordTypeIDInsensitively(id); err == nil { + return parsed.ID() + } + + return id +} From 3645b4e29db3509fce3be50434b44d7ba17ab14e Mon Sep 17 00:00:00 2001 From: xuwu1 Date: Mon, 11 Dec 2023 15:57:06 +0800 Subject: [PATCH 2/5] use lowercase resource group name to fix acc tests --- internal/services/dns/dns_cname_record_resource_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/services/dns/dns_cname_record_resource_test.go b/internal/services/dns/dns_cname_record_resource_test.go index 819118d8f720..7e4d42e98231 100644 --- a/internal/services/dns/dns_cname_record_resource_test.go +++ b/internal/services/dns/dns_cname_record_resource_test.go @@ -358,7 +358,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestrg-%d" location = "%s" } @@ -392,7 +392,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestrg-%d" location = "%s" } @@ -426,7 +426,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestrg-%d" location = "%s" } @@ -460,7 +460,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestrg-%d" location = "%s" } From 01a3f2de7782cbce3d17a8a99735004f4f8f9540 Mon Sep 17 00:00:00 2001 From: xuwu1 Date: Tue, 12 Dec 2023 09:22:39 +0800 Subject: [PATCH 3/5] inline normalize target resource id --- .../services/dns/dns_cname_record_resource.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/internal/services/dns/dns_cname_record_resource.go b/internal/services/dns/dns_cname_record_resource.go index 89e68b593d7f..19f944688057 100644 --- a/internal/services/dns/dns_cname_record_resource.go +++ b/internal/services/dns/dns_cname_record_resource.go @@ -191,8 +191,11 @@ func resourceDnsCNameRecordRead(d *pluginsdk.ResourceData, meta interface{}) err targetResourceId := "" if props.TargetResource != nil && props.TargetResource.Id != nil { targetResourceId = *props.TargetResource.Id + if parsedID, err := recordsets.ParseRecordTypeIDInsensitively(targetResourceId); err == nil { + targetResourceId = parsedID.ID() + } } - d.Set("target_resource_id", normalizeTargetResourceID(targetResourceId)) + d.Set("target_resource_id", targetResourceId) if err := tags.FlattenAndSet(d, props.Metadata); err != nil { return err @@ -219,15 +222,3 @@ func resourceDnsCNameRecordDelete(d *pluginsdk.ResourceData, meta interface{}) e return nil } - -func normalizeTargetResourceID(id string) string { - if id == "" { - return "" - } - - if parsed, err := recordsets.ParseRecordTypeIDInsensitively(id); err == nil { - return parsed.ID() - } - - return id -} From 5e65d42785fb877e3376e791351ccaff0256cfdc Mon Sep 17 00:00:00 2001 From: xuwu1 Date: Mon, 18 Dec 2023 17:33:05 +0800 Subject: [PATCH 4/5] add other possible resource id for target resource id --- internal/services/dns/dns_cname_record_resource.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/services/dns/dns_cname_record_resource.go b/internal/services/dns/dns_cname_record_resource.go index 19f944688057..7c0d0ff2ea12 100644 --- a/internal/services/dns/dns_cname_record_resource.go +++ b/internal/services/dns/dns_cname_record_resource.go @@ -11,10 +11,13 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/recordsets" + "github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2018-08-01/endpoints" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + cdn "github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/dns/migration" + frontdoor "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -191,8 +194,14 @@ func resourceDnsCNameRecordRead(d *pluginsdk.ResourceData, meta interface{}) err targetResourceId := "" if props.TargetResource != nil && props.TargetResource.Id != nil { targetResourceId = *props.TargetResource.Id - if parsedID, err := recordsets.ParseRecordTypeIDInsensitively(targetResourceId); err == nil { - targetResourceId = parsedID.ID() + if recordTypeID, err := recordsets.ParseRecordTypeIDInsensitively(targetResourceId); err == nil { + targetResourceId = recordTypeID.ID() + } else if trafficManagerID, err := endpoints.ParseEndpointTypeIDInsensitively(targetResourceId); err == nil { + targetResourceId = trafficManagerID.ID() + } else if cdnID, err := cdn.EndpointIDInsensitively(targetResourceId); err == nil { + targetResourceId = cdnID.ID() + } else if frontDoorID, err := frontdoor.FrontendEndpointIDInsensitively(targetResourceId); err == nil { + targetResourceId = frontDoorID.ID() } } d.Set("target_resource_id", targetResourceId) From 1af4cc21a721ea87738d75192af043856d56dd5e Mon Sep 17 00:00:00 2001 From: Steph Date: Thu, 25 Jan 2024 16:42:50 +0100 Subject: [PATCH 5/5] add todo comment for updating the id parser logic once the recaser work is finished --- internal/services/dns/dns_cname_record_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/dns/dns_cname_record_resource.go b/internal/services/dns/dns_cname_record_resource.go index 7c0d0ff2ea12..4935cdc1dedc 100644 --- a/internal/services/dns/dns_cname_record_resource.go +++ b/internal/services/dns/dns_cname_record_resource.go @@ -193,6 +193,7 @@ func resourceDnsCNameRecordRead(d *pluginsdk.ResourceData, meta interface{}) err targetResourceId := "" if props.TargetResource != nil && props.TargetResource.Id != nil { + // TODO update this once https://github.com/hashicorp/go-azure-helpers/issues/189 is resolved targetResourceId = *props.TargetResource.Id if recordTypeID, err := recordsets.ParseRecordTypeIDInsensitively(targetResourceId); err == nil { targetResourceId = recordTypeID.ID()