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_cname_record: try normalize target_resource_id with RecordTypeID before set to state #24181

Merged
merged 5 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Comment on lines +198 to +206
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're still silently ignoring the case where the returned ID is none of those resource types. We should error if the resource type isn't any of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the resource type is not listed, we should directly use the ID from the API response. This could indicate an API bug or a new resource type supported by the API. Neither of these scenarios should disrupt client behavior, as far as I understand it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to check internally but you're right @wuxu92, apologies!

I did push a commit to add a comment above this logic linking to a piece of work we're doing on dynamic resource IDs - once that functionality is available we should be able to update this.

}
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
Loading