1- name : Test actions using target and replace
1+ name : Test actions using target, replace, and exclude
22
33on :
44 - pull_request
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 : |
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 : |
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 : |
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,139 @@ 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+
629+ - name : Plan targeting with exclude
630+ uses : ./tofu-plan
631+ id : plan-target-exclude
632+ with :
633+ path : tests/workflows/test-target-replace-exclude
634+ target : |
635+ random_string.exclude_me
636+ random_string.keep_me
637+ exclude : |
638+ random_string.exclude_me
639+ variables : |
640+ length = 5
641+
642+ - name : Verify target+exclude plan
643+ env :
644+ CHANGES : ${{ steps.plan-target-exclude.outputs.changes }}
645+ run : |
646+ if [[ "$CHANGES" != "true" ]]; then
647+ echo "::error:: Target+exclude plan should have changes for keep_me resource"
648+ exit 1
649+ fi
650+
651+ - name : Apply targeting with exclude
652+ uses : ./tofu-apply
653+ id : apply-target-exclude
654+ with :
655+ path : tests/workflows/test-target-replace-exclude
656+ target : |
657+ random_string.exclude_me
658+ random_string.keep_me
659+ exclude : |
660+ random_string.exclude_me
661+ variables : |
662+ length = 7
663+
664+ - name : Verify target+exclude apply
665+ env :
666+ PREV_KEEP_ME : ${{ steps.apply-exclude.outputs.keep_me }}
667+ NEW_KEEP_ME : ${{ steps.apply-target-exclude.outputs.keep_me }}
668+ EXCLUDE_ME : ${{ steps.apply-target-exclude.outputs.exclude_me }}
669+ run : |
670+ # keep_me should have been updated (targeted but not excluded)
671+ if [[ "$NEW_KEEP_ME" == "$PREV_KEEP_ME" ]]; then
672+ echo "::error:: keep_me should have been updated (targeted and not excluded)"
673+ exit 1
674+ fi
675+
676+ # exclude_me should still be empty (excluded overrides target)
677+ if [[ "$EXCLUDE_ME" != "" ]]; then
678+ echo "::error:: exclude_me should still be empty (excluded overrides target)"
679+ exit 1
680+ fi
681+
0 commit comments