From 82a816fd48979e9159c0f1f27d6b88292b887eaf Mon Sep 17 00:00:00 2001 From: Tao <104055472+teowa@users.noreply.github.com> Date: Thu, 30 Nov 2023 19:28:36 +0800 Subject: [PATCH] add location normalization (#24074) --- internal/services/appconfiguration/app_configuration.go | 5 +++-- .../services/appconfiguration/app_configuration_resource.go | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/services/appconfiguration/app_configuration.go b/internal/services/appconfiguration/app_configuration.go index b54c2d691f1e..15a94babf315 100644 --- a/internal/services/appconfiguration/app_configuration.go +++ b/internal/services/appconfiguration/app_configuration.go @@ -11,6 +11,7 @@ import ( "github.com/Azure/go-autorest/autorest" "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2023-03-01/configurationstores" "github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2023-03-01/replicas" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -44,7 +45,7 @@ func flattenAppConfigurationReplicas(input []replicas.Replica) ([]interface{}, e result := map[string]interface{}{ "name": pointer.From(v.Name), - "location": pointer.From(v.Location), + "location": location.Normalize(pointer.From(v.Location)), "endpoint": pointer.From(v.Properties.Endpoint), "id": replicaId.ID(), } @@ -57,7 +58,7 @@ func resourceConfigurationStoreReplicaHash(input interface{}) int { var buf bytes.Buffer if rawData, ok := input.(map[string]interface{}); ok { buf.WriteString(rawData["name"].(string)) - buf.WriteString(rawData["location"].(string)) + buf.WriteString(location.Normalize(rawData["location"].(string))) } return pluginsdk.HashString(buf.String()) } diff --git a/internal/services/appconfiguration/app_configuration_resource.go b/internal/services/appconfiguration/app_configuration_resource.go index bf82774cff05..5d62e1c0605f 100644 --- a/internal/services/appconfiguration/app_configuration_resource.go +++ b/internal/services/appconfiguration/app_configuration_resource.go @@ -792,11 +792,11 @@ func expandAppConfigurationReplicas(input []interface{}, configurationStoreName, replicaName := replica["name"].(string) replicaLocation := location.Normalize(replica["location"].(string)) if strings.EqualFold(replicaLocation, configurationStoreLocation) { - return nil, fmt.Errorf("location (%q) of replica %q is duplicated with original configuration store %q", replicaName, replicaLocation, configurationStoreName) + return nil, fmt.Errorf("location (%q) of replica %q is duplicated with original configuration store %q", replicaLocation, replicaName, configurationStoreName) } if name, ok := locationSet[replicaLocation]; ok { - return nil, fmt.Errorf("location (%q) of replica %q is duplicated with replica %q", replicaName, replicaLocation, name) + return nil, fmt.Errorf("location (%q) of replica %q is duplicated with replica %q", replicaLocation, replicaName, name) } locationSet[replicaLocation] = replicaName @@ -807,7 +807,7 @@ func expandAppConfigurationReplicas(input []interface{}, configurationStoreName, replicaNameSet[normalizedReplicaName] = struct{}{} if len(replicaName)+len(configurationStoreName) > 60 { - return nil, fmt.Errorf("replica name %q is too long, the total length of replica name and configuration store name should be greater than 60", replicaName) + return nil, fmt.Errorf("replica name %q is too long, the total length of replica name and configuration store name should be less or equal than 60", replicaName) } result = append(result, replicas.Replica{