From dd6defda307a1404284e7c093099ce548fa71c9d Mon Sep 17 00:00:00 2001
From: Alex Maras <dev@alexmaras.com>
Date: Thu, 17 Apr 2025 09:22:50 +0800
Subject: [PATCH] test: ensure artifacts are uploaded by plan

---
 .../ExtraArtifactsAreIncluded.gitlab-ci.yml   | 42 +++++++++++++++++++
 tests/integration.gitlab-ci.yml               |  1 +
 2 files changed, 43 insertions(+)
 create mode 100644 tests/integration-tests/ExtraArtifactsAreIncluded.gitlab-ci.yml

diff --git a/tests/integration-tests/ExtraArtifactsAreIncluded.gitlab-ci.yml b/tests/integration-tests/ExtraArtifactsAreIncluded.gitlab-ci.yml
new file mode 100644
index 0000000..00666a0
--- /dev/null
+++ b/tests/integration-tests/ExtraArtifactsAreIncluded.gitlab-ci.yml
@@ -0,0 +1,42 @@
+variables:
+  ARTIFACT_FILE_NAME: integration_test_file_artifact
+
+include:
+  - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/plan@$CI_COMMIT_SHA
+    inputs:
+      image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE
+      version: $CI_COMMIT_SHA
+      base_os: $GITLAB_OPENTOFU_BASE_IMAGE_OS
+      opentofu_version: $OPENTOFU_VERSION
+      root_dir: $TEST_GITLAB_TOFU_ROOT_DIR
+      state_name: $TEST_GITLAB_TOFU_STATE_NAME
+      warning_on_non_empty_plan: true
+      plan_artifacts:
+        - $ARTIFACT_FILE_NAME
+
+  # For CI Terraform state cleanup
+  - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/delete-state@$CI_COMMIT_SHA
+    inputs:
+      state_name: $TEST_GITLAB_TOFU_STATE_NAME
+      rules: [{when: always}]
+
+stages: [build, cleanup, verify]
+
+plan:
+  before_script:
+    - touch "$ARTIFACT_FILE_NAME"
+
+verify:plan-job:uploaded-extra-artifact:
+  stage: verify
+  needs: ['plan']
+  rules: [{when: always}]
+  image: alpine:latest
+  script:
+    - |
+      if [ -f "$ARTIFACT_FILE_NAME" ]; then
+        echo 'Success: the extra artifact was uploaded by the plan job.'
+        exit 0
+      else
+        echo 'Error: the extra artifact was not uploaded by the plan job.'
+        exit 0
+      fi
diff --git a/tests/integration.gitlab-ci.yml b/tests/integration.gitlab-ci.yml
index 6f3be6d..ba4337e 100644
--- a/tests/integration.gitlab-ci.yml
+++ b/tests/integration.gitlab-ci.yml
@@ -136,6 +136,7 @@ plan-job-template:
     matrix:
       - PIPELINE_NAME:
           - WarningOnNonEmptyPlan
+          - ExtraArtifactsAreIncluded
         GITLAB_OPENTOFU_BASE_IMAGE_OS:
           - alpine
           - debian
-- 
GitLab