9
9
ApplyConfiguration ,
10
10
Configuration ,
11
11
ConfigureFunction ,
12
+ DestroyConfiguration ,
12
13
OutputConfiguration ,
13
14
PlanConfiguration ,
15
+ ValidateConfiguration ,
14
16
)
15
17
from .factory import TerraformTaskFactory
16
18
@@ -22,19 +24,24 @@ class TerraformTaskCollectionParameters(TypedDict, total=False):
22
24
task_extra_parameters : dict [str , ParameterList ]
23
25
task_override_parameters : dict [str , ParameterList ]
24
26
task_extra_configure_function : dict [str , ConfigureFunction [Any ]]
25
- task_override_configure_function : dict [str , ConfigureFunction [Configuration ]]
27
+ task_override_configure_function : dict [
28
+ str , ConfigureFunction [Configuration ]
29
+ ]
26
30
27
31
28
32
class TerraformTaskCollection :
29
33
def __init__ (
30
34
self ,
31
35
configuration_name : str | None = None ,
32
36
global_parameters : ParameterList | None = None ,
33
- global_configure_function : ConfigureFunction [Configuration ] | None = None ,
37
+ global_configure_function : ConfigureFunction [Configuration ]
38
+ | None = None ,
34
39
task_extra_parameters : dict [str , ParameterList ] | None = None ,
35
40
task_override_parameters : dict [str , ParameterList ] | None = None ,
36
- task_extra_configure_function : dict [str , ConfigureFunction [Any ]] | None = None ,
37
- task_override_configure_function : dict [str , ConfigureFunction [Any ]] | None = None ,
41
+ task_extra_configure_function : dict [str , ConfigureFunction [Any ]]
42
+ | None = None ,
43
+ task_override_configure_function : dict [str , ConfigureFunction [Any ]]
44
+ | None = None ,
38
45
task_factory : TerraformTaskFactory = TerraformTaskFactory (),
39
46
):
40
47
self .configuration_name = configuration_name
@@ -54,12 +61,16 @@ def __init__(
54
61
if task_override_parameters is not None
55
62
else {}
56
63
)
57
- self .task_extra_configure_function : dict [str , ConfigureFunction [Any ]] = (
64
+ self .task_extra_configure_function : dict [
65
+ str , ConfigureFunction [Any ]
66
+ ] = (
58
67
task_extra_configure_function
59
68
if task_extra_configure_function is not None
60
69
else {}
61
70
)
62
- self .task_override_configure_function : dict [str , ConfigureFunction [Any ]] = (
71
+ self .task_override_configure_function : dict [
72
+ str , ConfigureFunction [Any ]
73
+ ] = (
63
74
task_override_configure_function
64
75
if task_override_configure_function is not None
65
76
else {}
@@ -108,88 +119,94 @@ def with_global_configure_function(
108
119
return self ._clone (global_configure_function = global_configure_function )
109
120
110
121
def with_extra_task_parameters (
111
- self , task_name : str , * parameters : Parameter
122
+ self , task_name : str , * parameters : Parameter
112
123
) -> Self :
113
- return self ._clone (task_extra_parameters = {
114
- ** self .task_extra_parameters ,
115
- task_name : parameters
116
- })
124
+ return self ._clone (
125
+ task_extra_parameters = {
126
+ ** self .task_extra_parameters ,
127
+ task_name : parameters ,
128
+ }
129
+ )
117
130
118
131
def with_overridden_task_parameters (
119
- self , task_name : str , * parameters : Parameter
132
+ self , task_name : str , * parameters : Parameter
120
133
) -> Self :
121
- return self ._clone (task_override_parameters = {
122
- ** self .task_override_parameters ,
123
- task_name : parameters
124
- })
134
+ return self ._clone (
135
+ task_override_parameters = {
136
+ ** self .task_override_parameters ,
137
+ task_name : parameters ,
138
+ }
139
+ )
125
140
126
141
@overload
127
142
def with_extra_task_configure_function (
128
- self ,
129
- task_name : Literal ["plan " ],
130
- task_configure_function : ConfigureFunction [PlanConfiguration ]
143
+ self ,
144
+ task_name : Literal ["validate " ],
145
+ task_configure_function : ConfigureFunction [ValidateConfiguration ],
131
146
) -> Self : ...
132
147
133
148
@overload
134
149
def with_extra_task_configure_function (
135
- self ,
136
- task_name : Literal ["apply " ],
137
- task_configure_function : ConfigureFunction [ApplyConfiguration ]
150
+ self ,
151
+ task_name : Literal ["plan " ],
152
+ task_configure_function : ConfigureFunction [PlanConfiguration ],
138
153
) -> Self : ...
139
154
140
155
@overload
141
156
def with_extra_task_configure_function (
142
- self ,
143
- task_name : Literal ["output " ],
144
- task_configure_function : ConfigureFunction [OutputConfiguration ]
157
+ self ,
158
+ task_name : Literal ["apply " ],
159
+ task_configure_function : ConfigureFunction [ApplyConfiguration ],
145
160
) -> Self : ...
146
161
162
+ @overload
147
163
def with_extra_task_configure_function (
148
- self ,
149
- task_name : str ,
150
- task_configure_function : ConfigureFunction [Any ]
164
+ self ,
165
+ task_name : Literal ["destroy" ],
166
+ task_configure_function : ConfigureFunction [DestroyConfiguration ],
167
+ ) -> Self : ...
168
+
169
+ @overload
170
+ def with_extra_task_configure_function (
171
+ self ,
172
+ task_name : Literal ["output" ],
173
+ task_configure_function : ConfigureFunction [OutputConfiguration ],
174
+ ) -> Self : ...
175
+
176
+ def with_extra_task_configure_function (
177
+ self , task_name : str , task_configure_function : ConfigureFunction [Any ]
151
178
) -> Self :
152
- return self ._clone (task_extra_configure_function = {
153
- ** self .task_extra_configure_function ,
154
- task_name : task_configure_function
155
- })
179
+ return self ._clone (
180
+ task_extra_configure_function = {
181
+ ** self .task_extra_configure_function ,
182
+ task_name : task_configure_function ,
183
+ }
184
+ )
156
185
157
186
def with_overridden_task_configure_function (
158
- self ,
159
- task_name : str ,
160
- task_configure_function : ConfigureFunction [Configuration ]
187
+ self ,
188
+ task_name : str ,
189
+ task_configure_function : ConfigureFunction [Configuration ],
161
190
) -> Self :
162
- return self ._clone (task_override_configure_function = {
163
- ** self .task_override_configure_function ,
164
- task_name : task_configure_function
165
- })
191
+ return self ._clone (
192
+ task_override_configure_function = {
193
+ ** self .task_override_configure_function ,
194
+ task_name : task_configure_function ,
195
+ }
196
+ )
166
197
167
198
def _resolve_parameters (self , task_name : str ) -> ParameterList :
168
199
if task_name in self .task_override_parameters :
169
200
return self .task_override_parameters [task_name ]
170
201
171
202
return [
172
203
* self .global_parameters ,
173
- * self .task_extra_parameters .get (task_name , [])
204
+ * self .task_extra_parameters .get (task_name , []),
174
205
]
175
206
176
- @overload
177
- def _resolve_configure_function (
178
- self , task_name : Literal ["plan" ]
179
- ) -> ConfigureFunction [Configuration ]: ...
180
-
181
- @overload
182
207
def _resolve_configure_function (
183
- self , task_name : Literal ["apply" ]
184
- ) -> ConfigureFunction [Configuration ]: ...
185
-
186
- @overload
187
- def _resolve_configure_function (
188
- self , task_name : Literal ["output" ]
189
- ) -> ConfigureFunction [Configuration ]: ...
190
-
191
- def _resolve_configure_function (
192
- self , task_name : str
208
+ self ,
209
+ task_name : Literal ["validate" , "plan" , "apply" , "destroy" , "output" ],
193
210
) -> ConfigureFunction [Configuration ]:
194
211
if task_name in self .task_override_configure_function :
195
212
return self .task_override_configure_function [task_name ]
@@ -200,28 +217,37 @@ def _resolve_configure_function(
200
217
)
201
218
202
219
specific_configuration_type : (
203
- type [PlanConfiguration ] |
204
- type [ApplyConfiguration ] |
205
- type [OutputConfiguration ]
220
+ type [ValidateConfiguration ]
221
+ | type [PlanConfiguration ]
222
+ | type [ApplyConfiguration ]
223
+ | type [DestroyConfiguration ]
224
+ | type [OutputConfiguration ]
206
225
)
207
- if task_name == "plan" :
208
- specific_configuration_type = PlanConfiguration
209
- elif task_name == "apply" :
210
- specific_configuration_type = ApplyConfiguration
211
- elif task_name == "output" :
212
- specific_configuration_type = OutputConfiguration
213
- else :
214
- raise ValueError ("Unsupported task name: " + task_name )
226
+ match task_name :
227
+ case "validate" :
228
+ specific_configuration_type = PlanConfiguration
229
+ case "plan" :
230
+ specific_configuration_type = PlanConfiguration
231
+ case "apply" :
232
+ specific_configuration_type = ApplyConfiguration
233
+ case "destroy" :
234
+ specific_configuration_type = ApplyConfiguration
235
+ case "output" :
236
+ specific_configuration_type = OutputConfiguration
237
+ case _:
238
+ raise ValueError ("Unsupported task name: " + task_name )
215
239
216
240
def combined_configure_function (
217
241
context : Context ,
218
242
arguments : Arguments ,
219
- configuration : Configuration
243
+ configuration : Configuration ,
220
244
):
221
245
global_configure_function (context , arguments , configuration )
222
246
223
247
specific_configuration = specific_configuration_type (configuration )
224
- extra_configure_function (context , arguments , specific_configuration )
248
+ extra_configure_function (
249
+ context , arguments , specific_configuration
250
+ )
225
251
226
252
configuration .apply_overrides (specific_configuration )
227
253
@@ -230,25 +256,39 @@ def combined_configure_function(
230
256
def create (self ) -> Collection :
231
257
collection = Collection (self .configuration_name )
232
258
259
+ validate_task = self ._task_factory .create_validate_task (
260
+ self ._resolve_configure_function ("validate" ),
261
+ self ._resolve_parameters ("validate" ),
262
+ )
233
263
plan_task = self ._task_factory .create_plan_task (
234
264
self ._resolve_configure_function ("plan" ),
235
- self ._resolve_parameters ("plan" )
265
+ self ._resolve_parameters ("plan" ),
236
266
)
237
267
apply_task = self ._task_factory .create_apply_task (
238
268
self ._resolve_configure_function ("apply" ),
239
- self ._resolve_parameters ("apply" )
269
+ self ._resolve_parameters ("apply" ),
270
+ )
271
+ destroy_task = self ._task_factory .create_destroy_task (
272
+ self ._resolve_configure_function ("destroy" ),
273
+ self ._resolve_parameters ("destroy" ),
240
274
)
241
275
output_task = self ._task_factory .create_output_task (
242
276
self ._resolve_configure_function ("output" ),
243
- self ._resolve_parameters ("output" )
277
+ self ._resolve_parameters ("output" ),
244
278
)
245
279
280
+ collection .add_task ( # pyright: ignore[reportUnknownMemberType]
281
+ validate_task
282
+ )
246
283
collection .add_task ( # pyright: ignore[reportUnknownMemberType]
247
284
plan_task
248
285
)
249
286
collection .add_task ( # pyright: ignore[reportUnknownMemberType]
250
287
apply_task
251
288
)
289
+ collection .add_task ( # pyright: ignore[reportUnknownMemberType]
290
+ destroy_task
291
+ )
252
292
collection .add_task ( # pyright: ignore[reportUnknownMemberType]
253
293
output_task
254
294
)
0 commit comments