Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions acceptance/bundle/resources/jobs/update/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged

>>> [CLI] bundle debug plan
{
"plan": {}
"plan": {
"resources.jobs.foo": {
"action": "skip"
}
}
}

>>> print_requests
Expand Down Expand Up @@ -91,7 +95,11 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged

>>> [CLI] bundle debug plan
{
"plan": {}
"plan": {
"resources.jobs.foo": {
"action": "skip"
}
}
}

>>> print_requests
Expand Down
4 changes: 4 additions & 0 deletions bundle/direct/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState
}

func (d *DeploymentUnit) Deploy(ctx context.Context, db *dstate.DeploymentState, inputConfig any, actionType deployplan.ActionType) error {
if actionType == deployplan.ActionTypeSkip {
return nil
}

// Note, newState may be different between plan and deploy due to resolved $resource references
newState, err := d.Adapter.PrepareState(inputConfig)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions bundle/direct/bundle_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,15 @@ func (b *DeploymentBundle) CalculatePlanForDeploy(ctx context.Context, client *d
}
}

plan.Plan[resourceKey] = deployplan.PlanEntry{
Action: actionType.String(),
}

if actionType == deployplan.ActionTypeSkip {
if hasDelayedResolutions {
logdiag.LogError(ctx, fmt.Errorf("%s: internal error, action noop must not have delayed resolutions", errorPrefix))
return false
}
return true
}

plan.Plan[resourceKey] = deployplan.PlanEntry{
Action: actionType.String(),
}

return true
Expand Down
21 changes: 6 additions & 15 deletions cmd/bundle/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ It is useful for previewing changes before running 'bundle deploy'.`,
createCount := 0
updateCount := 0
deleteCount := 0
changed := make(map[string]bool)
unchangedCount := 0

for _, change := range plan.GetActions() {
changed[change.ResourceKey] = true
switch change.ActionType {
case deployplan.ActionTypeCreate:
createCount++
Expand All @@ -87,18 +86,7 @@ It is useful for previewing changes before running 'bundle deploy'.`,
deleteCount++
createCount++
case deployplan.ActionTypeSkip, deployplan.ActionTypeUnset:
// Noop
}
}

// Calculate number of all unchanged resources
unchanged := 0
for _, group := range b.Config.Resources.AllResources() {
for rKey := range group.Resources {
resourceKey := "resources." + group.Description.PluralName + "." + rKey
if _, ok := changed[resourceKey]; !ok {
unchanged++
}
unchangedCount++
}
}

Expand All @@ -111,12 +99,15 @@ It is useful for previewing changes before running 'bundle deploy'.`,
if totalChanges > 0 {
// Print all actions in the order they were processed
for _, action := range plan.GetActions() {
if action.ActionType == deployplan.ActionTypeSkip {
continue
}
key := strings.TrimPrefix(action.ResourceKey, "resources.")
fmt.Fprintf(out, "%s %s\n", action.ActionType.StringShort(), key)
}
fmt.Fprintln(out)
}
fmt.Fprintf(out, "Plan: %d to add, %d to change, %d to delete, %d unchanged\n", createCount, updateCount, deleteCount, unchanged)
fmt.Fprintf(out, "Plan: %d to add, %d to change, %d to delete, %d unchanged\n", createCount, updateCount, deleteCount, unchangedCount)
case flags.OutputJSON:
buf, err := json.MarshalIndent(plan, "", " ")
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions cmd/bundle/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,19 @@ func GetPlan(ctx context.Context, b *bundle.Bundle) (*deployplan.Plan, error) {
return nil, root.ErrAlreadyPrinted
}

// Direct engine includes noop actions, TF does not. This adds no-op actions for consistency:
if !b.DirectDeployment {
for _, group := range b.Config.Resources.AllResources() {
for rKey := range group.Resources {
resourceKey := "resources." + group.Description.PluralName + "." + rKey
if _, ok := plan.Plan[resourceKey]; !ok {
plan.Plan[resourceKey] = deployplan.PlanEntry{
Action: deployplan.ActionTypeSkip.String(),
}
}
}
}
}

return plan, nil
}
Loading