Skip to content

Commit

Permalink
fix update to skip unchanged replicas
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed Sep 15, 2023
1 parent 30313ab commit d9738be
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/services/appconfiguration/app_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ func resourceAppConfigurationUpdate(d *pluginsdk.ResourceData, meta interface{})

// check if a replica has been removed from config and if so, delete it
deleteReplicaIds := make([]replicas.ReplicaId, 0)
unchangedReplicaNames := make(map[string]struct{}, 0)
oldReplicas, newReplicas := d.GetChange("replica")
for _, oldReplica := range oldReplicas.(*pluginsdk.Set).List() {
isRemoved := true
Expand All @@ -488,8 +489,8 @@ func resourceAppConfigurationUpdate(d *pluginsdk.ResourceData, meta interface{})
for _, newReplica := range newReplicas.(*pluginsdk.Set).List() {
newReplicaMap := newReplica.(map[string]interface{})

if strings.EqualFold(oldReplicaMap["name"].(string), newReplicaMap["name"].(string)) &&
strings.EqualFold(location.Normalize(oldReplicaMap["location"].(string)), location.Normalize(newReplicaMap["location"].(string))) {
if strings.EqualFold(oldReplicaMap["name"].(string), newReplicaMap["name"].(string)) && strings.EqualFold(location.Normalize(oldReplicaMap["location"].(string)), location.Normalize(newReplicaMap["location"].(string))) {
unchangedReplicaNames[oldReplicaMap["name"].(string)] = struct{}{}
isRemoved = false
break
}
Expand All @@ -511,6 +512,10 @@ func resourceAppConfigurationUpdate(d *pluginsdk.ResourceData, meta interface{})

// check if a replica has been added or an existing one changed its location, (re)create it
for _, replica := range *expandedReplicas {
if _, isUnchanged := unchangedReplicaNames[*replica.Name]; isUnchanged {
continue
}

replicaId := replicas.NewReplicaID(id.SubscriptionId, id.ResourceGroupName, id.ConfigurationStoreName, *replica.Name)

existingReplica, err := replicaClient.Get(ctx, replicaId)
Expand Down Expand Up @@ -778,8 +783,8 @@ 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
locationSet := map[string]string{}
replicaNameSet := map[string]struct{}{}
locationSet := make(map[string]string, 0)
replicaNameSet := make(map[string]struct{}, 0)

for _, v := range input {
replica := v.(map[string]interface{})
Expand All @@ -794,9 +799,11 @@ func expandAppConfigurationReplicas(input []interface{}, configurationStoreName,
}
locationSet[replicaLocation] = replicaName

if _, ok := replicaNameSet[replicaName]; ok {
normalizedReplicaName := strings.ToLower(replicaName)
if _, ok := replicaNameSet[normalizedReplicaName]; ok {
return nil, fmt.Errorf("replica name %q is duplicated", replicaName)
}
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)
Expand Down

0 comments on commit d9738be

Please sign in to comment.