diff --git a/internal/services/appconfiguration/app_configuration_resource.go b/internal/services/appconfiguration/app_configuration_resource.go index a14759c4c18ca..11528402395ee 100644 --- a/internal/services/appconfiguration/app_configuration_resource.go +++ b/internal/services/appconfiguration/app_configuration_resource.go @@ -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 @@ -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 } @@ -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) @@ -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{}) @@ -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)