Skip to content

Commit

Permalink
add location normalization (#24074)
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa authored Nov 30, 2023
1 parent d079377 commit 82a816f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions internal/services/appconfiguration/app_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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{
Expand Down

0 comments on commit 82a816f

Please sign in to comment.