forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan.go
89 lines (73 loc) · 3.23 KB
/
plan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package terraform
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
// InitAndPlan runs terraform init and plan with the given options and returns stdout/stderr from the plan command.
// This will fail the test if there is an error in the command.
func InitAndPlan(t *testing.T, options *Options) string {
out, err := InitAndPlanE(t, options)
require.NoError(t, err)
return out
}
// InitAndPlanE runs terraform init and plan with the given options and returns stdout/stderr from the plan command.
func InitAndPlanE(t *testing.T, options *Options) (string, error) {
if _, err := InitE(t, options); err != nil {
return "", err
}
if _, err := GetE(t, options); err != nil {
return "", err
}
return PlanE(t, options)
}
// Plan runs terraform plan with the given options and returns stdout/stderr.
// This will fail the test if there is an error in the command.
func Plan(t *testing.T, options *Options) string {
out, err := PlanE(t, options)
require.NoError(t, err)
return out
}
// PlanE runs terraform plan with the given options and returns stdout/stderr.
func PlanE(t *testing.T, options *Options) (string, error) {
return RunTerraformCommandE(t, options, FormatArgs(options, "plan", "-input=false", "-lock=false")...)
}
// InitAndPlanWithExitCode runs terraform init and plan with the given options and returns exitcode for the plan command.
// This will fail the test if there is an error in the command.
func InitAndPlanWithExitCode(t *testing.T, options *Options) int {
exitCode, err := InitAndPlanWithExitCodeE(t, options)
require.NoError(t, err)
return exitCode
}
// InitAndPlanWithExitCodeE runs terraform init and plan with the given options and returns exitcode for the plan command.
func InitAndPlanWithExitCodeE(t *testing.T, options *Options) (int, error) {
if _, err := InitE(t, options); err != nil {
return DefaultErrorExitCode, err
}
return PlanExitCodeE(t, options)
}
// PlanExitCode runs terraform plan with the given options and returns the detailed exitcode.
// This will fail the test if there is an error in the command.
func PlanExitCode(t *testing.T, options *Options) int {
exitCode, err := PlanExitCodeE(t, options)
require.NoError(t, err)
return exitCode
}
// PlanExitCodeE runs terraform plan with the given options and returns the detailed exitcode.
func PlanExitCodeE(t *testing.T, options *Options) (int, error) {
return GetExitCodeForTerraformCommandE(t, options, FormatArgs(options, "plan", "-input=false", "-detailed-exitcode")...)
}
// TgPlanAllExitCode runs terragrunt plan-all with the given options and returns the detailed exitcode.
// This will fail the test if there is an error in the command.
func TgPlanAllExitCode(t *testing.T, options *Options) int {
exitCode, err := TgPlanAllExitCodeE(t, options)
require.NoError(t, err)
return exitCode
}
// TgPlanAllExitCodeE runs terragrunt plan-all with the given options and returns the detailed exitcode.
func TgPlanAllExitCodeE(t *testing.T, options *Options) (int, error) {
if options.TerraformBinary != "terragrunt" {
return 1, fmt.Errorf("terragrunt must be set as TerraformBinary to use this method")
}
return GetExitCodeForTerraformCommandE(t, options, FormatArgs(options, "plan-all", "--input=false", "--lock=true", "--detailed-exitcode")...)
}