diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 6a37f70..cfe98d7 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -100,14 +100,24 @@ workflows: workspace: "orb-testing" requires: - terraform/plan - - terraform/destroy: + - terraform/plan: + name: Plan destroy context: CPE_ORBS_AWS filters: *filters checkout: true path: "src/infra" workspace: "orb-testing" + destroy_plan: true requires: - terraform/apply + - terraform/destroy: + context: CPE_ORBS_AWS + filters: *filters + checkout: true + path: "src/infra" + workspace: "orb-testing" + requires: + - Plan destroy - orb-tools/pack: filters: *filters - orb-tools/publish: @@ -122,6 +132,7 @@ workflows: - terraform/validate - terraform/plan - terraform/apply + - Plan destroy - terraform/destroy - test-absolute-path context: orb-publisher diff --git a/src/commands/plan.yml b/src/commands/plan.yml index bac0119..6f5d8e4 100644 --- a/src/commands/plan.yml +++ b/src/commands/plan.yml @@ -2,6 +2,10 @@ description: | Execute 'terraform plan' against current state. parameters: + destroy_plan: + type: boolean + description: Run this plan as a destroy plan. + default: false path: type: "string" description: "Path to the terraform module" @@ -53,6 +57,7 @@ steps: name: terraform plan no_output_timeout: <> environment: + TF_PARAM_DESTROY: <> TF_PARAM_PATH: <> TF_PARAM_VAR: <> TF_PARAM_VAR_FILE: <> diff --git a/src/examples/deploy_infrastructure.yml b/src/examples/deploy_infrastructure.yml index 10e3a4f..0bb45f3 100644 --- a/src/examples/deploy_infrastructure.yml +++ b/src/examples/deploy_infrastructure.yml @@ -6,7 +6,7 @@ description: | usage: version: 2.1 orbs: - terraform: circleci/terraform@3.3 + terraform: circleci/terraform@3.5 workflows: deploy_infrastructure: jobs: diff --git a/src/examples/deploy_infrastructure_job.yml b/src/examples/deploy_infrastructure_job.yml index 5b7eebf..a756cca 100644 --- a/src/examples/deploy_infrastructure_job.yml +++ b/src/examples/deploy_infrastructure_job.yml @@ -4,7 +4,7 @@ description: | usage: version: 2.1 orbs: - terraform: circleci/terraform@3.3 + terraform: circleci/terraform@3.5 jobs: single-job-lifecycle: executor: terraform/default @@ -21,6 +21,9 @@ usage: path: "." - terraform/apply: path: "." + - terraform/plan: + path: "." + destroy_plan: true - terraform/destroy: path: "." workflows: diff --git a/src/examples/deploy_using_remote_backend.yml b/src/examples/deploy_using_remote_backend.yml index f527a03..b953c3c 100644 --- a/src/examples/deploy_using_remote_backend.yml +++ b/src/examples/deploy_using_remote_backend.yml @@ -4,7 +4,7 @@ description: | usage: version: 2.1 orbs: - terraform: circleci/terraform@3.3 + terraform: circleci/terraform@3.5 jobs: single-job-lifecycle: executor: terraform/default @@ -25,7 +25,8 @@ usage: - terraform/init: path: "." backend: true - backend_config_file: backend.hcl #See the Using CLI Input section for details on creating backend configuration file: https://www.terraform.io/docs/language/settings/backends/remote.html#using-cli-input + #See the Using CLI Input section for details on creating backend configuration file: https://www.terraform.io/docs/language/settings/backends/remote.html#using-cli-input + backend_config_file: backend.hcl - terraform/plan: path: "." backend_config_file: backend.hcl diff --git a/src/jobs/plan.yml b/src/jobs/plan.yml index 2f3fdba..8a6d2b1 100644 --- a/src/jobs/plan.yml +++ b/src/jobs/plan.yml @@ -2,6 +2,10 @@ description: > Run Terraform plan against current state parameters: + destroy_plan: + type: boolean + description: Run this plan as a destroy plan. + default: false attach-workspace: default: false description: "Do cool stuff with workspaces" @@ -95,6 +99,7 @@ steps: timeout: <> - plan: path: << parameters.path >> + destroy_plan: << parameters.destroy_plan >> var: << parameters.var >> var_file: << parameters.var_file >> workspace: << parameters.workspace >> diff --git a/src/scripts/plan.sh b/src/scripts/plan.sh index 737b291..198dda7 100644 --- a/src/scripts/plan.sh +++ b/src/scripts/plan.sh @@ -68,9 +68,15 @@ if [[ -n "${TF_PARAM_VAR_FILE}" ]]; then done fi +if [ "$TF_PARAM_DESTROY" = 1 ]; then + PLAN_ARGS="$PLAN_ARGS -destroy" +fi + if [[ -n "${TF_PARAM_LOCK_TIMEOUT}" ]]; then PLAN_ARGS="$PLAN_ARGS -lock-timeout=${TF_PARAM_LOCK_TIMEOUT}" fi export PLAN_ARGS # shellcheck disable=SC2086 +set -x terraform -chdir="$module_path" plan -input=false -out=${TF_PARAM_OUT} -lock=${TF_PARAM_LOCK} $PLAN_ARGS +set +x \ No newline at end of file