Move show plan to a function

This commit is contained in:
Wojciech Pratkowiecki 2024-10-03 09:37:11 +02:00
parent 9e53f117d2
commit fd67acbc7f
1 changed files with 38 additions and 5 deletions

View File

@ -51,6 +51,43 @@ func parseTerraformActions(changes []*tfjson.ResourceChange, toInclude func(typ
return res return res
} }
func showDryRunChanges(ctx context.Context, plan *tfjson.Plan) {
updateActions := make([]terraformlib.Action, 0)
for _, rc := range plan.ResourceChanges {
if rc.Change.Actions.Update() {
updateActions = append(updateActions, terraformlib.Action{
Action: terraformlib.ActionTypeUpdate,
ResourceType: rc.Type,
ResourceName: rc.Name,
})
}
}
createActions := make([]terraformlib.Action, 0)
for _, rc := range plan.ResourceChanges {
if rc.Change.Actions.Create() {
createActions = append(createActions, terraformlib.Action{
Action: terraformlib.ActionTypeCreate,
ResourceType: rc.Type,
ResourceName: rc.Name,
})
}
}
if len(updateActions) > 0 {
cmdio.LogString(ctx, "The following resources will be updated:")
for _, a := range updateActions {
cmdio.Log(ctx, a)
}
cmdio.LogString(ctx, "")
}
if len(createActions) > 0 {
cmdio.LogString(ctx, "The following resources will be created:")
for _, a := range createActions {
cmdio.Log(ctx, a)
}
cmdio.LogString(ctx, "")
}
}
func approvalForDeploy(ctx context.Context, b *bundle.Bundle) (bool, error) { func approvalForDeploy(ctx context.Context, b *bundle.Bundle) (bool, error) {
tf := b.Terraform tf := b.Terraform
if tf == nil { if tf == nil {
@ -64,11 +101,7 @@ func approvalForDeploy(ctx context.Context, b *bundle.Bundle) (bool, error) {
} }
if b.DryRun { if b.DryRun {
cmdio.LogString(ctx, "Following changes would be deployed:") showDryRunChanges(ctx, plan)
_, err := tf.ShowPlanFile(ctx, b.Plan.Path)
if err != nil {
return false, err
}
return false, nil return false, nil
} }