diff --git a/internal/services/dns/dns_cname_record_resource.go b/internal/services/dns/dns_cname_record_resource.go index 2c9615a3759c..4935cdc1dedc 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" @@ -190,7 +193,17 @@ 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() + } 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) 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" }