From 95d037aa15d65e7259935ba92b62c812c01f7925 Mon Sep 17 00:00:00 2001 From: Ruben Laban <5331085+tun0@users.noreply.github.com> Date: Tue, 22 Feb 2022 11:51:19 +0100 Subject: [PATCH] Add support for planning destroys (#24) * Add support for planning destroys * Forgot to build * Do not use global ncc to build * Build using "npm run build" --- action.yaml | 4 ++++ dist/index.js | 3 ++- index.js | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index c161e0c7..7b039d39 100644 --- a/action.yaml +++ b/action.yaml @@ -25,6 +25,10 @@ inputs: required: false description: Limit the number of concurrent operations during plan/apply default: '10' + terraform_plan_destroy: + required: false + description: Whether to run `terraform plan -destroy` instead of `terraform plan` + default: 'false' terraform_targets: required: false description: A multiline string containing targets that should be passed to terraform (one per line) diff --git a/dist/index.js b/dist/index.js index 98ee319f..6c8da458 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5514,6 +5514,7 @@ async function terraform(args) { let terraformDoDestroy = core.getBooleanInput('terraform_do_destroy'); const terraformLock = core.getBooleanInput('terraform_lock'); const terraformParallelism = core.getInput('terraform_parallelism'); + const terraformPlanDestroy = (terraformDoDestroy || core.getBooleanInput('terraform_plan_destroy')) ? '-destroy' : ''; const terraformTargets = core.getMultilineInput('terraform_targets').map((target) => `-target=${target}`); const terraformVariables = core.getInput('terraform_variables'); const terraformWorkspace = core.getInput('terraform_workspace'); @@ -5646,7 +5647,7 @@ async function terraform(args) { } core.startGroup('Run terraform plan'); - const tfp = await terraform(['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan'].concat(terraformTargets)); + const tfp = await terraform(['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan'].concat(terraformTargets).concat(terraformPlanDestroy)); core.endGroup(); if (tfp.status > 0) { tf_plan = status_failed; diff --git a/index.js b/index.js index adf58ca9..f1a678cc 100644 --- a/index.js +++ b/index.js @@ -43,6 +43,7 @@ async function terraform(args) { let terraformDoDestroy = core.getBooleanInput('terraform_do_destroy'); const terraformLock = core.getBooleanInput('terraform_lock'); const terraformParallelism = core.getInput('terraform_parallelism'); + const terraformPlanDestroy = (terraformDoDestroy || core.getBooleanInput('terraform_plan_destroy')) ? '-destroy' : ''; const terraformTargets = core.getMultilineInput('terraform_targets').map((target) => `-target=${target}`); const terraformVariables = core.getInput('terraform_variables'); const terraformWorkspace = core.getInput('terraform_workspace'); @@ -175,7 +176,7 @@ async function terraform(args) { } core.startGroup('Run terraform plan'); - const tfp = await terraform(['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan'].concat(terraformTargets)); + const tfp = await terraform(['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan'].concat(terraformTargets).concat(terraformPlanDestroy)); core.endGroup(); if (tfp.status > 0) { tf_plan = status_failed;