-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
apply.go
114 lines (92 loc) · 4.78 KB
/
apply.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package terraform
import (
"errors"
"github.com/gruntwork-io/terratest/modules/testing"
"github.com/stretchr/testify/require"
)
// InitAndApply runs terraform init and apply with the given options and return stdout/stderr from the apply command. Note that this
// method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running
// apply.
func InitAndApply(t testing.TestingT, options *Options) string {
out, err := InitAndApplyE(t, options)
require.NoError(t, err)
return out
}
// InitAndApplyE runs terraform init and apply with the given options and return stdout/stderr from the apply command. Note that this
// method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running
// apply.
func InitAndApplyE(t testing.TestingT, options *Options) (string, error) {
if _, err := InitE(t, options); err != nil {
return "", err
}
return ApplyE(t, options)
}
// Apply runs terraform apply with the given options and return stdout/stderr. Note that this method does NOT call destroy and
// assumes the caller is responsible for cleaning up any resources created by running apply.
func Apply(t testing.TestingT, options *Options) string {
out, err := ApplyE(t, options)
require.NoError(t, err)
return out
}
// TgApplyAll runs terragrunt apply with the given options and return stdout/stderr. Note that this method does NOT call destroy and
// assumes the caller is responsible for cleaning up any resources created by running apply.
func TgApplyAll(t testing.TestingT, options *Options) string {
out, err := TgApplyAllE(t, options)
require.NoError(t, err)
return out
}
// ApplyE runs terraform apply with the given options and return stdout/stderr. Note that this method does NOT call destroy and
// assumes the caller is responsible for cleaning up any resources created by running apply.
func ApplyE(t testing.TestingT, options *Options) (string, error) {
return RunTerraformCommandE(t, options, FormatArgs(options, "apply", "-input=false", "-auto-approve")...)
}
// TgApplyAllE runs terragrunt apply-all with the given options and return stdout/stderr. Note that this method does NOT call destroy and
// assumes the caller is responsible for cleaning up any resources created by running apply.
func TgApplyAllE(t testing.TestingT, options *Options) (string, error) {
if options.TerraformBinary != "terragrunt" {
return "", TgInvalidBinary(options.TerraformBinary)
}
return RunTerraformCommandE(t, options, FormatArgs(options, "run-all", "apply", "-input=false", "-auto-approve")...)
}
// ApplyAndIdempotent runs terraform apply with the given options and return stdout/stderr from the apply command. It then runs
// plan again and will fail the test if plan requires additional changes. Note that this method does NOT call destroy and assumes
// the caller is responsible for cleaning up any resources created by running apply.
func ApplyAndIdempotent(t testing.TestingT, options *Options) string {
out, err := ApplyAndIdempotentE(t, options)
require.NoError(t, err)
return out
}
// ApplyAndIdempotentE runs terraform apply with the given options and return stdout/stderr from the apply command. It then runs
// plan again and will fail the test if plan requires additional changes. Note that this method does NOT call destroy and assumes
// the caller is responsible for cleaning up any resources created by running apply.
func ApplyAndIdempotentE(t testing.TestingT, options *Options) (string, error) {
out, err := ApplyE(t, options)
if err != nil {
return out, err
}
exitCode, err := PlanExitCodeE(t, options)
if err != nil {
return out, err
}
if exitCode != 0 {
return out, errors.New("terraform configuration not idempotent")
}
return out, nil
}
// InitAndApplyAndIdempotent runs terraform init and apply with the given options and return stdout/stderr from the apply command. It then runs
// plan again and will fail the test if plan requires additional changes. Note that this method does NOT call destroy and assumes
// the caller is responsible for cleaning up any resources created by running apply.
func InitAndApplyAndIdempotent(t testing.TestingT, options *Options) string {
out, err := InitAndApplyAndIdempotentE(t, options)
require.NoError(t, err)
return out
}
// InitAndApplyAndIdempotentE runs terraform init and apply with the given options and return stdout/stderr from the apply command. It then runs
// plan again and will fail the test if plan requires additional changes. Note that this method does NOT call destroy and assumes
// the caller is responsible for cleaning up any resources created by running apply.
func InitAndApplyAndIdempotentE(t testing.TestingT, options *Options) (string, error) {
if _, err := InitE(t, options); err != nil {
return "", err
}
return ApplyAndIdempotentE(t, options)
}