Skip to content

Commit 2a198db

Browse files
committed
Fix secret_acl plan action aggregation for mixed create+delete
When multiple secret ACL changes for the same scope include both creates and deletes, report the net action as "update" instead of "delete". GetHigherAction picks the highest severity (delete > create), but mixed ACL changes represent a permissions update, not a deletion. Task: 019.md Co-authored-by: Isaac
1 parent 2ab6a25 commit 2a198db

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎bundle/deploy/terraform/showplanfile.go‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func convertSecretAclNameToScopeKey(name string) string {
6868
return "resources.secret_scopes." + name + ".permissions"
6969
}
7070

71+
// isCreateDeleteMix returns true if one action is Create and the other is Delete (in either order).
72+
func isCreateDeleteMix(a, b deployplan.ActionType) bool {
73+
return (a == deployplan.Create && b == deployplan.Delete) || (a == deployplan.Delete && b == deployplan.Create)
74+
}
75+
7176
// populatePlan populates a deployplan.Plan from Terraform resource changes.
7277
func populatePlan(ctx context.Context, plan *deployplan.Plan, changes []*tfjson.ResourceChange) {
7378
for _, rc := range changes {
@@ -110,7 +115,12 @@ func populatePlan(ctx context.Context, plan *deployplan.Plan, changes []*tfjson.
110115
}
111116

112117
if existing, ok := plan.Plan[key]; ok {
113-
existing.Action = deployplan.GetHigherAction(existing.Action, actionType)
118+
// For secret ACLs, mixed create+delete means the permissions are being updated, not deleted.
119+
if group == "secret_acls" && isCreateDeleteMix(existing.Action, actionType) {
120+
existing.Action = deployplan.Update
121+
} else {
122+
existing.Action = deployplan.GetHigherAction(existing.Action, actionType)
123+
}
114124
} else {
115125
plan.Plan[key] = &deployplan.PlanEntry{Action: actionType}
116126
}

‎bundle/deploy/terraform/showplanfile_test.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ func TestPopulatePlanSecretAcl(t *testing.T) {
101101
}, plan.Plan)
102102
}
103103

104+
func TestPopulatePlanSecretAclMixedCreateDelete(t *testing.T) {
105+
ctx := t.Context()
106+
changes := []*tfjson.ResourceChange{
107+
{
108+
Type: "databricks_secret_acl",
109+
Change: &tfjson.Change{Actions: tfjson.Actions{tfjson.ActionDelete}},
110+
Name: "secret_acl_my_scope_0",
111+
},
112+
{
113+
Type: "databricks_secret_acl",
114+
Change: &tfjson.Change{Actions: tfjson.Actions{tfjson.ActionCreate}},
115+
Name: "secret_acl_my_scope_1",
116+
},
117+
}
118+
119+
plan := deployplan.NewPlanTerraform()
120+
populatePlan(ctx, plan, changes)
121+
122+
assert.Equal(t, map[string]*deployplan.PlanEntry{
123+
"resources.secret_scopes.my_scope.permissions": {Action: deployplan.Update},
124+
}, plan.Plan)
125+
}
126+
104127
func TestConvertSecretAclNameToScopeKey(t *testing.T) {
105128
assert.Equal(t, "resources.secret_scopes.my_scope.permissions", convertSecretAclNameToScopeKey("secret_acl_my_scope_0"))
106129
assert.Equal(t, "resources.secret_scopes.my_scope.permissions", convertSecretAclNameToScopeKey("secret_acl_my_scope_1"))

0 commit comments

Comments
 (0)