Skip to content

Commit 39dc760

Browse files
authored
Include skip actions in JSON plan (#3663)
## Changes Include 'skip' nodes in JSON plan. ## Why We need to process 'skip' resources as well (e.g. to resolve references). Today, we have these nodes in the graph but not in the plan. Once we move to serialized plan #3636 we will build graph from the plan so they must match. This prepares for that (and minimizes that PR). This also gives more information to users of JSON plan, e.g. they can count unchanged count. ## Tests Existing tests.
1 parent e0d771e commit 39dc760

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

acceptance/bundle/resources/jobs/update/output.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
2424

2525
>>> [CLI] bundle debug plan
2626
{
27-
"plan": {}
27+
"plan": {
28+
"resources.jobs.foo": {
29+
"action": "skip"
30+
}
31+
}
2832
}
2933

3034
>>> print_requests
@@ -91,7 +95,11 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
9195

9296
>>> [CLI] bundle debug plan
9397
{
94-
"plan": {}
98+
"plan": {
99+
"resources.jobs.foo": {
100+
"action": "skip"
101+
}
102+
}
95103
}
96104

97105
>>> print_requests

bundle/direct/apply.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState
3333
}
3434

3535
func (d *DeploymentUnit) Deploy(ctx context.Context, db *dstate.DeploymentState, inputConfig any, actionType deployplan.ActionType) error {
36+
if actionType == deployplan.ActionTypeSkip {
37+
return nil
38+
}
39+
3640
// Note, newState may be different between plan and deploy due to resolved $resource references
3741
newState, err := d.Adapter.PrepareState(inputConfig)
3842
if err != nil {

bundle/direct/bundle_plan.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,15 @@ func (b *DeploymentBundle) CalculatePlanForDeploy(ctx context.Context, client *d
121121
}
122122
}
123123

124+
plan.Plan[resourceKey] = deployplan.PlanEntry{
125+
Action: actionType.String(),
126+
}
127+
124128
if actionType == deployplan.ActionTypeSkip {
125129
if hasDelayedResolutions {
126130
logdiag.LogError(ctx, fmt.Errorf("%s: internal error, action noop must not have delayed resolutions", errorPrefix))
127131
return false
128132
}
129-
return true
130-
}
131-
132-
plan.Plan[resourceKey] = deployplan.PlanEntry{
133-
Action: actionType.String(),
134133
}
135134

136135
return true

cmd/bundle/plan.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ It is useful for previewing changes before running 'bundle deploy'.`,
7171
createCount := 0
7272
updateCount := 0
7373
deleteCount := 0
74-
changed := make(map[string]bool)
74+
unchangedCount := 0
7575

7676
for _, change := range plan.GetActions() {
77-
changed[change.ResourceKey] = true
7877
switch change.ActionType {
7978
case deployplan.ActionTypeCreate:
8079
createCount++
@@ -87,18 +86,7 @@ It is useful for previewing changes before running 'bundle deploy'.`,
8786
deleteCount++
8887
createCount++
8988
case deployplan.ActionTypeSkip, deployplan.ActionTypeUnset:
90-
// Noop
91-
}
92-
}
93-
94-
// Calculate number of all unchanged resources
95-
unchanged := 0
96-
for _, group := range b.Config.Resources.AllResources() {
97-
for rKey := range group.Resources {
98-
resourceKey := "resources." + group.Description.PluralName + "." + rKey
99-
if _, ok := changed[resourceKey]; !ok {
100-
unchanged++
101-
}
89+
unchangedCount++
10290
}
10391
}
10492

@@ -111,12 +99,15 @@ It is useful for previewing changes before running 'bundle deploy'.`,
11199
if totalChanges > 0 {
112100
// Print all actions in the order they were processed
113101
for _, action := range plan.GetActions() {
102+
if action.ActionType == deployplan.ActionTypeSkip {
103+
continue
104+
}
114105
key := strings.TrimPrefix(action.ResourceKey, "resources.")
115106
fmt.Fprintf(out, "%s %s\n", action.ActionType.StringShort(), key)
116107
}
117108
fmt.Fprintln(out)
118109
}
119-
fmt.Fprintf(out, "Plan: %d to add, %d to change, %d to delete, %d unchanged\n", createCount, updateCount, deleteCount, unchanged)
110+
fmt.Fprintf(out, "Plan: %d to add, %d to change, %d to delete, %d unchanged\n", createCount, updateCount, deleteCount, unchangedCount)
120111
case flags.OutputJSON:
121112
buf, err := json.MarshalIndent(plan, "", " ")
122113
if err != nil {

cmd/bundle/utils/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,19 @@ func GetPlan(ctx context.Context, b *bundle.Bundle) (*deployplan.Plan, error) {
6363
return nil, root.ErrAlreadyPrinted
6464
}
6565

66+
// Direct engine includes noop actions, TF does not. This adds no-op actions for consistency:
67+
if !b.DirectDeployment {
68+
for _, group := range b.Config.Resources.AllResources() {
69+
for rKey := range group.Resources {
70+
resourceKey := "resources." + group.Description.PluralName + "." + rKey
71+
if _, ok := plan.Plan[resourceKey]; !ok {
72+
plan.Plan[resourceKey] = deployplan.PlanEntry{
73+
Action: deployplan.ActionTypeSkip.String(),
74+
}
75+
}
76+
}
77+
}
78+
}
79+
6680
return plan, nil
6781
}

0 commit comments

Comments
 (0)