From 57698a842d09cf04612a98883066989d1e669df3 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Wed, 25 Dec 2024 09:04:50 -0800 Subject: [PATCH] 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" +}