diff --git a/templates/plan.yml b/templates/plan.yml index 7441ebddd57b6037a1ecdf0860119b0a610d3e98..bcaed749b3b8a097b888607fd1e7c65a0ed2a683 100644 --- a/templates/plan.yml +++ b/templates/plan.yml @@ -50,6 +50,10 @@ spec: state_name: default: default description: 'Remote OpenTofu state name.' + destroy: + default: false + type: boolean + description: 'Indicate if the plan should be a destroy plan' --- @@ -88,5 +92,11 @@ spec: image: name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' script: - - gitlab-tofu plan + - | + args="" + if [ "$[[ inputs.destroy ]]" == "true" ]; then + echo "Planning for a destroy" + args="-destroy" + fi + - gitlab-tofu plan $args - gitlab-tofu plan-json diff --git a/tests/integration-tests/Destroy.gitlab-ci.yml b/tests/integration-tests/Destroy.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..0c89d9f65d15267f044165b0bf990fd65f3376e5 --- /dev/null +++ b/tests/integration-tests/Destroy.gitlab-ci.yml @@ -0,0 +1,16 @@ +include: + - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/plan@$CI_COMMIT_SHA + inputs: + image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE + version: $CI_COMMIT_SHA + opentofu_version: $OPENTOFU_VERSION + root_dir: $TEST_TF_ROOT + state_name: $TEST_TF_STATE_NAME + destroy: true + +stages: [build] + +# Required to run everything immediately, instead of manually. + +plan: + rules: [{when: always}] diff --git a/tests/integration.gitlab-ci.yml b/tests/integration.gitlab-ci.yml index 8f490d7441e320cd8ed19329c3e3e86bc231a7c4..ca0369b60c6531be1b47a082ae0b61b0b39213cf 100644 --- a/tests/integration.gitlab-ci.yml +++ b/tests/integration.gitlab-ci.yml @@ -12,3 +12,4 @@ component: - PIPELINE_NAME: [Defaults] - PIPELINE_NAME: [JobTemplates] - PIPELINE_NAME: [TestJob] + - PIPELINE_NAME: [Destroy]