@@ -21,7 +21,9 @@ def test_init_executes(self):
21
21
22
22
terraform .init ()
23
23
24
- executor .execute .assert_called_once_with (["terraform" , "init" ])
24
+ executor .execute .assert_called_once_with (
25
+ ["terraform" , "init" ], env = None
26
+ )
25
27
26
28
def test_init_executes_with_chdir (self ):
27
29
executor = Mock (spec = Executor )
@@ -30,7 +32,7 @@ def test_init_executes_with_chdir(self):
30
32
terraform .init (chdir = "/some/dir" )
31
33
32
34
executor .execute .assert_called_once_with (
33
- ["terraform" , "-chdir=/some/dir" , "init" ]
35
+ ["terraform" , "-chdir=/some/dir" , "init" ], env = None
34
36
)
35
37
36
38
def test_init_executes_with_backend_config_dictionary (self ):
@@ -41,7 +43,7 @@ def test_init_executes_with_backend_config_dictionary(self):
41
43
terraform .init (backend_config = backend_config )
42
44
43
45
executor .execute .assert_called_once_with (
44
- ["terraform" , "init" , '-backend-config="foo=1"' ]
46
+ ["terraform" , "init" , '-backend-config="foo=1"' ], env = None
45
47
)
46
48
47
49
def test_init_executes_with_backend_config_path (self ):
@@ -52,7 +54,8 @@ def test_init_executes_with_backend_config_path(self):
52
54
terraform .init (backend_config = backend_config )
53
55
54
56
executor .execute .assert_called_once_with (
55
- ["terraform" , "init" , "-backend-config=/some/config.tfvars" ]
57
+ ["terraform" , "init" , "-backend-config=/some/config.tfvars" ],
58
+ env = None ,
56
59
)
57
60
58
61
def test_init_executes_with_reconfigure (self ):
@@ -62,7 +65,18 @@ def test_init_executes_with_reconfigure(self):
62
65
terraform .init (reconfigure = True )
63
66
64
67
executor .execute .assert_called_once_with (
65
- ["terraform" , "init" , "-reconfigure" ]
68
+ ["terraform" , "init" , "-reconfigure" ], env = None
69
+ )
70
+
71
+ def test_init_executes_with_environment (self ):
72
+ executor = Mock (spec = Executor )
73
+ terraform = Terraform (executor )
74
+ environment = {"ENV_VAR" : "value" }
75
+
76
+ terraform .init (environment = environment )
77
+
78
+ executor .execute .assert_called_once_with (
79
+ ["terraform" , "init" ], env = environment
66
80
)
67
81
68
82
def test_plan_executes (self ):
@@ -71,7 +85,9 @@ def test_plan_executes(self):
71
85
72
86
terraform .plan ()
73
87
74
- executor .execute .assert_called_once_with (["terraform" , "plan" ])
88
+ executor .execute .assert_called_once_with (
89
+ ["terraform" , "plan" ], env = None
90
+ )
75
91
76
92
def test_plan_executes_with_chdir (self ):
77
93
executor = Mock (spec = Executor )
@@ -80,7 +96,7 @@ def test_plan_executes_with_chdir(self):
80
96
terraform .plan (chdir = "/some/dir" )
81
97
82
98
executor .execute .assert_called_once_with (
83
- ["terraform" , "-chdir=/some/dir" , "plan" ]
99
+ ["terraform" , "-chdir=/some/dir" , "plan" ], env = None
84
100
)
85
101
86
102
def test_plan_executes_with_vars (self ):
@@ -91,7 +107,18 @@ def test_plan_executes_with_vars(self):
91
107
terraform .plan (vars = variables )
92
108
93
109
executor .execute .assert_called_once_with (
94
- ["terraform" , "plan" , '-var="foo=1"' ]
110
+ ["terraform" , "plan" , '-var="foo=1"' ], env = None
111
+ )
112
+
113
+ def test_plan_executes_with_environment (self ):
114
+ executor = Mock (spec = Executor )
115
+ terraform = Terraform (executor )
116
+ environment = {"ENV_VAR" : "value" }
117
+
118
+ terraform .plan (environment = environment )
119
+
120
+ executor .execute .assert_called_once_with (
121
+ ["terraform" , "plan" ], env = environment
95
122
)
96
123
97
124
def test_apply_executes (self ):
@@ -100,7 +127,9 @@ def test_apply_executes(self):
100
127
101
128
terraform .apply ()
102
129
103
- executor .execute .assert_called_once_with (["terraform" , "apply" ])
130
+ executor .execute .assert_called_once_with (
131
+ ["terraform" , "apply" ], env = None
132
+ )
104
133
105
134
def test_apply_executes_with_chdir (self ):
106
135
executor = Mock (spec = Executor )
@@ -109,7 +138,7 @@ def test_apply_executes_with_chdir(self):
109
138
terraform .apply (chdir = "/some/dir" )
110
139
111
140
executor .execute .assert_called_once_with (
112
- ["terraform" , "-chdir=/some/dir" , "apply" ]
141
+ ["terraform" , "-chdir=/some/dir" , "apply" ], env = None
113
142
)
114
143
115
144
def test_apply_executes_with_vars (self ):
@@ -120,7 +149,7 @@ def test_apply_executes_with_vars(self):
120
149
terraform .apply (vars = variables )
121
150
122
151
executor .execute .assert_called_once_with (
123
- ["terraform" , "apply" , '-var="foo=1"' ]
152
+ ["terraform" , "apply" , '-var="foo=1"' ], env = None
124
153
)
125
154
126
155
def test_apply_executes_with_autoapprove (self ):
@@ -130,7 +159,18 @@ def test_apply_executes_with_autoapprove(self):
130
159
terraform .apply (autoapprove = True )
131
160
132
161
executor .execute .assert_called_once_with (
133
- ["terraform" , "apply" , "-auto-approve" ]
162
+ ["terraform" , "apply" , "-auto-approve" ], env = None
163
+ )
164
+
165
+ def test_apply_executes_with_environment (self ):
166
+ executor = Mock (spec = Executor )
167
+ terraform = Terraform (executor )
168
+ environment = {"ENV_VAR" : "value" }
169
+
170
+ terraform .apply (environment = environment )
171
+
172
+ executor .execute .assert_called_once_with (
173
+ ["terraform" , "apply" ], env = environment
134
174
)
135
175
136
176
def test_select_workspace_executes (self ):
@@ -141,7 +181,7 @@ def test_select_workspace_executes(self):
141
181
terraform .select_workspace (workspace )
142
182
143
183
executor .execute .assert_called_once_with (
144
- ["terraform" , "workspace" , "select" , workspace ]
184
+ ["terraform" , "workspace" , "select" , workspace ], env = None
145
185
)
146
186
147
187
def test_select_workspace_executes_with_chdir (self ):
@@ -152,7 +192,14 @@ def test_select_workspace_executes_with_chdir(self):
152
192
terraform .select_workspace (workspace , chdir = "/some/dir" )
153
193
154
194
executor .execute .assert_called_once_with (
155
- ["terraform" , "-chdir=/some/dir" , "workspace" , "select" , workspace ]
195
+ [
196
+ "terraform" ,
197
+ "-chdir=/some/dir" ,
198
+ "workspace" ,
199
+ "select" ,
200
+ workspace ,
201
+ ],
202
+ env = None ,
156
203
)
157
204
158
205
def test_select_workspace_executes_with_or_create (self ):
@@ -163,5 +210,18 @@ def test_select_workspace_executes_with_or_create(self):
163
210
terraform .select_workspace (workspace , or_create = True )
164
211
165
212
executor .execute .assert_called_once_with (
166
- ["terraform" , "workspace" , "select" , "-or-create=true" , workspace ]
213
+ ["terraform" , "workspace" , "select" , "-or-create=true" , workspace ],
214
+ env = None ,
215
+ )
216
+
217
+ def test_select_workspace_executes_with_environment (self ):
218
+ executor = Mock (spec = Executor )
219
+ terraform = Terraform (executor )
220
+ workspace = "workspace"
221
+ environment = {"ENV_VAR" : "value" }
222
+
223
+ terraform .select_workspace (workspace , environment = environment )
224
+
225
+ executor .execute .assert_called_once_with (
226
+ ["terraform" , "workspace" , "select" , workspace ], env = environment
167
227
)
0 commit comments