Skip to content

Commit

Permalink
exit code for non empty plan file
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalkaoz committed Nov 6, 2023
1 parent 8a06577 commit 7f931a7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,20 @@ func NewPlanCommand(root *cobra.Command) {
planFile = fmt.Sprintf("%s-%s.tfplan", strings.Replace(time.Now().Format(time.RFC3339), ":", "-", -1), args[0])
}

_, err := tf.Plan(ctx, buildPlanOptions(files, args, planFile)...)
diff, err := tf.Plan(ctx, buildPlanOptions(files, args, planFile)...)
// behave exactly like terraform:
/*
0 = Succeeded with empty diff (no changes)
1 = Error
2 = Succeeded with non-empty diff (changes present)
*/
if err != nil {
os.Exit(1)
}

if diff {
os.Exit(2)
}
},
}

Expand Down

0 comments on commit 7f931a7

Please sign in to comment.