mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -06:00
command: plan supports detailed exit code
This commit is contained in:
parent
3f5829dc78
commit
9a091ffa78
@ -16,7 +16,7 @@ type PlanCommand struct {
|
||||
}
|
||||
|
||||
func (c *PlanCommand) Run(args []string) int {
|
||||
var destroy, refresh bool
|
||||
var destroy, refresh, detailed bool
|
||||
var outPath string
|
||||
var moduleDepth int
|
||||
|
||||
@ -29,6 +29,7 @@ func (c *PlanCommand) Run(args []string) int {
|
||||
cmdFlags.StringVar(&outPath, "out", "", "path")
|
||||
cmdFlags.StringVar(&c.Meta.statePath, "state", DefaultStateFilename, "path")
|
||||
cmdFlags.StringVar(&c.Meta.backupPath, "backup", "", "path")
|
||||
cmdFlags.BoolVar(&detailed, "detailed-exitcode", false, "detailed-exitcode")
|
||||
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
||||
if err := cmdFlags.Parse(args); err != nil {
|
||||
return 1
|
||||
@ -129,6 +130,9 @@ func (c *PlanCommand) Run(args []string) int {
|
||||
ModuleDepth: moduleDepth,
|
||||
}))
|
||||
|
||||
if detailed {
|
||||
return 2
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -152,6 +156,12 @@ Options:
|
||||
-destroy If set, a plan will be generated to destroy all resources
|
||||
managed by the given configuration and state.
|
||||
|
||||
-detailed-exitcode Return detailed exit codes when the command exits. This
|
||||
will change the meaning of exit codes to:
|
||||
0 - Succeeded, diff is empty (no changes)
|
||||
1 - Errored
|
||||
2 - Succeeded, there is a diff
|
||||
|
||||
-input=true Ask for input for variables if not directly set.
|
||||
|
||||
-module-depth=n Specifies the depth of modules to show in the output.
|
||||
|
@ -567,6 +567,56 @@ func TestPlan_disableBackup(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlan_detailedExitcode(t *testing.T) {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if err := os.Chdir(testFixturePath("plan")); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Chdir(cwd)
|
||||
|
||||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &PlanCommand{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{"-detailed-exitcode"}
|
||||
if code := c.Run(args); code != 2 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlan_detailedExitcode_emptyDiff(t *testing.T) {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if err := os.Chdir(testFixturePath("plan-emptydiff")); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Chdir(cwd)
|
||||
|
||||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &PlanCommand{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{"-detailed-exitcode"}
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
}
|
||||
|
||||
const planVarFile = `
|
||||
foo = "bar"
|
||||
`
|
||||
|
0
command/test-fixtures/plan-emptydiff/main.tf
Normal file
0
command/test-fixtures/plan-emptydiff/main.tf
Normal file
Loading…
Reference in New Issue
Block a user