From f52ceb64cd7145ede8900baba10ff4ee83579b17 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sat, 18 Mar 2023 12:05:48 -0700 Subject: [PATCH 01/46] Implement testing --- .github/workflows/CICD.yml | 59 ++++++++++++++++++++++++++++++++++ main.tf | 9 +++--- outputs.tf | 2 +- tests/fail/.terraform.lock.hcl | 22 +++++++++++++ tests/fail/main.tf | 5 +++ tests/pass/.terraform.lock.hcl | 22 +++++++++++++ tests/pass/main.tf | 5 +++ versions.tf | 6 ++-- 8 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/CICD.yml create mode 100644 tests/fail/.terraform.lock.hcl create mode 100644 tests/fail/main.tf create mode 100644 tests/pass/.terraform.lock.hcl create mode 100644 tests/pass/main.tf diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml new file mode 100644 index 0000000..8476874 --- /dev/null +++ b/.github/workflows/CICD.yml @@ -0,0 +1,59 @@ +name: "Build" + +on: [push, pull_request] + +jobs: + Matrix: + runs-on: ubuntu-latest + + steps: + - name: Generate Matrix + id: matrix + uses: Invicton-Labs/terraform-module-testing/matrix@main + with: + minimum_tf_version: '0.13.0' + + - name: Output Matrix + run: | + echo "Strategy: ${{ steps.matrix.outputs.strategy }}" + + outputs: + strategy: ${{ steps.matrix.outputs.strategy }} + + Test: + needs: [Matrix] + strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}} + runs-on: ${{ matrix.runs-on }} + container: ${{ matrix.container }} + steps: + - name: Initialize - Pass + id: init + uses: Invicton-Labs/terraform-module-testing/initialize@dev + with: + testing_path: tests/pass + - name: Run Tests - Pass + id: tests + uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + with: + testing_path: tests/pass + + - name: Initialize - Fail + id: init + uses: Invicton-Labs/terraform-module-testing/initialize@dev + with: + testing_path: tests/fail + - name: Run Tests - Fail + id: tests + uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + with: + testing_path: tests/fail + + # This job just waits for all other jobs to pass. We have it here + # so our branch protection rule can reference a single job, instead + # of needing to list every matrix value of every job above. + Passed: + runs-on: ubuntu-latest + needs: [Test] + steps: + - name: Mark tests as passed + run: echo "🎉" \ No newline at end of file diff --git a/main.tf b/main.tf index 8373e4d..a019ad6 100644 --- a/main.tf +++ b/main.tf @@ -3,12 +3,11 @@ // Therefore, unless the "checked" output parameter was actually used somewhere in the parent module, // the assertion check would never actually run. By putting it in a data source, it will always run // regardless of whether any outputs of this module are used in the parent module. The `null` data -// source would be ideal, but it throws a deprecation warning. This template data source is the +// source would be ideal, but it throws a deprecation warning. This CloudInit data source is the // next best alternative, since it is fast and doesn't interact with the operating system at all -// (unlike an external data source, for example). -data "template_file" "check" { - template = "" - vars = { +// (unlike an external data source, for example), and isn't deprecated. +data "cloudinit_config" "check" { + part { content = var.condition ? "" : SEE_ABOVE_ERROR_MESSAGE(true ? null : "ERROR: ${var.error_message}") } } diff --git a/outputs.tf b/outputs.tf index 0b93c50..d2bce0e 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,4 +1,4 @@ output "checked" { description = "Whether the condition has been checked (used for assertion dependencies)." - value = data.template_file.check.rendered == "" ? true : true + value = data.cloudinit_config.check.rendered == "" ? true : true } diff --git a/tests/fail/.terraform.lock.hcl b/tests/fail/.terraform.lock.hcl new file mode 100644 index 0000000..db7a7c3 --- /dev/null +++ b/tests/fail/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/cloudinit" { + version = "2.3.2" + constraints = ">= 2.3.1" + hashes = [ + "h1:2jb+BfT5T96dXxUD2LQ6MtVHpXErd7ZybmMvdWE2jd4=", + "zh:2487e498736ed90f53de8f66fe2b8c05665b9f8ff1506f751c5ee227c7f457d1", + "zh:3d8627d142942336cf65eea6eb6403692f47e9072ff3fa11c3f774a3b93130b3", + "zh:434b643054aeafb5df28d5529b72acc20c6f5ded24decad73b98657af2b53f4f", + "zh:436aa6c2b07d82aa6a9dd746a3e3a627f72787c27c80552ceda6dc52d01f4b6f", + "zh:458274c5aabe65ef4dbd61d43ce759287788e35a2da004e796373f88edcaa422", + "zh:54bc70fa6fb7da33292ae4d9ceef5398d637c7373e729ed4fce59bd7b8d67372", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:893ba267e18749c1a956b69be569f0d7bc043a49c3a0eb4d0d09a8e8b2ca3136", + "zh:95493b7517bce116f75cdd4c63b7c82a9d0d48ec2ef2f5eb836d262ef96d0aa7", + "zh:9ae21ab393be52e3e84e5cce0ef20e690d21f6c10ade7d9d9d22b39851bfeddc", + "zh:cc3b01ac2472e6d59358d54d5e4945032efbc8008739a6d4946ca1b621a16040", + "zh:f23bfe9758f06a1ec10ea3a81c9deedf3a7b42963568997d84a5153f35c5839a", + ] +} diff --git a/tests/fail/main.tf b/tests/fail/main.tf new file mode 100644 index 0000000..749cea6 --- /dev/null +++ b/tests/fail/main.tf @@ -0,0 +1,5 @@ +module "fail" { + source = "../../" + condition = false + error_message = "sample error" +} diff --git a/tests/pass/.terraform.lock.hcl b/tests/pass/.terraform.lock.hcl new file mode 100644 index 0000000..db7a7c3 --- /dev/null +++ b/tests/pass/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/cloudinit" { + version = "2.3.2" + constraints = ">= 2.3.1" + hashes = [ + "h1:2jb+BfT5T96dXxUD2LQ6MtVHpXErd7ZybmMvdWE2jd4=", + "zh:2487e498736ed90f53de8f66fe2b8c05665b9f8ff1506f751c5ee227c7f457d1", + "zh:3d8627d142942336cf65eea6eb6403692f47e9072ff3fa11c3f774a3b93130b3", + "zh:434b643054aeafb5df28d5529b72acc20c6f5ded24decad73b98657af2b53f4f", + "zh:436aa6c2b07d82aa6a9dd746a3e3a627f72787c27c80552ceda6dc52d01f4b6f", + "zh:458274c5aabe65ef4dbd61d43ce759287788e35a2da004e796373f88edcaa422", + "zh:54bc70fa6fb7da33292ae4d9ceef5398d637c7373e729ed4fce59bd7b8d67372", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:893ba267e18749c1a956b69be569f0d7bc043a49c3a0eb4d0d09a8e8b2ca3136", + "zh:95493b7517bce116f75cdd4c63b7c82a9d0d48ec2ef2f5eb836d262ef96d0aa7", + "zh:9ae21ab393be52e3e84e5cce0ef20e690d21f6c10ade7d9d9d22b39851bfeddc", + "zh:cc3b01ac2472e6d59358d54d5e4945032efbc8008739a6d4946ca1b621a16040", + "zh:f23bfe9758f06a1ec10ea3a81c9deedf3a7b42963568997d84a5153f35c5839a", + ] +} diff --git a/tests/pass/main.tf b/tests/pass/main.tf new file mode 100644 index 0000000..b1ac4e3 --- /dev/null +++ b/tests/pass/main.tf @@ -0,0 +1,5 @@ +module "pass" { + source = "../../" + condition = true + error_message = "sample error" +} diff --git a/versions.tf b/versions.tf index cfe9f63..eb46da1 100644 --- a/versions.tf +++ b/versions.tf @@ -1,9 +1,9 @@ terraform { required_version = ">= 0.13.0" required_providers { - template = { - source = "hashicorp/template" - version = ">= 2.2.0" + cloudinit = { + source = "hashicorp/cloudinit" + version = ">= 2.3.1" } } } From 4b337012a37fe738eba77ca2bb0f585720cdbe88 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sat, 18 Mar 2023 12:08:47 -0700 Subject: [PATCH 02/46] Update CICD.yml --- .github/workflows/CICD.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 8476874..331e487 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -27,23 +27,23 @@ jobs: container: ${{ matrix.container }} steps: - name: Initialize - Pass - id: init + id: init-pass uses: Invicton-Labs/terraform-module-testing/initialize@dev with: testing_path: tests/pass - name: Run Tests - Pass - id: tests + id: tests-pass uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: testing_path: tests/pass - name: Initialize - Fail - id: init + id: init-fail uses: Invicton-Labs/terraform-module-testing/initialize@dev with: testing_path: tests/fail - name: Run Tests - Fail - id: tests + id: tests-fail uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: testing_path: tests/fail From 4de4243842ec1f909e243ab3dee25f0de365f878 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 11:52:15 -0400 Subject: [PATCH 03/46] Update CICD.yml --- .github/workflows/CICD.yml | 100 +++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 331e487..a517b71 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -3,57 +3,69 @@ name: "Build" on: [push, pull_request] jobs: - Matrix: + Demo: runs-on: ubuntu-latest - steps: - name: Generate Matrix id: matrix - uses: Invicton-Labs/terraform-module-testing/matrix@main + uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: - minimum_tf_version: '0.13.0' + tf_vars: + - key1: value1 + - key2: value2 + + + # Matrix: + # runs-on: ubuntu-latest - - name: Output Matrix - run: | - echo "Strategy: ${{ steps.matrix.outputs.strategy }}" + # steps: + # - name: Generate Matrix + # id: matrix + # uses: Invicton-Labs/terraform-module-testing/matrix@main + # with: + # minimum_tf_version: '0.13.0' - outputs: - strategy: ${{ steps.matrix.outputs.strategy }} + # - name: Output Matrix + # run: | + # echo "Strategy: ${{ steps.matrix.outputs.strategy }}" + + # outputs: + # strategy: ${{ steps.matrix.outputs.strategy }} - Test: - needs: [Matrix] - strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}} - runs-on: ${{ matrix.runs-on }} - container: ${{ matrix.container }} - steps: - - name: Initialize - Pass - id: init-pass - uses: Invicton-Labs/terraform-module-testing/initialize@dev - with: - testing_path: tests/pass - - name: Run Tests - Pass - id: tests-pass - uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev - with: - testing_path: tests/pass + # Test: + # needs: [Matrix] + # strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}} + # runs-on: ${{ matrix.runs-on }} + # container: ${{ matrix.container }} + # steps: + # - name: Initialize - Pass + # id: init-pass + # uses: Invicton-Labs/terraform-module-testing/initialize@dev + # with: + # testing_path: tests/pass + # - name: Run Tests - Pass + # id: tests-pass + # uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + # with: + # testing_path: tests/pass - - name: Initialize - Fail - id: init-fail - uses: Invicton-Labs/terraform-module-testing/initialize@dev - with: - testing_path: tests/fail - - name: Run Tests - Fail - id: tests-fail - uses: Invicton-Labs/terraform-module-testing/apply-failure@dev - with: - testing_path: tests/fail + # - name: Initialize - Fail + # id: init-fail + # uses: Invicton-Labs/terraform-module-testing/initialize@dev + # with: + # testing_path: tests/fail + # - name: Run Tests - Fail + # id: tests-fail + # uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + # with: + # testing_path: tests/fail - # This job just waits for all other jobs to pass. We have it here - # so our branch protection rule can reference a single job, instead - # of needing to list every matrix value of every job above. - Passed: - runs-on: ubuntu-latest - needs: [Test] - steps: - - name: Mark tests as passed - run: echo "🎉" \ No newline at end of file + # # This job just waits for all other jobs to pass. We have it here + # # so our branch protection rule can reference a single job, instead + # # of needing to list every matrix value of every job above. + # Passed: + # runs-on: ubuntu-latest + # needs: [Test] + # steps: + # - name: Mark tests as passed + # run: echo "🎉" \ No newline at end of file From 37b908d8776530b99c6daa0bb7b5e789494a4ad8 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 11:52:54 -0400 Subject: [PATCH 04/46] Update CICD.yml --- .github/workflows/CICD.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index a517b71..40fd2cb 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -10,9 +10,9 @@ jobs: id: matrix uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: - tf_vars: - - key1: value1 - - key2: value2 + tf_vars: | + key1: value1 + key2: value2 # Matrix: From 19304ac670e5a26a9ba283b2b1a9d0a67fe94847 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 11:53:32 -0400 Subject: [PATCH 05/46] Update CICD.yml --- .github/workflows/CICD.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 40fd2cb..c5a7029 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -11,8 +11,8 @@ jobs: uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: tf_vars: | - key1: value1 - key2: value2 + key1=value1 + key2=value2 # Matrix: From 7acac4d7b26e6410f0607b686c23992ac8131a85 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 12:28:36 -0400 Subject: [PATCH 06/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index c5a7029..4d1c3be 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -13,6 +13,8 @@ jobs: tf_vars: | key1=value1 key2=value2 + key3=va"l"ue3 + key4=val'u'e4 # Matrix: From 5d2c67336415d29015cea80f30fb2fe7ed4f8afd Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 12:42:27 -0400 Subject: [PATCH 07/46] Testing --- .github/workflows/CICD.yml | 1 + tests/outputs/main.tf | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/outputs/main.tf diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 4d1c3be..af802ab 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -10,6 +10,7 @@ jobs: id: matrix uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: + tf_path: tests/outputs tf_vars: | key1=value1 key2=value2 diff --git a/tests/outputs/main.tf b/tests/outputs/main.tf new file mode 100644 index 0000000..935d1a2 --- /dev/null +++ b/tests/outputs/main.tf @@ -0,0 +1,25 @@ +variable "key1" { + type = number +} +variable "key2" { + type = string +} +variable "key3" { + type = list(string) +} +variable "key4" { + type = map(string) +} + +output "key1" { + value = var.key1 +} +output "key2" { + value = var.key1 +} +output "key3" { + value = var.key1 +} +output "key4" { + value = var.key1 +} From 24846b4611b7bc70db6e12e054e57ab0003bb4c7 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 12:43:30 -0400 Subject: [PATCH 08/46] Update CICD.yml --- .github/workflows/CICD.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index af802ab..8c3428b 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -12,10 +12,10 @@ jobs: with: tf_path: tests/outputs tf_vars: | - key1=value1 - key2=value2 - key3=va"l"ue3 - key4=val'u'e4 + key1=444 + key2=va"l"u'e'2 + key3=["abc", "def"] + key4={"subkey1": "subval1", "subkey2": "subval2"} # Matrix: From a8c60f9c2978805dc878d126f4d33da2f674cfc9 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 12:51:22 -0400 Subject: [PATCH 09/46] Update CICD.yml --- .github/workflows/CICD.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 8c3428b..04ab698 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -6,6 +6,12 @@ jobs: Demo: runs-on: ubuntu-latest steps: + - name: Initialize Terraform + id: matrix + uses: Invicton-Labs/terraform-module-testing/initialize@dev + with: + tf_path: tests/outputs + - name: Generate Matrix id: matrix uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev From e584f10332736fd86152534ef7c427b4e6918ff7 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 12:51:44 -0400 Subject: [PATCH 10/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 04ab698..a6b55f1 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Initialize Terraform - id: matrix + id: initialize uses: Invicton-Labs/terraform-module-testing/initialize@dev with: tf_path: tests/outputs From e984e927eaa0910213764da8b76f0d5a1da89a0b Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 13:10:03 -0400 Subject: [PATCH 11/46] Update CICD.yml --- .github/workflows/CICD.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index a6b55f1..460d219 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -17,11 +17,11 @@ jobs: uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: tf_path: tests/outputs - tf_vars: | - key1=444 - key2=va"l"u'e'2 - key3=["abc", "def"] - key4={"subkey1": "subval1", "subkey2": "subval2"} + tf_args: | + -var="key1=444" + -var="key2=va"l"u'e'2" + -var="key3=[\"abc\", \"def\"]" + -var="key4={\"subkey1\": \"subval1\", \"subkey2\": \"subval2\"}" # Matrix: From fd465e23783cb8786d85e17278b29f15d36287e8 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 13:10:37 -0400 Subject: [PATCH 12/46] Update main.tf --- tests/outputs/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/outputs/main.tf b/tests/outputs/main.tf index 935d1a2..0a52dcf 100644 --- a/tests/outputs/main.tf +++ b/tests/outputs/main.tf @@ -15,11 +15,11 @@ output "key1" { value = var.key1 } output "key2" { - value = var.key1 + value = var.key2 } output "key3" { - value = var.key1 + value = var.key3 } output "key4" { - value = var.key1 + value = var.key4 } From f23f1a6082a169cdc2c8312d4c50549d494f2e19 Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 13:11:18 -0400 Subject: [PATCH 13/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 460d219..bee3979 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -19,7 +19,7 @@ jobs: tf_path: tests/outputs tf_args: | -var="key1=444" - -var="key2=va"l"u'e'2" + -var="key2=va\"l\"u'e'2" -var="key3=[\"abc\", \"def\"]" -var="key4={\"subkey1\": \"subval1\", \"subkey2\": \"subval2\"}" From 5a0a77fcbf0929a733c6d68c9b0e997cd11fb50d Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 13:15:46 -0400 Subject: [PATCH 14/46] Update CICD --- .github/workflows/CICD.yml | 109 +++++++++++++++---------------------- tests/outputs/main.tf | 25 --------- 2 files changed, 44 insertions(+), 90 deletions(-) delete mode 100644 tests/outputs/main.tf diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index bee3979..5ed00e0 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -3,78 +3,57 @@ name: "Build" on: [push, pull_request] jobs: - Demo: + Matrix: runs-on: ubuntu-latest - steps: - - name: Initialize Terraform - id: initialize - uses: Invicton-Labs/terraform-module-testing/initialize@dev - with: - tf_path: tests/outputs + steps: - name: Generate Matrix id: matrix - uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + uses: Invicton-Labs/terraform-module-testing/matrix@dev with: - tf_path: tests/outputs - tf_args: | - -var="key1=444" - -var="key2=va\"l\"u'e'2" - -var="key3=[\"abc\", \"def\"]" - -var="key4={\"subkey1\": \"subval1\", \"subkey2\": \"subval2\"}" + minimum_tf_version: '0.13.0' + - name: Output Matrix + run: | + echo "Strategy: ${{ steps.matrix.outputs.strategy }}" - # Matrix: - # runs-on: ubuntu-latest - - # steps: - # - name: Generate Matrix - # id: matrix - # uses: Invicton-Labs/terraform-module-testing/matrix@main - # with: - # minimum_tf_version: '0.13.0' - - # - name: Output Matrix - # run: | - # echo "Strategy: ${{ steps.matrix.outputs.strategy }}" - - # outputs: - # strategy: ${{ steps.matrix.outputs.strategy }} + outputs: + strategy: ${{ steps.matrix.outputs.strategy }} - # Test: - # needs: [Matrix] - # strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}} - # runs-on: ${{ matrix.runs-on }} - # container: ${{ matrix.container }} - # steps: - # - name: Initialize - Pass - # id: init-pass - # uses: Invicton-Labs/terraform-module-testing/initialize@dev - # with: - # testing_path: tests/pass - # - name: Run Tests - Pass - # id: tests-pass - # uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev - # with: - # testing_path: tests/pass + Test: + needs: [Matrix] + strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}} + runs-on: ${{ matrix.runs-on }} + container: ${{ matrix.container }} + steps: + - name: Initialize - Pass + id: init-pass + uses: Invicton-Labs/terraform-module-testing/initialize@dev + with: + tf_path: tests/pass + - name: Run Tests - Pass + id: tests-pass + uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + with: + tf_path: tests/pass - # - name: Initialize - Fail - # id: init-fail - # uses: Invicton-Labs/terraform-module-testing/initialize@dev - # with: - # testing_path: tests/fail - # - name: Run Tests - Fail - # id: tests-fail - # uses: Invicton-Labs/terraform-module-testing/apply-failure@dev - # with: - # testing_path: tests/fail + - name: Initialize - Fail + id: init-fail + uses: Invicton-Labs/terraform-module-testing/initialize@dev + with: + tf_path: tests/fail + - name: Run Tests - Fail + id: tests-fail + uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + with: + tf_path: tests/fail - # # This job just waits for all other jobs to pass. We have it here - # # so our branch protection rule can reference a single job, instead - # # of needing to list every matrix value of every job above. - # Passed: - # runs-on: ubuntu-latest - # needs: [Test] - # steps: - # - name: Mark tests as passed - # run: echo "🎉" \ No newline at end of file + # This job just waits for all other jobs to pass. We have it here + # so our branch protection rule can reference a single job, instead + # of needing to list every matrix value of every job above. + Passed: + runs-on: ubuntu-latest + needs: [Test] + steps: + - name: Mark tests as passed + run: echo "🎉" \ No newline at end of file diff --git a/tests/outputs/main.tf b/tests/outputs/main.tf deleted file mode 100644 index 0a52dcf..0000000 --- a/tests/outputs/main.tf +++ /dev/null @@ -1,25 +0,0 @@ -variable "key1" { - type = number -} -variable "key2" { - type = string -} -variable "key3" { - type = list(string) -} -variable "key4" { - type = map(string) -} - -output "key1" { - value = var.key1 -} -output "key2" { - value = var.key2 -} -output "key3" { - value = var.key3 -} -output "key4" { - value = var.key4 -} From 100de725b0a2474305a08ae7fc47364d9abe1e9d Mon Sep 17 00:00:00 2001 From: KyleKotowick Date: Sun, 26 Mar 2023 13:43:26 -0400 Subject: [PATCH 15/46] Update CICD.yml --- .github/workflows/CICD.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 5ed00e0..20b5f22 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Generate Matrix id: matrix - uses: Invicton-Labs/terraform-module-testing/matrix@dev + uses: Invicton-Labs/terraform-module-testing/matrix@v0.1.0 with: minimum_tf_version: '0.13.0' @@ -28,23 +28,23 @@ jobs: steps: - name: Initialize - Pass id: init-pass - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 with: tf_path: tests/pass - name: Run Tests - Pass id: tests-pass - uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.1.0 with: tf_path: tests/pass - name: Initialize - Fail id: init-fail - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 with: tf_path: tests/fail - name: Run Tests - Fail id: tests-fail - uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.1.0 with: tf_path: tests/fail From 00a8319394a314c3355154dfb3e9ee2b8cf1ee7c Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Sun, 7 Jul 2024 12:05:50 -0400 Subject: [PATCH 16/46] Refactor to use new variable validation capabilities --- LICENSE | 2 +- main.tf | 13 ------------- outputs.tf | 12 +++++++++++- variables.tf | 19 ++++++++++++++----- versions.tf | 8 +------- 5 files changed, 27 insertions(+), 27 deletions(-) delete mode 100644 main.tf diff --git a/LICENSE b/LICENSE index 65ede90..667eff7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021-2022 Invicton Labs (https://invictonlabs.com) +Copyright (c) 2021-2024 Invicton Labs (https://invictonlabs.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/main.tf b/main.tf deleted file mode 100644 index a019ad6..0000000 --- a/main.tf +++ /dev/null @@ -1,13 +0,0 @@ -// Previously, this check was done in a local. Somewhere around TF v1.4.0 though, it changed -// such that locals wouldn't be computed unless they were necessary for a resource or data source. -// Therefore, unless the "checked" output parameter was actually used somewhere in the parent module, -// the assertion check would never actually run. By putting it in a data source, it will always run -// regardless of whether any outputs of this module are used in the parent module. The `null` data -// source would be ideal, but it throws a deprecation warning. This CloudInit data source is the -// next best alternative, since it is fast and doesn't interact with the operating system at all -// (unlike an external data source, for example), and isn't deprecated. -data "cloudinit_config" "check" { - part { - content = var.condition ? "" : SEE_ABOVE_ERROR_MESSAGE(true ? null : "ERROR: ${var.error_message}") - } -} diff --git a/outputs.tf b/outputs.tf index d2bce0e..c653073 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,4 +1,14 @@ +output "error_message" { + description = "The value of the `error_message` input variable." + value = var.error_message +} + +output "condition" { + description = "The value of the `condition` input variable." + value = var.condition +} + output "checked" { description = "Whether the condition has been checked (used for assertion dependencies)." - value = data.cloudinit_config.check.rendered == "" ? true : true + value = var.condition == true ? true : true } diff --git a/variables.tf b/variables.tf index ed0106b..0350283 100644 --- a/variables.tf +++ b/variables.tf @@ -1,9 +1,18 @@ -variable "condition" { - description = "The condition to ensure is `true`." - type = bool -} - variable "error_message" { description = "The error message to display if the condition evaluates to `false`." type = string + nullable = false +} + +variable "condition" { + description = "The condition to ensure is `true`." + type = bool + validation { + // We have to use var.error_message != null to force the evaluation to wait + // until var.error_message is known. Otherwise, it can fail during the validation + // phase but won't output the proper error message. + // https://github.com/hashicorp/terraform/issues/35397 + condition = var.error_message != null && var.condition == true + error_message = var.error_message + } } diff --git a/versions.tf b/versions.tf index eb46da1..bfb98ab 100644 --- a/versions.tf +++ b/versions.tf @@ -1,9 +1,3 @@ terraform { - required_version = ">= 0.13.0" - required_providers { - cloudinit = { - source = "hashicorp/cloudinit" - version = ">= 2.3.1" - } - } + required_version = ">= 1.9.0" } From bdc74f48f5788bd4e0aa763732642d84fa099255 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Sun, 7 Jul 2024 12:07:03 -0400 Subject: [PATCH 17/46] Update CI/CD minimum Terraform version --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 20b5f22..0154a6d 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -11,7 +11,7 @@ jobs: id: matrix uses: Invicton-Labs/terraform-module-testing/matrix@v0.1.0 with: - minimum_tf_version: '0.13.0' + minimum_tf_version: '1.9.0' - name: Output Matrix run: | From f37120b51281fdd3ed247540a1440ba3f10a5097 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 11:53:27 -0400 Subject: [PATCH 18/46] Update CICD.yml --- .github/workflows/CICD.yml | 72 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 0154a6d..5be9843 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Generate Matrix id: matrix - uses: Invicton-Labs/terraform-module-testing/matrix@v0.1.0 + uses: Invicton-Labs/terraform-module-testing/matrix@a4a51fb1fa70a00b9f468ff48540cb44e38c1c74 with: minimum_tf_version: '1.9.0' @@ -20,40 +20,40 @@ jobs: outputs: strategy: ${{ steps.matrix.outputs.strategy }} - Test: - needs: [Matrix] - strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}} - runs-on: ${{ matrix.runs-on }} - container: ${{ matrix.container }} - steps: - - name: Initialize - Pass - id: init-pass - uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 - with: - tf_path: tests/pass - - name: Run Tests - Pass - id: tests-pass - uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.1.0 - with: - tf_path: tests/pass + # Test: + # needs: [Matrix] + # strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}} + # runs-on: ${{ matrix.runs-on }} + # container: ${{ matrix.container }} + # steps: + # - name: Initialize - Pass + # id: init-pass + # uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 + # with: + # tf_path: tests/pass + # - name: Run Tests - Pass + # id: tests-pass + # uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.1.0 + # with: + # tf_path: tests/pass - - name: Initialize - Fail - id: init-fail - uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 - with: - tf_path: tests/fail - - name: Run Tests - Fail - id: tests-fail - uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.1.0 - with: - tf_path: tests/fail + # - name: Initialize - Fail + # id: init-fail + # uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 + # with: + # tf_path: tests/fail + # - name: Run Tests - Fail + # id: tests-fail + # uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.1.0 + # with: + # tf_path: tests/fail - # This job just waits for all other jobs to pass. We have it here - # so our branch protection rule can reference a single job, instead - # of needing to list every matrix value of every job above. - Passed: - runs-on: ubuntu-latest - needs: [Test] - steps: - - name: Mark tests as passed - run: echo "🎉" \ No newline at end of file + # # This job just waits for all other jobs to pass. We have it here + # # so our branch protection rule can reference a single job, instead + # # of needing to list every matrix value of every job above. + # Passed: + # runs-on: ubuntu-latest + # needs: [Test] + # steps: + # - name: Mark tests as passed + # run: echo "🎉" \ No newline at end of file From 4d01d6210ef3b7df469d3dbe53bc61d17ba3e7ca Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 11:55:55 -0400 Subject: [PATCH 19/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 5be9843..65c2cda 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Generate Matrix id: matrix - uses: Invicton-Labs/terraform-module-testing/matrix@a4a51fb1fa70a00b9f468ff48540cb44e38c1c74 + uses: Invicton-Labs/terraform-module-testing/matrix@feat/additional-os with: minimum_tf_version: '1.9.0' From 4f2561d873e1270b473d7923391d8aed3fb92fdf Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 12:04:15 -0400 Subject: [PATCH 20/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 65c2cda..e3b320d 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -12,6 +12,8 @@ jobs: uses: Invicton-Labs/terraform-module-testing/matrix@feat/additional-os with: minimum_tf_version: '1.9.0' + additional_runners: 'macos-13, windows-2019' + additional_images: 'amazonlinux:2' - name: Output Matrix run: | From 47726b421bad6f423e7edf5f70ba8b1809f5987a Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 12:48:08 -0400 Subject: [PATCH 21/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index e3b320d..0b9ee5d 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -11,7 +11,7 @@ jobs: id: matrix uses: Invicton-Labs/terraform-module-testing/matrix@feat/additional-os with: - minimum_tf_version: '1.9.0' + minimum_tf_version: '1.7.0' additional_runners: 'macos-13, windows-2019' additional_images: 'amazonlinux:2' From 17bc1b7814b6f678ed12d4c2061939759bf6caf6 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 12:58:42 -0400 Subject: [PATCH 22/46] Update CICD.yml --- .github/workflows/CICD.yml | 70 +++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 0b9ee5d..4cc5ac0 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -22,40 +22,40 @@ jobs: outputs: strategy: ${{ steps.matrix.outputs.strategy }} - # Test: - # needs: [Matrix] - # strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}} - # runs-on: ${{ matrix.runs-on }} - # container: ${{ matrix.container }} - # steps: - # - name: Initialize - Pass - # id: init-pass - # uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 - # with: - # tf_path: tests/pass - # - name: Run Tests - Pass - # id: tests-pass - # uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.1.0 - # with: - # tf_path: tests/pass + Test: + needs: [Matrix] + strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}} + runs-on: ${{ matrix.runs-on }} + container: ${{ matrix.container }} + steps: + - name: Initialize - Pass + id: init-pass + uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 + with: + tf_path: tests/pass + - name: Run Tests - Pass + id: tests-pass + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.1.0 + with: + tf_path: tests/pass - # - name: Initialize - Fail - # id: init-fail - # uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 - # with: - # tf_path: tests/fail - # - name: Run Tests - Fail - # id: tests-fail - # uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.1.0 - # with: - # tf_path: tests/fail + - name: Initialize - Fail + id: init-fail + uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 + with: + tf_path: tests/fail + - name: Run Tests - Fail + id: tests-fail + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.1.0 + with: + tf_path: tests/fail - # # This job just waits for all other jobs to pass. We have it here - # # so our branch protection rule can reference a single job, instead - # # of needing to list every matrix value of every job above. - # Passed: - # runs-on: ubuntu-latest - # needs: [Test] - # steps: - # - name: Mark tests as passed - # run: echo "🎉" \ No newline at end of file + # This job just waits for all other jobs to pass. We have it here + # so our branch protection rule can reference a single job, instead + # of needing to list every matrix value of every job above. + Passed: + runs-on: ubuntu-latest + needs: [Test] + steps: + - name: Mark tests as passed + run: echo "🎉" \ No newline at end of file From 32e3442d9d23abeabd1044e8b17acbcf3bf85973 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 13:03:21 -0400 Subject: [PATCH 23/46] Update CICD.yml --- .github/workflows/CICD.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 4cc5ac0..eb31f65 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -30,23 +30,23 @@ jobs: steps: - name: Initialize - Pass id: init-pass - uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 + uses: Invicton-Labs/terraform-module-testing/initialize@feat/additional-os with: tf_path: tests/pass - name: Run Tests - Pass id: tests-pass - uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.1.0 + uses: Invicton-Labs/terraform-module-testing/apply-destroy@feat/additional-os with: tf_path: tests/pass - name: Initialize - Fail id: init-fail - uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0 + uses: Invicton-Labs/terraform-module-testing/initialize@feat/additional-os with: tf_path: tests/fail - name: Run Tests - Fail id: tests-fail - uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.1.0 + uses: Invicton-Labs/terraform-module-testing/apply-failure@feat/additional-os with: tf_path: tests/fail @@ -58,4 +58,4 @@ jobs: needs: [Test] steps: - name: Mark tests as passed - run: echo "🎉" \ No newline at end of file + run: echo "🎉" From da3d24f3849c92c8fe44c2a78bebc7c8685ea151 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 13:14:26 -0400 Subject: [PATCH 24/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index eb31f65..8ecd9a5 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -11,7 +11,7 @@ jobs: id: matrix uses: Invicton-Labs/terraform-module-testing/matrix@feat/additional-os with: - minimum_tf_version: '1.7.0' + minimum_tf_version: '1.9.0' additional_runners: 'macos-13, windows-2019' additional_images: 'amazonlinux:2' From 7991f18a45a736a7f60f00cfd5ecce686ad77ac0 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 13:16:50 -0400 Subject: [PATCH 25/46] Update CICD.yml --- .github/workflows/CICD.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 8ecd9a5..e285987 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -13,7 +13,6 @@ jobs: with: minimum_tf_version: '1.9.0' additional_runners: 'macos-13, windows-2019' - additional_images: 'amazonlinux:2' - name: Output Matrix run: | From 0037be7ef82d4e2a158c2df00b3d0f0e21b948d4 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 13:36:31 -0400 Subject: [PATCH 26/46] Update CICD.yml --- .github/workflows/CICD.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index e285987..8ecd9a5 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -13,6 +13,7 @@ jobs: with: minimum_tf_version: '1.9.0' additional_runners: 'macos-13, windows-2019' + additional_images: 'amazonlinux:2' - name: Output Matrix run: | From 1ef9c6db0a31e86f00b873b310851ecc0711fe8d Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 15:03:48 -0400 Subject: [PATCH 27/46] Update CICD.yml --- .github/workflows/CICD.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 8ecd9a5..e285987 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -13,7 +13,6 @@ jobs: with: minimum_tf_version: '1.9.0' additional_runners: 'macos-13, windows-2019' - additional_images: 'amazonlinux:2' - name: Output Matrix run: | From 40a0160150e474bcf8dbbb6cbd923a139ac4a9c6 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Thu, 11 Jul 2024 15:08:57 -0400 Subject: [PATCH 28/46] Update CICD.yml --- .github/workflows/CICD.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index e285987..271d828 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -9,10 +9,9 @@ jobs: steps: - name: Generate Matrix id: matrix - uses: Invicton-Labs/terraform-module-testing/matrix@feat/additional-os + uses: Invicton-Labs/terraform-module-testing/matrix@v0.2.0 with: minimum_tf_version: '1.9.0' - additional_runners: 'macos-13, windows-2019' - name: Output Matrix run: | @@ -29,23 +28,23 @@ jobs: steps: - name: Initialize - Pass id: init-pass - uses: Invicton-Labs/terraform-module-testing/initialize@feat/additional-os + uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 with: tf_path: tests/pass - name: Run Tests - Pass id: tests-pass - uses: Invicton-Labs/terraform-module-testing/apply-destroy@feat/additional-os + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.2.0 with: tf_path: tests/pass - name: Initialize - Fail id: init-fail - uses: Invicton-Labs/terraform-module-testing/initialize@feat/additional-os + uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 with: tf_path: tests/fail - name: Run Tests - Fail id: tests-fail - uses: Invicton-Labs/terraform-module-testing/apply-failure@feat/additional-os + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.2.0 with: tf_path: tests/fail From b95683eb255367508bec7874694608b97a761e8f Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 09:02:10 -0800 Subject: [PATCH 29/46] Update version, add tests for forced output checking --- .github/workflows/CICD.yml | 24 +++++++++++++++++++++++- tests/fail-output/.terraform.lock.hcl | 22 ++++++++++++++++++++++ tests/fail-output/main.tf | 11 +++++++++++ tests/pass-output/.terraform.lock.hcl | 22 ++++++++++++++++++++++ tests/pass-output/main.tf | 11 +++++++++++ versions.tf | 2 +- 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 tests/fail-output/.terraform.lock.hcl create mode 100644 tests/fail-output/main.tf create mode 100644 tests/pass-output/.terraform.lock.hcl create mode 100644 tests/pass-output/main.tf diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 271d828..f54a435 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -11,7 +11,7 @@ jobs: id: matrix uses: Invicton-Labs/terraform-module-testing/matrix@v0.2.0 with: - minimum_tf_version: '1.9.0' + minimum_tf_version: '1.10.3' - name: Output Matrix run: | @@ -37,6 +37,17 @@ jobs: with: tf_path: tests/pass + - name: Initialize - Pass (With Output) + id: init-pass-output + uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + with: + tf_path: tests/pass-output + - name: Run Tests - Pass (With Output) + id: tests-pass-output + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.2.0 + with: + tf_path: tests/pass-output + - name: Initialize - Fail id: init-fail uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 @@ -48,6 +59,17 @@ jobs: with: tf_path: tests/fail + - name: Initialize - Fail (Output) + id: init-fail-output + uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + with: + tf_path: tests/fail-output + - name: Run Tests - Fail (Output) + id: tests-fail-output + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.2.0 + with: + tf_path: tests/fail-output + # This job just waits for all other jobs to pass. We have it here # so our branch protection rule can reference a single job, instead # of needing to list every matrix value of every job above. diff --git a/tests/fail-output/.terraform.lock.hcl b/tests/fail-output/.terraform.lock.hcl new file mode 100644 index 0000000..db7a7c3 --- /dev/null +++ b/tests/fail-output/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/cloudinit" { + version = "2.3.2" + constraints = ">= 2.3.1" + hashes = [ + "h1:2jb+BfT5T96dXxUD2LQ6MtVHpXErd7ZybmMvdWE2jd4=", + "zh:2487e498736ed90f53de8f66fe2b8c05665b9f8ff1506f751c5ee227c7f457d1", + "zh:3d8627d142942336cf65eea6eb6403692f47e9072ff3fa11c3f774a3b93130b3", + "zh:434b643054aeafb5df28d5529b72acc20c6f5ded24decad73b98657af2b53f4f", + "zh:436aa6c2b07d82aa6a9dd746a3e3a627f72787c27c80552ceda6dc52d01f4b6f", + "zh:458274c5aabe65ef4dbd61d43ce759287788e35a2da004e796373f88edcaa422", + "zh:54bc70fa6fb7da33292ae4d9ceef5398d637c7373e729ed4fce59bd7b8d67372", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:893ba267e18749c1a956b69be569f0d7bc043a49c3a0eb4d0d09a8e8b2ca3136", + "zh:95493b7517bce116f75cdd4c63b7c82a9d0d48ec2ef2f5eb836d262ef96d0aa7", + "zh:9ae21ab393be52e3e84e5cce0ef20e690d21f6c10ade7d9d9d22b39851bfeddc", + "zh:cc3b01ac2472e6d59358d54d5e4945032efbc8008739a6d4946ca1b621a16040", + "zh:f23bfe9758f06a1ec10ea3a81c9deedf3a7b42963568997d84a5153f35c5839a", + ] +} diff --git a/tests/fail-output/main.tf b/tests/fail-output/main.tf new file mode 100644 index 0000000..16ca369 --- /dev/null +++ b/tests/fail-output/main.tf @@ -0,0 +1,11 @@ +module "fail" { + source = "../../" + condition = false + error_message = "sample error" +} + +// Force the module and conditions to be evaluated +// by using the module output in a config output. +output "result" { + value = module.fail.checked +} diff --git a/tests/pass-output/.terraform.lock.hcl b/tests/pass-output/.terraform.lock.hcl new file mode 100644 index 0000000..db7a7c3 --- /dev/null +++ b/tests/pass-output/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/cloudinit" { + version = "2.3.2" + constraints = ">= 2.3.1" + hashes = [ + "h1:2jb+BfT5T96dXxUD2LQ6MtVHpXErd7ZybmMvdWE2jd4=", + "zh:2487e498736ed90f53de8f66fe2b8c05665b9f8ff1506f751c5ee227c7f457d1", + "zh:3d8627d142942336cf65eea6eb6403692f47e9072ff3fa11c3f774a3b93130b3", + "zh:434b643054aeafb5df28d5529b72acc20c6f5ded24decad73b98657af2b53f4f", + "zh:436aa6c2b07d82aa6a9dd746a3e3a627f72787c27c80552ceda6dc52d01f4b6f", + "zh:458274c5aabe65ef4dbd61d43ce759287788e35a2da004e796373f88edcaa422", + "zh:54bc70fa6fb7da33292ae4d9ceef5398d637c7373e729ed4fce59bd7b8d67372", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:893ba267e18749c1a956b69be569f0d7bc043a49c3a0eb4d0d09a8e8b2ca3136", + "zh:95493b7517bce116f75cdd4c63b7c82a9d0d48ec2ef2f5eb836d262ef96d0aa7", + "zh:9ae21ab393be52e3e84e5cce0ef20e690d21f6c10ade7d9d9d22b39851bfeddc", + "zh:cc3b01ac2472e6d59358d54d5e4945032efbc8008739a6d4946ca1b621a16040", + "zh:f23bfe9758f06a1ec10ea3a81c9deedf3a7b42963568997d84a5153f35c5839a", + ] +} diff --git a/tests/pass-output/main.tf b/tests/pass-output/main.tf new file mode 100644 index 0000000..0ec99a3 --- /dev/null +++ b/tests/pass-output/main.tf @@ -0,0 +1,11 @@ +module "pass" { + source = "../../" + condition = true + error_message = "sample error" +} + +// Force the module and conditions to be evaluated +// by using the module output in a config output. +output "result" { + value = module.pass.checked +} diff --git a/versions.tf b/versions.tf index bfb98ab..12bb31a 100644 --- a/versions.tf +++ b/versions.tf @@ -1,3 +1,3 @@ terraform { - required_version = ">= 1.9.0" + required_version = ">= 1.10.3" } From 57698a842d09cf04612a98883066989d1e669df3 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 09:04:50 -0800 Subject: [PATCH 30/46] Add tests for conditions not known until the apply step --- .github/workflows/CICD.yml | 22 ++++++++++++++++++++++ tests/fail-delayed/.terraform.lock.hcl | 22 ++++++++++++++++++++++ tests/fail-delayed/main.tf | 6 ++++++ tests/pass-delayed/.terraform.lock.hcl | 22 ++++++++++++++++++++++ tests/pass-delayed/main.tf | 6 ++++++ 5 files changed, 78 insertions(+) create mode 100644 tests/fail-delayed/.terraform.lock.hcl create mode 100644 tests/fail-delayed/main.tf create mode 100644 tests/pass-delayed/.terraform.lock.hcl create mode 100644 tests/pass-delayed/main.tf diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index f54a435..a4f9d53 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -48,6 +48,17 @@ jobs: with: tf_path: tests/pass-output + - name: Initialize - Pass - Delayed + id: init-pass-delayed + uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + with: + tf_path: tests/pass-delayed + - name: Run Tests - Pass - Delayed + id: tests-pass-delayed + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.2.0 + with: + tf_path: tests/pass-delayed + - name: Initialize - Fail id: init-fail uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 @@ -70,6 +81,17 @@ jobs: with: tf_path: tests/fail-output + - name: Initialize - Fail - Delayed + id: init-fail-delayed + uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + with: + tf_path: tests/fail-delayed + - name: Run Tests - Fail - Delayed + id: tests-fail-delayed + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.2.0 + with: + tf_path: tests/fail-delayed + # This job just waits for all other jobs to pass. We have it here # so our branch protection rule can reference a single job, instead # of needing to list every matrix value of every job above. diff --git a/tests/fail-delayed/.terraform.lock.hcl b/tests/fail-delayed/.terraform.lock.hcl new file mode 100644 index 0000000..db7a7c3 --- /dev/null +++ b/tests/fail-delayed/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/cloudinit" { + version = "2.3.2" + constraints = ">= 2.3.1" + hashes = [ + "h1:2jb+BfT5T96dXxUD2LQ6MtVHpXErd7ZybmMvdWE2jd4=", + "zh:2487e498736ed90f53de8f66fe2b8c05665b9f8ff1506f751c5ee227c7f457d1", + "zh:3d8627d142942336cf65eea6eb6403692f47e9072ff3fa11c3f774a3b93130b3", + "zh:434b643054aeafb5df28d5529b72acc20c6f5ded24decad73b98657af2b53f4f", + "zh:436aa6c2b07d82aa6a9dd746a3e3a627f72787c27c80552ceda6dc52d01f4b6f", + "zh:458274c5aabe65ef4dbd61d43ce759287788e35a2da004e796373f88edcaa422", + "zh:54bc70fa6fb7da33292ae4d9ceef5398d637c7373e729ed4fce59bd7b8d67372", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:893ba267e18749c1a956b69be569f0d7bc043a49c3a0eb4d0d09a8e8b2ca3136", + "zh:95493b7517bce116f75cdd4c63b7c82a9d0d48ec2ef2f5eb836d262ef96d0aa7", + "zh:9ae21ab393be52e3e84e5cce0ef20e690d21f6c10ade7d9d9d22b39851bfeddc", + "zh:cc3b01ac2472e6d59358d54d5e4945032efbc8008739a6d4946ca1b621a16040", + "zh:f23bfe9758f06a1ec10ea3a81c9deedf3a7b42963568997d84a5153f35c5839a", + ] +} diff --git a/tests/fail-delayed/main.tf b/tests/fail-delayed/main.tf new file mode 100644 index 0000000..2965a87 --- /dev/null +++ b/tests/fail-delayed/main.tf @@ -0,0 +1,6 @@ +module "fail" { + source = "../../" + // Use a condition that isn't known until the apply step + condition = uuid() == "" + error_message = "sample error" +} diff --git a/tests/pass-delayed/.terraform.lock.hcl b/tests/pass-delayed/.terraform.lock.hcl new file mode 100644 index 0000000..db7a7c3 --- /dev/null +++ b/tests/pass-delayed/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/cloudinit" { + version = "2.3.2" + constraints = ">= 2.3.1" + hashes = [ + "h1:2jb+BfT5T96dXxUD2LQ6MtVHpXErd7ZybmMvdWE2jd4=", + "zh:2487e498736ed90f53de8f66fe2b8c05665b9f8ff1506f751c5ee227c7f457d1", + "zh:3d8627d142942336cf65eea6eb6403692f47e9072ff3fa11c3f774a3b93130b3", + "zh:434b643054aeafb5df28d5529b72acc20c6f5ded24decad73b98657af2b53f4f", + "zh:436aa6c2b07d82aa6a9dd746a3e3a627f72787c27c80552ceda6dc52d01f4b6f", + "zh:458274c5aabe65ef4dbd61d43ce759287788e35a2da004e796373f88edcaa422", + "zh:54bc70fa6fb7da33292ae4d9ceef5398d637c7373e729ed4fce59bd7b8d67372", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:893ba267e18749c1a956b69be569f0d7bc043a49c3a0eb4d0d09a8e8b2ca3136", + "zh:95493b7517bce116f75cdd4c63b7c82a9d0d48ec2ef2f5eb836d262ef96d0aa7", + "zh:9ae21ab393be52e3e84e5cce0ef20e690d21f6c10ade7d9d9d22b39851bfeddc", + "zh:cc3b01ac2472e6d59358d54d5e4945032efbc8008739a6d4946ca1b621a16040", + "zh:f23bfe9758f06a1ec10ea3a81c9deedf3a7b42963568997d84a5153f35c5839a", + ] +} diff --git a/tests/pass-delayed/main.tf b/tests/pass-delayed/main.tf new file mode 100644 index 0000000..75a20a3 --- /dev/null +++ b/tests/pass-delayed/main.tf @@ -0,0 +1,6 @@ +module "pass" { + source = "../../" + // Use a condition that isn't known until the apply step + condition = uuid() != "" + error_message = "sample error" +} From b3e0caa5de6f3da6293fbddae4652a2069990376 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 09:14:00 -0800 Subject: [PATCH 31/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index a4f9d53..182378e 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -11,7 +11,7 @@ jobs: id: matrix uses: Invicton-Labs/terraform-module-testing/matrix@v0.2.0 with: - minimum_tf_version: '1.10.3' + minimum_tf_version: '1.7.0' - name: Output Matrix run: | From 70c959a56b2ca5b335d9dc4775dcfa755bca7d2a Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 09:16:43 -0800 Subject: [PATCH 32/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 182378e..01395e1 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -12,6 +12,8 @@ jobs: uses: Invicton-Labs/terraform-module-testing/matrix@v0.2.0 with: minimum_tf_version: '1.7.0' + additional_runners: 'macos-13, windows-2019' + additional_images: 'amazonlinux:2' - name: Output Matrix run: | From 47c07cdad33579d5ad33e153e7edd388b1b776f6 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 09:17:18 -0800 Subject: [PATCH 33/46] Update versions.tf --- versions.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions.tf b/versions.tf index 12bb31a..1e3f40b 100644 --- a/versions.tf +++ b/versions.tf @@ -1,3 +1,3 @@ terraform { - required_version = ">= 1.10.3" + required_version = ">= 1.8.0" } From ed70fa856eee0dfd4bff6ab3db521851bf0cf1b8 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 09:19:14 -0800 Subject: [PATCH 34/46] Update required version --- .github/workflows/CICD.yml | 2 +- versions.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 01395e1..b322f64 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -11,7 +11,7 @@ jobs: id: matrix uses: Invicton-Labs/terraform-module-testing/matrix@v0.2.0 with: - minimum_tf_version: '1.7.0' + minimum_tf_version: '1.10.3' additional_runners: 'macos-13, windows-2019' additional_images: 'amazonlinux:2' diff --git a/versions.tf b/versions.tf index 1e3f40b..12bb31a 100644 --- a/versions.tf +++ b/versions.tf @@ -1,3 +1,3 @@ terraform { - required_version = ">= 1.8.0" + required_version = ">= 1.10.3" } From e3018e796e7d28e14b7d01405aec2a8b72e2dcee Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 09:22:44 -0800 Subject: [PATCH 35/46] Update CICD.yml --- .github/workflows/CICD.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index b322f64..b3a9d63 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -13,7 +13,6 @@ jobs: with: minimum_tf_version: '1.10.3' additional_runners: 'macos-13, windows-2019' - additional_images: 'amazonlinux:2' - name: Output Matrix run: | From c0c470453e2c52bd0384567fda919bc242f98bbb Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 14:18:30 -0800 Subject: [PATCH 36/46] Remove lock files --- tests/fail-delayed/.terraform.lock.hcl | 22 ---------------------- tests/pass-delayed/.terraform.lock.hcl | 22 ---------------------- 2 files changed, 44 deletions(-) delete mode 100644 tests/fail-delayed/.terraform.lock.hcl delete mode 100644 tests/pass-delayed/.terraform.lock.hcl diff --git a/tests/fail-delayed/.terraform.lock.hcl b/tests/fail-delayed/.terraform.lock.hcl deleted file mode 100644 index db7a7c3..0000000 --- a/tests/fail-delayed/.terraform.lock.hcl +++ /dev/null @@ -1,22 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/cloudinit" { - version = "2.3.2" - constraints = ">= 2.3.1" - hashes = [ - "h1:2jb+BfT5T96dXxUD2LQ6MtVHpXErd7ZybmMvdWE2jd4=", - "zh:2487e498736ed90f53de8f66fe2b8c05665b9f8ff1506f751c5ee227c7f457d1", - "zh:3d8627d142942336cf65eea6eb6403692f47e9072ff3fa11c3f774a3b93130b3", - "zh:434b643054aeafb5df28d5529b72acc20c6f5ded24decad73b98657af2b53f4f", - "zh:436aa6c2b07d82aa6a9dd746a3e3a627f72787c27c80552ceda6dc52d01f4b6f", - "zh:458274c5aabe65ef4dbd61d43ce759287788e35a2da004e796373f88edcaa422", - "zh:54bc70fa6fb7da33292ae4d9ceef5398d637c7373e729ed4fce59bd7b8d67372", - "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:893ba267e18749c1a956b69be569f0d7bc043a49c3a0eb4d0d09a8e8b2ca3136", - "zh:95493b7517bce116f75cdd4c63b7c82a9d0d48ec2ef2f5eb836d262ef96d0aa7", - "zh:9ae21ab393be52e3e84e5cce0ef20e690d21f6c10ade7d9d9d22b39851bfeddc", - "zh:cc3b01ac2472e6d59358d54d5e4945032efbc8008739a6d4946ca1b621a16040", - "zh:f23bfe9758f06a1ec10ea3a81c9deedf3a7b42963568997d84a5153f35c5839a", - ] -} diff --git a/tests/pass-delayed/.terraform.lock.hcl b/tests/pass-delayed/.terraform.lock.hcl deleted file mode 100644 index db7a7c3..0000000 --- a/tests/pass-delayed/.terraform.lock.hcl +++ /dev/null @@ -1,22 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/cloudinit" { - version = "2.3.2" - constraints = ">= 2.3.1" - hashes = [ - "h1:2jb+BfT5T96dXxUD2LQ6MtVHpXErd7ZybmMvdWE2jd4=", - "zh:2487e498736ed90f53de8f66fe2b8c05665b9f8ff1506f751c5ee227c7f457d1", - "zh:3d8627d142942336cf65eea6eb6403692f47e9072ff3fa11c3f774a3b93130b3", - "zh:434b643054aeafb5df28d5529b72acc20c6f5ded24decad73b98657af2b53f4f", - "zh:436aa6c2b07d82aa6a9dd746a3e3a627f72787c27c80552ceda6dc52d01f4b6f", - "zh:458274c5aabe65ef4dbd61d43ce759287788e35a2da004e796373f88edcaa422", - "zh:54bc70fa6fb7da33292ae4d9ceef5398d637c7373e729ed4fce59bd7b8d67372", - "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:893ba267e18749c1a956b69be569f0d7bc043a49c3a0eb4d0d09a8e8b2ca3136", - "zh:95493b7517bce116f75cdd4c63b7c82a9d0d48ec2ef2f5eb836d262ef96d0aa7", - "zh:9ae21ab393be52e3e84e5cce0ef20e690d21f6c10ade7d9d9d22b39851bfeddc", - "zh:cc3b01ac2472e6d59358d54d5e4945032efbc8008739a6d4946ca1b621a16040", - "zh:f23bfe9758f06a1ec10ea3a81c9deedf3a7b42963568997d84a5153f35c5839a", - ] -} From 1b737319ef21194645ac8d5d2d47aa0e337bceba Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 14:19:10 -0800 Subject: [PATCH 37/46] Add delayed message tests --- .github/workflows/CICD.yml | 46 ++++++++++++++----- .gitignore | 2 + .../main.tf | 0 tests/fail-message-delayed/main.tf | 6 +++ .../main.tf | 0 tests/pass-message-delayed/main.tf | 6 +++ 6 files changed, 48 insertions(+), 12 deletions(-) rename tests/{fail-delayed => fail-condition-delayed}/main.tf (100%) create mode 100644 tests/fail-message-delayed/main.tf rename tests/{pass-delayed => pass-condition-delayed}/main.tf (100%) create mode 100644 tests/pass-message-delayed/main.tf diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index b3a9d63..9bccec6 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -49,16 +49,27 @@ jobs: with: tf_path: tests/pass-output - - name: Initialize - Pass - Delayed - id: init-pass-delayed + - name: Initialize - Pass - Condition Delayed + id: init-pass-condition-delayed uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 with: - tf_path: tests/pass-delayed - - name: Run Tests - Pass - Delayed - id: tests-pass-delayed + tf_path: tests/pass-condition-delayed + - name: Run Tests - Pass - Condition Delayed + id: tests-pass-condition-delayed uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.2.0 with: - tf_path: tests/pass-delayed + tf_path: tests/pass-condition-delayed + + - name: Initialize - Pass - Message Delayed + id: init-pass-message-delayed + uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + with: + tf_path: tests/pass-message-delayed + - name: Run Tests - Pass - Message Delayed + id: tests-pass-message-delayed + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.2.0 + with: + tf_path: tests/pass-message-delayed - name: Initialize - Fail id: init-fail @@ -82,16 +93,27 @@ jobs: with: tf_path: tests/fail-output - - name: Initialize - Fail - Delayed - id: init-fail-delayed + - name: Initialize - Fail - Condition Delayed + id: init-fail-condition-delayed + uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + with: + tf_path: tests/fail-condition-delayed + - name: Run Tests - Fail - Condition Delayed + id: tests-fail-condition-delayed + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.2.0 + with: + tf_path: tests/fail-condition-delayed + + - name: Initialize - Fail - Message Delayed + id: init-fail-message-delayed uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 with: - tf_path: tests/fail-delayed - - name: Run Tests - Fail - Delayed - id: tests-fail-delayed + tf_path: tests/fail-message-delayed + - name: Run Tests - Fail - Message Delayed + id: tests-fail-message-delayed uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.2.0 with: - tf_path: tests/fail-delayed + tf_path: tests/fail-message-delayed # This job just waits for all other jobs to pass. We have it here # so our branch protection rule can reference a single job, instead diff --git a/.gitignore b/.gitignore index 7a3e2fd..3017b18 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ override.tf.json # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan # example: *tfplan* + +/tests/**/.terraform.lock.hcl \ No newline at end of file diff --git a/tests/fail-delayed/main.tf b/tests/fail-condition-delayed/main.tf similarity index 100% rename from tests/fail-delayed/main.tf rename to tests/fail-condition-delayed/main.tf diff --git a/tests/fail-message-delayed/main.tf b/tests/fail-message-delayed/main.tf new file mode 100644 index 0000000..707ea91 --- /dev/null +++ b/tests/fail-message-delayed/main.tf @@ -0,0 +1,6 @@ +module "fail" { + source = "../../" + // Use a condition that isn't known until the apply step + condition = false + error_message = uuid() == "" ? "should never happen" : "sample error" +} diff --git a/tests/pass-delayed/main.tf b/tests/pass-condition-delayed/main.tf similarity index 100% rename from tests/pass-delayed/main.tf rename to tests/pass-condition-delayed/main.tf diff --git a/tests/pass-message-delayed/main.tf b/tests/pass-message-delayed/main.tf new file mode 100644 index 0000000..97bfe9c --- /dev/null +++ b/tests/pass-message-delayed/main.tf @@ -0,0 +1,6 @@ +module "pass" { + source = "../../" + // Use a condition that isn't known until the apply step + condition = uuid() != "" + error_message = uuid() == "" ? "should never happen" : "sample error" +} From f8b6ce9859ef58649fcb21c785d93c2c562a872a Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 14:50:43 -0800 Subject: [PATCH 38/46] Update variables.tf --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 0350283..e99decf 100644 --- a/variables.tf +++ b/variables.tf @@ -12,7 +12,7 @@ variable "condition" { // until var.error_message is known. Otherwise, it can fail during the validation // phase but won't output the proper error message. // https://github.com/hashicorp/terraform/issues/35397 - condition = var.error_message != null && var.condition == true + condition = var.error_message == "" ? var.condition : var.condition error_message = var.error_message } } From b3a28fa5960538d3a551bdaa9548ecf001eefb43 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 14:54:10 -0800 Subject: [PATCH 39/46] Fix tests --- tests/fail-message-delayed/main.tf | 2 +- tests/pass-message-delayed/main.tf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fail-message-delayed/main.tf b/tests/fail-message-delayed/main.tf index 707ea91..32f9b91 100644 --- a/tests/fail-message-delayed/main.tf +++ b/tests/fail-message-delayed/main.tf @@ -2,5 +2,5 @@ module "fail" { source = "../../" // Use a condition that isn't known until the apply step condition = false - error_message = uuid() == "" ? "should never happen" : "sample error" + error_message = "sample error: ${uuid()}" } diff --git a/tests/pass-message-delayed/main.tf b/tests/pass-message-delayed/main.tf index 97bfe9c..932f2a3 100644 --- a/tests/pass-message-delayed/main.tf +++ b/tests/pass-message-delayed/main.tf @@ -1,6 +1,6 @@ module "pass" { source = "../../" // Use a condition that isn't known until the apply step - condition = uuid() != "" - error_message = uuid() == "" ? "should never happen" : "sample error" + condition = true + error_message = "sample error: ${uuid()}" } From 281d40a30fb23af8f20debe17aadc10e78d70f5f Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 14:59:18 -0800 Subject: [PATCH 40/46] Testing --- outputs.tf | 2 +- variables.tf | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/outputs.tf b/outputs.tf index c653073..5e61c6d 100644 --- a/outputs.tf +++ b/outputs.tf @@ -10,5 +10,5 @@ output "condition" { output "checked" { description = "Whether the condition has been checked (used for assertion dependencies)." - value = var.condition == true ? true : true + value = local.evaluation == true ? true : true //var.condition == true ? true : true } diff --git a/variables.tf b/variables.tf index e99decf..d89ad19 100644 --- a/variables.tf +++ b/variables.tf @@ -7,12 +7,16 @@ variable "error_message" { variable "condition" { description = "The condition to ensure is `true`." type = bool - validation { - // We have to use var.error_message != null to force the evaluation to wait - // until var.error_message is known. Otherwise, it can fail during the validation - // phase but won't output the proper error message. - // https://github.com/hashicorp/terraform/issues/35397 - condition = var.error_message == "" ? var.condition : var.condition - error_message = var.error_message - } + # validation { + # // We have to use var.error_message != null to force the evaluation to wait + # // until var.error_message is known. Otherwise, it can fail during the validation + # // phase but won't output the proper error message. + # // https://github.com/hashicorp/terraform/issues/35397 + # condition = var.error_message == "" ? var.condition : var.condition + # error_message = var.error_message + # } +} + +locals { + evaluation = var.condition ? null : SEE_ERROR_MESSAGE(var.error_message) } From 8cd53c21e6d6e8cf42404ee0fea83a85673a589a Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 16:04:00 -0800 Subject: [PATCH 41/46] Update CICD --- .github/workflows/CICD.yml | 34 +++++++++++++++--------------- README.md | 22 +++++++++++++++++++ outputs.tf | 3 ++- tests/fail-message-delayed/main.tf | 2 +- tests/pass-message-delayed/main.tf | 2 +- variables.tf | 22 +++++++++---------- 6 files changed, 54 insertions(+), 31 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 9bccec6..c617f54 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Generate Matrix id: matrix - uses: Invicton-Labs/terraform-module-testing/matrix@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/matrix@dev with: minimum_tf_version: '1.10.3' additional_runners: 'macos-13, windows-2019' @@ -29,89 +29,89 @@ jobs: steps: - name: Initialize - Pass id: init-pass - uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/initialize@dev with: tf_path: tests/pass - name: Run Tests - Pass id: tests-pass - uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: tf_path: tests/pass - name: Initialize - Pass (With Output) id: init-pass-output - uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/initialize@dev with: tf_path: tests/pass-output - name: Run Tests - Pass (With Output) id: tests-pass-output - uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: tf_path: tests/pass-output - name: Initialize - Pass - Condition Delayed id: init-pass-condition-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/initialize@dev with: tf_path: tests/pass-condition-delayed - name: Run Tests - Pass - Condition Delayed id: tests-pass-condition-delayed - uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: tf_path: tests/pass-condition-delayed - name: Initialize - Pass - Message Delayed id: init-pass-message-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/initialize@dev with: tf_path: tests/pass-message-delayed - name: Run Tests - Pass - Message Delayed id: tests-pass-message-delayed - uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: tf_path: tests/pass-message-delayed - name: Initialize - Fail id: init-fail - uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/initialize@dev with: tf_path: tests/fail - name: Run Tests - Fail id: tests-fail - uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail - name: Initialize - Fail (Output) id: init-fail-output - uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/initialize@dev with: tf_path: tests/fail-output - name: Run Tests - Fail (Output) id: tests-fail-output - uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail-output - name: Initialize - Fail - Condition Delayed id: init-fail-condition-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/initialize@dev with: tf_path: tests/fail-condition-delayed - name: Run Tests - Fail - Condition Delayed id: tests-fail-condition-delayed - uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail-condition-delayed - name: Initialize - Fail - Message Delayed id: init-fail-message-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/initialize@dev with: tf_path: tests/fail-message-delayed - name: Run Tests - Fail - Message Delayed id: tests-fail-message-delayed - uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.2.0 + uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail-message-delayed diff --git a/README.md b/README.md index 4649d15..09454f6 100644 --- a/README.md +++ b/README.md @@ -30,3 +30,25 @@ var.error_message is "This Terraform configuration can only be run on Unix-based // Ignore this part There is no function named "SEE_ABOVE_ERROR_MESSAGE". ``` + +## Plan, Apply, and Unknown Values + +There are several edge cases regarding conditions that aren't known until apply and error messages that aren't known until apply. + + +### Conditions not known during planning + +When the `condition` variable doesn't have a known value during the plan step, the assertion will not be checked during the plan step. The `error_message` variable will not be used or evaluated. + +The `condition` _will_ still be checked during the apply step, and the `error_message` variable will be used if `condition` evaluates to `false`. + + +### Error messages not known during planning + +When the `error_message` variable doesn't have a known value during the plan step, the behaviour will vary depending on whether the `condition` value is known during the plan step. + +If `condition` is not known during planning, then the `error_message` will not be evaluated/used until the apply step, and only if `condition` evaluates to `false`. + +If the `condition` _is_ known during planning and it evaluates to `false`, then the Terraform operation will fail during the plan step and the output error message will explain that the `error_message` variable value is invalid (not known). + +If `condition` evaluates to `true` as soon as it's known, then `error_message` will never be used or evaluated, so it doesn't matter if it's known or not. diff --git a/outputs.tf b/outputs.tf index 5e61c6d..d7dbd48 100644 --- a/outputs.tf +++ b/outputs.tf @@ -10,5 +10,6 @@ output "condition" { output "checked" { description = "Whether the condition has been checked (used for assertion dependencies)." - value = local.evaluation == true ? true : true //var.condition == true ? true : true + value = var.condition == true ? true : true + //value = local.evaluation == "" ? true : true //var.condition == true ? true : true } diff --git a/tests/fail-message-delayed/main.tf b/tests/fail-message-delayed/main.tf index 32f9b91..eae5749 100644 --- a/tests/fail-message-delayed/main.tf +++ b/tests/fail-message-delayed/main.tf @@ -1,6 +1,6 @@ module "fail" { source = "../../" // Use a condition that isn't known until the apply step - condition = false + condition = uuid() == "" error_message = "sample error: ${uuid()}" } diff --git a/tests/pass-message-delayed/main.tf b/tests/pass-message-delayed/main.tf index 932f2a3..dd73eea 100644 --- a/tests/pass-message-delayed/main.tf +++ b/tests/pass-message-delayed/main.tf @@ -1,6 +1,6 @@ module "pass" { source = "../../" // Use a condition that isn't known until the apply step - condition = true + condition = uuid() != "" error_message = "sample error: ${uuid()}" } diff --git a/variables.tf b/variables.tf index d89ad19..9ebd4e4 100644 --- a/variables.tf +++ b/variables.tf @@ -7,16 +7,16 @@ variable "error_message" { variable "condition" { description = "The condition to ensure is `true`." type = bool - # validation { - # // We have to use var.error_message != null to force the evaluation to wait - # // until var.error_message is known. Otherwise, it can fail during the validation - # // phase but won't output the proper error message. - # // https://github.com/hashicorp/terraform/issues/35397 - # condition = var.error_message == "" ? var.condition : var.condition - # error_message = var.error_message - # } + validation { + // We have to use var.error_message != null to force the evaluation to wait + // until var.error_message is known. Otherwise, it can fail during the validation + // phase but won't output the proper error message. + // https://github.com/hashicorp/terraform/issues/35397 + condition = var.error_message == "" ? var.condition : var.condition + error_message = var.error_message + } } -locals { - evaluation = var.condition ? null : SEE_ERROR_MESSAGE(var.error_message) -} +# locals { +# evaluation = var.condition ? "" : SEE_ABOVE_ERROR_MESSAGE(true ? null : "ERROR: ${var.error_message}") +# } From 7f80898973fdc02ca154a21d20a8ce82752eac25 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 16:10:16 -0800 Subject: [PATCH 42/46] Add stderr check --- .github/workflows/CICD.yml | 28 ++++++++++++++++++++ tests/fail-condition-message-delayed/main.tf | 7 +++++ tests/fail-message-delayed/main.tf | 6 ++--- tests/pass-condition-message-delayed/main.tf | 7 +++++ tests/pass-message-delayed/main.tf | 6 ++--- 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 tests/fail-condition-message-delayed/main.tf create mode 100644 tests/pass-condition-message-delayed/main.tf diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index c617f54..382a46e 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -70,6 +70,18 @@ jobs: uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev with: tf_path: tests/pass-message-delayed + stderr_contains: Unsuitable value for error message + + - name: Initialize - Pass - Condition & Message Delayed + id: init-pass-condition-message-delayed + uses: Invicton-Labs/terraform-module-testing/initialize@dev + with: + tf_path: tests/pass-condition-message-delayed + - name: Run Tests - Pass - Condition & Message Delayed + id: tests-pass-condition-message-delayed + uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + with: + tf_path: tests/pass-condition-message-delayed - name: Initialize - Fail id: init-fail @@ -81,6 +93,7 @@ jobs: uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail + stderr_contains: sample error - name: Initialize - Fail (Output) id: init-fail-output @@ -92,6 +105,7 @@ jobs: uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail-output + stderr_contains: sample error - name: Initialize - Fail - Condition Delayed id: init-fail-condition-delayed @@ -103,6 +117,7 @@ jobs: uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail-condition-delayed + stderr_contains: sample error - name: Initialize - Fail - Message Delayed id: init-fail-message-delayed @@ -114,6 +129,19 @@ jobs: uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail-message-delayed + stderr_contains: Unsuitable value for error message + + - name: Initialize - Fail - Condition & Message Delayed + id: init-fail-condition-message-delayed + uses: Invicton-Labs/terraform-module-testing/initialize@dev + with: + tf_path: tests/fail-condition-message-delayed + - name: Run Tests - Fail - Condition & Message Delayed + id: tests-fail-condition-message-delayed + uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + with: + tf_path: tests/fail-condition-message-delayed + stderr_contains: sample error # This job just waits for all other jobs to pass. We have it here # so our branch protection rule can reference a single job, instead diff --git a/tests/fail-condition-message-delayed/main.tf b/tests/fail-condition-message-delayed/main.tf new file mode 100644 index 0000000..a8527d4 --- /dev/null +++ b/tests/fail-condition-message-delayed/main.tf @@ -0,0 +1,7 @@ +module "fail" { + source = "../../" + // Use a condition that isn't known until the apply step + condition = uuid() == "" + // Use a message that isn't known until the apply step + error_message = "sample error: ${uuid()}" +} diff --git a/tests/fail-message-delayed/main.tf b/tests/fail-message-delayed/main.tf index eae5749..f711e3f 100644 --- a/tests/fail-message-delayed/main.tf +++ b/tests/fail-message-delayed/main.tf @@ -1,6 +1,6 @@ module "fail" { - source = "../../" - // Use a condition that isn't known until the apply step - condition = uuid() == "" + source = "../../" + condition = false + // Use a message that isn't known until the apply step error_message = "sample error: ${uuid()}" } diff --git a/tests/pass-condition-message-delayed/main.tf b/tests/pass-condition-message-delayed/main.tf new file mode 100644 index 0000000..2760912 --- /dev/null +++ b/tests/pass-condition-message-delayed/main.tf @@ -0,0 +1,7 @@ +module "pass" { + source = "../../" + // Use a condition that isn't known until the apply step + condition = uuid() != "" + // Use a message that isn't known until the apply step + error_message = "sample error: ${uuid()}" +} diff --git a/tests/pass-message-delayed/main.tf b/tests/pass-message-delayed/main.tf index dd73eea..9a526eb 100644 --- a/tests/pass-message-delayed/main.tf +++ b/tests/pass-message-delayed/main.tf @@ -1,6 +1,6 @@ module "pass" { - source = "../../" - // Use a condition that isn't known until the apply step - condition = uuid() != "" + source = "../../" + condition = true + // Use a message that isn't known until the apply step error_message = "sample error: ${uuid()}" } From 31a69e931ef4e964f3a148e36ffad492b8964329 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 16:16:01 -0800 Subject: [PATCH 43/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 382a46e..a9b3aae 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -141,7 +141,7 @@ jobs: uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail-condition-message-delayed - stderr_contains: sample error + stderr_contains: sample errorsss # This job just waits for all other jobs to pass. We have it here # so our branch protection rule can reference a single job, instead From 23e6e9612d62a559ed21cca4a39c3c3801ccedbd Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 16:17:36 -0800 Subject: [PATCH 44/46] Update CICD.yml --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index a9b3aae..382a46e 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -141,7 +141,7 @@ jobs: uses: Invicton-Labs/terraform-module-testing/apply-failure@dev with: tf_path: tests/fail-condition-message-delayed - stderr_contains: sample errorsss + stderr_contains: sample error # This job just waits for all other jobs to pass. We have it here # so our branch protection rule can reference a single job, instead From 6ba7bac9a8362bbaaaa08de67eba39452dc13a7a Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 18:49:11 -0800 Subject: [PATCH 45/46] Update CICD.yml --- .github/workflows/CICD.yml | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 382a46e..e0b1533 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Generate Matrix id: matrix - uses: Invicton-Labs/terraform-module-testing/matrix@dev + uses: Invicton-Labs/terraform-module-testing/matrix@v0.3.0 with: minimum_tf_version: '1.10.3' additional_runners: 'macos-13, windows-2019' @@ -29,116 +29,116 @@ jobs: steps: - name: Initialize - Pass id: init-pass - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/pass - name: Run Tests - Pass id: tests-pass - uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.3.0 with: tf_path: tests/pass - name: Initialize - Pass (With Output) id: init-pass-output - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/pass-output - name: Run Tests - Pass (With Output) id: tests-pass-output - uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.3.0 with: tf_path: tests/pass-output - name: Initialize - Pass - Condition Delayed id: init-pass-condition-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/pass-condition-delayed - name: Run Tests - Pass - Condition Delayed id: tests-pass-condition-delayed - uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.3.0 with: tf_path: tests/pass-condition-delayed - name: Initialize - Pass - Message Delayed id: init-pass-message-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/pass-message-delayed - name: Run Tests - Pass - Message Delayed id: tests-pass-message-delayed - uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.3.0 with: tf_path: tests/pass-message-delayed stderr_contains: Unsuitable value for error message - name: Initialize - Pass - Condition & Message Delayed id: init-pass-condition-message-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/pass-condition-message-delayed - name: Run Tests - Pass - Condition & Message Delayed id: tests-pass-condition-message-delayed - uses: Invicton-Labs/terraform-module-testing/apply-destroy@dev + uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.3.0 with: tf_path: tests/pass-condition-message-delayed - name: Initialize - Fail id: init-fail - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/fail - name: Run Tests - Fail id: tests-fail - uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.3.0 with: tf_path: tests/fail stderr_contains: sample error - name: Initialize - Fail (Output) id: init-fail-output - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/fail-output - name: Run Tests - Fail (Output) id: tests-fail-output - uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.3.0 with: tf_path: tests/fail-output stderr_contains: sample error - name: Initialize - Fail - Condition Delayed id: init-fail-condition-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/fail-condition-delayed - name: Run Tests - Fail - Condition Delayed id: tests-fail-condition-delayed - uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.3.0 with: tf_path: tests/fail-condition-delayed stderr_contains: sample error - name: Initialize - Fail - Message Delayed id: init-fail-message-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/fail-message-delayed - name: Run Tests - Fail - Message Delayed id: tests-fail-message-delayed - uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.3.0 with: tf_path: tests/fail-message-delayed stderr_contains: Unsuitable value for error message - name: Initialize - Fail - Condition & Message Delayed id: init-fail-condition-message-delayed - uses: Invicton-Labs/terraform-module-testing/initialize@dev + uses: Invicton-Labs/terraform-module-testing/initialize@v0.3.0 with: tf_path: tests/fail-condition-message-delayed - name: Run Tests - Fail - Condition & Message Delayed id: tests-fail-condition-message-delayed - uses: Invicton-Labs/terraform-module-testing/apply-failure@dev + uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.3.0 with: tf_path: tests/fail-condition-message-delayed stderr_contains: sample error From e4118f72d5e42b5b9f1b499b1fbd145cd40089cd Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 18:59:18 -0800 Subject: [PATCH 46/46] Delete commented code --- outputs.tf | 1 - variables.tf | 4 ---- 2 files changed, 5 deletions(-) diff --git a/outputs.tf b/outputs.tf index d7dbd48..c653073 100644 --- a/outputs.tf +++ b/outputs.tf @@ -11,5 +11,4 @@ output "condition" { output "checked" { description = "Whether the condition has been checked (used for assertion dependencies)." value = var.condition == true ? true : true - //value = local.evaluation == "" ? true : true //var.condition == true ? true : true } diff --git a/variables.tf b/variables.tf index 9ebd4e4..e99decf 100644 --- a/variables.tf +++ b/variables.tf @@ -16,7 +16,3 @@ variable "condition" { error_message = var.error_message } } - -# locals { -# evaluation = var.condition ? "" : SEE_ABOVE_ERROR_MESSAGE(true ? null : "ERROR: ${var.error_message}") -# }