Skip to content

Commit

Permalink
optmize location compare
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed Sep 15, 2023
1 parent b043d04 commit 30313ab
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions internal/services/appconfiguration/app_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,22 +778,19 @@ func expandAppConfigurationReplicas(input []interface{}, configurationStoreName,

// check if there are duplicated replica names or locations
// location cannot be same as original configuration store and other replicas
const placeholder = ""
locationSet := map[string]string{
configurationStoreLocation: placeholder,
}
locationSet := map[string]string{}
replicaNameSet := map[string]struct{}{}

for _, v := range input {
replica := v.(map[string]interface{})
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)
}

if name, ok := locationSet[replicaLocation]; ok {
if name == placeholder {
return nil, fmt.Errorf("replica %q location %q is duplicated with original configuration store %q", replicaName, replicaLocation, configurationStoreName)
}
return nil, fmt.Errorf("replica %q location %q is duplicated with replica %q", replicaName, replicaLocation, name)
return nil, fmt.Errorf("location (%q) of replica %q is duplicated with replica %q", replicaName, replicaLocation, name)
}
locationSet[replicaLocation] = replicaName

Expand Down

0 comments on commit 30313ab

Please sign in to comment.