Skip to content

Commit b58301a

Browse files
committed
Add OpenTofu 1.9 exclude parameter support
1 parent ee5e8e7 commit b58301a

File tree

21 files changed

+310
-55
lines changed

21 files changed

+310
-55
lines changed

.github/actionlint.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ paths:
3030
- 'property "git_https" is not defined in object type'
3131
- 'property "awkward_.*" is not defined in object type'
3232
- 'property "word" is not defined in object type'
33-
.github/workflows/test-target-replace.yaml:
33+
.github/workflows/test-target-replace-exclude.yaml:
3434
ignore:
3535
- 'property "count" is not defined in object type'
3636
- 'property "foreach" is not defined in object type'
37+
- 'property "keep_me" is not defined in object type'
38+
- 'property "exclude_me" is not defined in object type'
39+
- 'property "also_exclude" is not defined in object type'
3740
.github/workflows/release.yaml:
3841
ignore:
3942
- 'Useless cat.'

.github/workflows/test-target-replace.yaml renamed to .github/workflows/test-target-replace-exclude.yaml

Lines changed: 102 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test actions using target and replace
1+
name: Test actions using target, replace, and exclude
22

33
on:
44
- pull_request
@@ -27,7 +27,7 @@ jobs:
2727
id: plan
2828
with:
2929
label: test-target-replace plan_targeting
30-
path: tests/workflows/test-target-replace
30+
path: tests/workflows/test-target-replace-exclude
3131
target: |
3232
random_string.notpresent
3333
variables: |
@@ -46,7 +46,7 @@ jobs:
4646
uses: ./terraform-plan
4747
id: plan-first-change
4848
with:
49-
path: tests/workflows/test-target-replace
49+
path: tests/workflows/test-target-replace-exclude
5050
target: |
5151
random_string.count[0]
5252
variables: |
@@ -65,7 +65,7 @@ jobs:
6565
uses: ./terraform-apply
6666
id: apply-first-change
6767
with:
68-
path: tests/workflows/test-target-replace
68+
path: tests/workflows/test-target-replace-exclude
6969
target: |
7070
random_string.count[0]
7171
variables: |
@@ -84,7 +84,7 @@ jobs:
8484
uses: ./terraform-plan
8585
id: plan-second-change
8686
with:
87-
path: tests/workflows/test-target-replace
87+
path: tests/workflows/test-target-replace-exclude
8888
target: |
8989
random_string.foreach["hello"]
9090
variables: |
@@ -103,7 +103,7 @@ jobs:
103103
uses: ./terraform-apply
104104
id: apply-second-change
105105
with:
106-
path: tests/workflows/test-target-replace
106+
path: tests/workflows/test-target-replace-exclude
107107
target: |
108108
random_string.foreach["hello"]
109109
variables: |
@@ -129,7 +129,7 @@ jobs:
129129
uses: ./terraform-apply
130130
id: apply-third-change
131131
with:
132-
path: tests/workflows/test-target-replace
132+
path: tests/workflows/test-target-replace-exclude
133133
target: |
134134
random_string.count[0]
135135
random_string.foreach["hello"]
@@ -158,7 +158,7 @@ jobs:
158158
uses: ./terraform-plan
159159
id: plan-targeted-replacement
160160
with:
161-
path: tests/workflows/test-target-replace
161+
path: tests/workflows/test-target-replace-exclude
162162
target: |
163163
random_string.foreach["hello"]
164164
replace: |
@@ -180,7 +180,7 @@ jobs:
180180
uses: ./terraform-apply
181181
id: apply-targeted-replacement
182182
with:
183-
path: tests/workflows/test-target-replace
183+
path: tests/workflows/test-target-replace-exclude
184184
target: |
185185
random_string.foreach["hello"]
186186
replace: |
@@ -210,7 +210,7 @@ jobs:
210210
uses: ./terraform-plan
211211
id: plan-replacement
212212
with:
213-
path: tests/workflows/test-target-replace
213+
path: tests/workflows/test-target-replace-exclude
214214
replace: |
215215
random_string.foreach["hello"]
216216
random_string.count[0]
@@ -230,7 +230,7 @@ jobs:
230230
uses: ./terraform-apply
231231
id: apply-replacement
232232
with:
233-
path: tests/workflows/test-target-replace
233+
path: tests/workflows/test-target-replace-exclude
234234
replace: |
235235
random_string.foreach["hello"]
236236
random_string.count[0]
@@ -268,7 +268,7 @@ jobs:
268268

