Skip to content

Commit

Permalink
azurerm_dns_cname_record: try normalize target_resource_id with R…
Browse files Browse the repository at this point in the history
…ecordTypeID before set to state (#24181)

* try normalize dns target resource id to fix case issue

* use lowercase resource group name to fix acc tests

* inline normalize target resource id

* add other possible resource id for target resource id

* add todo comment for updating the id parser logic once the recaser work is finished

---------

Co-authored-by: Steph <steph@hashicorp.com>
  • Loading branch information
wuxu92 and stephybun authored Jan 25, 2024
1 parent 141640f commit 6b1e66a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions internal/services/dns/dns_cname_record_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions internal/services/dns/dns_cname_record_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ provider "azurerm" {
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestrg-%d"
location = "%s"
}
Expand Down Expand Up @@ -392,7 +392,7 @@ provider "azurerm" {
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestrg-%d"
location = "%s"
}
Expand Down Expand Up @@ -426,7 +426,7 @@ provider "azurerm" {
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestrg-%d"
location = "%s"
}
Expand Down Expand Up @@ -460,7 +460,7 @@ provider "azurerm" {
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestrg-%d"
location = "%s"
}
Expand Down

0 comments on commit 6b1e66a

Please sign in to comment.