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 (hashicorp#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 <[email protected]>
  • Loading branch information
2 people authored and rizkybiz committed Jan 26, 2024
1 parent d3bd237 commit 687f957
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 687f957

Please sign in to comment.