269269
- name: Setup remote backend
270270
run: |
271-
cat >tests/workflows/test-target-replace/backend.tf <<EOF
271+
cat >tests/workflows/test-target-replace-exclude/backend.tf <<EOF
272272
terraform {
273273
backend "remote" {
274274
organization = "flooktech"
@@ -284,7 +284,7 @@ jobs:
284284
- name: Create test workspace
285285
uses: ./terraform-new-workspace
286286
with:
287-
path: tests/workflows/test-target-replace
287+
path: tests/workflows/test-target-replace-exclude
288288
workspace: ${{ github.head_ref }}
289289
backend_config: token=${{ secrets.TF_API_TOKEN }}
290290

@@ -293,7 +293,7 @@ jobs:
293293
id: plan
294294
with:
295295
label: test-target-replace remote_plan_targeting
296-
path: tests/workflows/test-target-replace
296+
path: tests/workflows/test-target-replace-exclude
297297
target: |
298298
random_string.notpresent
299299
variables: |
@@ -314,7 +314,7 @@ jobs:
314314
uses: ./terraform-plan
315315
id: plan-first-change
316316
with:
317-
path: tests/workflows/test-target-replace
317+
path: tests/workflows/test-target-replace-exclude
318318
target: |
319319
random_string.count[0]
320320
variables: |
@@ -335,7 +335,7 @@ jobs:
335335
uses: ./terraform-apply
336336
id: apply-first-change
337337
with:
338-
path: tests/workflows/test-target-replace
338+
path: tests/workflows/test-target-replace-exclude
339339
target: |
340340
random_string.count[0]
341341
variables: |
@@ -356,7 +356,7 @@ jobs:
356356
uses: ./terraform-plan
357357
id: plan-second-change
358358
with:
359-
path: tests/workflows/test-target-replace
359+
path: tests/workflows/test-target-replace-exclude
360360
target: |
361361
random_string.foreach["hello"]
362362
variables: |
@@ -377,7 +377,7 @@ jobs:
377377
uses: ./terraform-apply
378378
id: apply-second-change
379379
with:
380-
path: tests/workflows/test-target-replace
380+
path: tests/workflows/test-target-replace-exclude
381381
target: |
382382
random_string.foreach["hello"]
383383
variables: |
@@ -405,7 +405,7 @@ jobs:
405405
uses: ./terraform-apply
406406
id: apply-third-change
407407
with:
408-
path: tests/workflows/test-target-replace
408+
path: tests/workflows/test-target-replace-exclude
409409
target: |
410410
random_string.count[0]
411411
random_string.foreach["hello"]
@@ -436,7 +436,7 @@ jobs:
436436
uses: ./terraform-plan
437437
id: plan-targeted-replacement
438438
with:
439-
path: tests/workflows/test-target-replace
439+
path: tests/workflows/test-target-replace-exclude
440440
target: |
441441
random_string.foreach["hello"]
442442
replace: |
@@ -460,7 +460,7 @@ jobs:
460460
uses: ./terraform-apply
461461
id: apply-targeted-replacement
462462
with:
463-
path: tests/workflows/test-target-replace
463+
path: tests/workflows/test-target-replace-exclude
464464
target: |
465465
random_string.foreach["hello"]
466466
replace: |
@@ -492,7 +492,7 @@ jobs:
492492
uses: ./terraform-plan
493493
id: plan-replacement
494494
with:
495-
path: tests/workflows/test-target-replace
495+
path: tests/workflows/test-target-replace-exclude
496496
replace: |
497497
random_string.foreach["hello"]
498498
random_string.count[0]
@@ -514,7 +514,7 @@ jobs:
514514
uses: ./terraform-apply
515515
id: apply-replacement
516516
with:
517-
path: tests/workflows/test-target-replace
517+
path: tests/workflows/test-target-replace-exclude
518518
replace: |
519519
random_string.foreach["hello"]
520520
random_string.count[0]
@@ -543,8 +543,86 @@ jobs:
543543
- name: Destroy the workspace
544544
uses: ./terraform-destroy-workspace
545545
with:
546-
path: tests/workflows/test-target-replace
546+
path: tests/workflows/test-target-replace-exclude
547547
workspace: ${{ github.head_ref }}
548548
variables: |
549549
length = 10
550550
backend_config: token=${{ secrets.TF_API_TOKEN }}
551+
552+
tofu_exclude_testing:
553+
runs-on: ubuntu-24.04
554+
name: OpenTofu exclude testing
555+
permissions:
556+
contents: read
557+
pull-requests: write
558+
steps:
559+
- name: Checkout
560+
uses: actions/checkout@v4
561+
with:
562+
persist-credentials: false
563+
564+
- name: Plan excluding resources
565+
uses: ./tofu-plan
566+
id: plan-exclude
567+
with:
568+
label: test-exclude tofu_exclude_testing
569+
path: tests/workflows/test-target-replace-exclude
570+
exclude: |
571+
random_string.exclude_me
572+
random_string.also_exclude
573+
variables: |
574+
length = 5
575+
576+
- name: Verify exclude plan outputs
577+
env:
578+
CHANGES: ${{ steps.plan-exclude.outputs.changes }}
579+
run: |
580+
if [[ "$CHANGES" != "true" ]]; then
581+
echo "::error:: Exclude plan should have changes for non-excluded resources"
582+
exit 1
583+
fi
584+
585+
- name: Apply excluding resources
586+
uses: ./tofu-apply
587+
id: apply-exclude
588+
with:
589+
label: test-exclude tofu_exclude_testing
590+
path: tests/workflows/test-target-replace-exclude
591+
exclude: |
592+
random_string.exclude_me
593+
random_string.also_exclude
594+
variables: |
595+
length = 5
596+
597+
- name: Verify exclude apply outputs
598+
env:
599+
COUNT: ${{ steps.apply-exclude.outputs.count }}
600+
FOREACH: ${{ steps.apply-exclude.outputs.foreach }}
601+
KEEP_ME: ${{ steps.apply-exclude.outputs.keep_me }}
602+
EXCLUDE_ME: ${{ steps.apply-exclude.outputs.exclude_me }}
603+
ALSO_EXCLUDE: ${{ steps.apply-exclude.outputs.also_exclude }}
604+
run: |
605+
# Should have created non-excluded resources
606+
if [[ "$COUNT" == "" ]]; then
607+
echo "::error:: count output should be set (resource not excluded)"
608+
exit 1
609+
fi
610+
if [[ "$FOREACH" == "" ]]; then
611+
echo "::error:: foreach output should be set (resource not excluded)"
612+
exit 1
613+
fi
614+
if [[ "$KEEP_ME" == "" ]]; then
615+
echo "::error:: keep_me output should be set (resource not excluded)"
616+
exit 1
617+
fi
618+
619+
# Should NOT have created excluded resources
620+
if [[ "$EXCLUDE_ME" != "" ]]; then
621+
echo "::error:: exclude_me output should be empty (resource excluded)"
622+
exit 1
623+
fi
624+
if [[ "$ALSO_EXCLUDE" != "" ]]; then
625+
echo "::error:: also_exclude output should be empty (resource excluded)"
626+
exit 1
627+
fi
628+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ build/
99
__pycache__/
1010
.DS_Store
1111
*.egg-info/
12+
13+
# API cache files
14+
github_api_cache.sqlite

docs-gen/action.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def assert_ordering(self):
172172
"backend_config_file",
173173
"replace",
174174
"target",
175+
"exclude",
175176
"destroy",
176177
"refresh",
177178
"plan_path",

docs-gen/actions/apply.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from inputs.refresh import refresh
2020
from inputs.replace import replace
2121
from inputs.target import target
22+
from inputs.exclude import exclude
2223
from inputs.var_file import var_file
2324
from inputs.variables import variables
2425
from inputs.var import var
@@ -79,6 +80,10 @@
7980
dataclasses.replace(target, description='''
8081
List of resources to apply, one per line.
8182
The apply operation will be limited to these resources and their dependencies.
83+
'''),
84+
dataclasses.replace(exclude, description='''
85+
List of resources to exclude from the apply operation, one per line.
86+
The apply operation will include all resources except the specified ones and their dependencies.
8287
'''),
8388
dataclasses.replace(destroy, description='''
8489
Set to `true` to destroy all resources.

docs-gen/actions/plan.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from inputs.refresh import refresh
2020
from inputs.replace import replace
2121
from inputs.target import target
22+
from inputs.exclude import exclude
2223
from inputs.var import var
2324
from inputs.var_file import var_file
2425
from inputs.variables import variables
@@ -57,6 +58,7 @@
5758
backend_config_file,
5859
replace,
5960
target,
61+
exclude,
6062
destroy,
6163
refresh,
6264
add_github_comment,

docs-gen/actions/refresh.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from inputs.variables import variables
1515
from inputs.workspace import workspace
1616
from inputs.target import target
17+
from inputs.exclude import exclude
1718
from outputs.failure_reason import failure_reason
1819
from outputs.lock_info import lock_info
1920
from outputs.run_id import run_id
@@ -35,6 +36,10 @@
3536
dataclasses.replace(target, description='''
3637
List of resources to target, one per line.
3738
The refresh will be limited to these resources and their dependencies.
39+
'''),
40+
dataclasses.replace(exclude, description='''
41+
List of resources to exclude from the refresh operation, one per line.
42+
The refresh will include all resources except the specified ones and their dependencies.
3843
'''),
3944
parallelism
4045
],

0 commit comments

Comments
 (0)