Skip to content

Commit e2e7ba3

Browse files
jiaweitao001Copilot
andcommitted
Fix #31965: Force recreation when policy definition parameter names change
The CustomizeDiff logic previously only handled parameter count decreases, but did not detect parameter renames (where count stays the same but names change). Azure API does not allow parameter name changes during update. This change iterates through old parameter names and forces recreation if any are missing from the new parameters, handling both removal and rename. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9c25dcb commit e2e7ba3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

internal/services/policy/policy_definition_resource.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func resourceArmPolicyDefinition() *pluginsdk.Resource {
4545
Schema: resourceArmPolicyDefinitionSchema(),
4646

4747
CustomizeDiff: pluginsdk.CustomizeDiffShim(func(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error {
48-
// `parameters` cannot have values removed so we'll ForceNew if there are less parameters between Terraform runs
48+
// `parameters` cannot have values removed or renamed so we'll ForceNew if any parameter names are removed/changed
4949
if d.HasChange("parameters") {
5050
oldParametersRaw, newParametersRaw := d.GetChange("parameters")
5151
if oldParametersString := oldParametersRaw.(string); oldParametersString != "" {
@@ -64,8 +64,11 @@ func resourceArmPolicyDefinition() *pluginsdk.Resource {
6464
return fmt.Errorf("expanding JSON for `parameters`: %+v", err)
6565
}
6666

67-
if len(newParameters) < len(oldParameters) {
68-
return d.ForceNew("parameters")
67+
// ForceNew if parameters were removed or renamed
68+
for oldKey := range oldParameters {
69+
if _, exists := newParameters[oldKey]; !exists {
70+
return d.ForceNew("parameters")
71+
}
6972
}
7073
}
7174
}

0 commit comments

Comments
 (0)