Skip to content

Commit

Permalink
Add option to run plan destroy to plan (#115)
Browse files Browse the repository at this point in the history
Fix linter

Do comparison differently

Add debug to plan command

Update condition

Update condition

Update condition

Uupdate condition
  • Loading branch information
marboledacci authored Nov 18, 2024
1 parent bd238b1 commit b95f400
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
13 changes: 12 additions & 1 deletion .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -122,6 +132,7 @@ workflows:
- terraform/validate
- terraform/plan
- terraform/apply
- Plan destroy
- terraform/destroy
- test-absolute-path
context: orb-publisher
Expand Down
5 changes: 5 additions & 0 deletions src/commands/plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -53,6 +57,7 @@ steps:
name: terraform plan
no_output_timeout: <<parameters.timeout>>
environment:
TF_PARAM_DESTROY: <<parameters.destroy_plan>>
TF_PARAM_PATH: <<parameters.path>>
TF_PARAM_VAR: <<parameters.var>>
TF_PARAM_VAR_FILE: <<parameters.var_file>>
Expand Down
2 changes: 1 addition & 1 deletion src/examples/deploy_infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: |
usage:
version: 2.1
orbs:
terraform: circleci/terraform@3.3
terraform: circleci/terraform@3.5
workflows:
deploy_infrastructure:
jobs:
Expand Down
5 changes: 4 additions & 1 deletion src/examples/deploy_infrastructure_job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +21,9 @@ usage:
path: "."
- terraform/apply:
path: "."
- terraform/plan:
path: "."
destroy_plan: true
- terraform/destroy:
path: "."
workflows:
Expand Down
5 changes: 3 additions & 2 deletions src/examples/deploy_using_remote_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/jobs/plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -95,6 +99,7 @@ steps:
timeout: <<parameters.timeout>>
- plan:
path: << parameters.path >>
destroy_plan: << parameters.destroy_plan >>
var: << parameters.var >>
var_file: << parameters.var_file >>
workspace: << parameters.workspace >>
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b95f400

Please sign in to comment.