From 0cadaa0d00d2b4b54dd67f498057802e9c327329 Mon Sep 17 00:00:00 2001 From: KyleTryon Date: Tue, 17 May 2022 14:56:06 -0400 Subject: [PATCH] feat: optionally apply plan file --- src/commands/apply.yml | 5 +++++ src/commands/plan.yml | 5 +++++ src/jobs/apply.yml | 5 +++++ src/jobs/plan.yml | 5 +++++ src/scripts/apply.sh | 2 +- src/scripts/plan.sh | 2 +- 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/commands/apply.yml b/src/commands/apply.yml index 276ccfe..dfb5808 100644 --- a/src/commands/apply.yml +++ b/src/commands/apply.yml @@ -31,6 +31,10 @@ parameters: type: "string" description: "Path to terraform cli config file" default: "" + plan: + type: string + description: Optionally provide a plan file to supply to the 'apply' command. + default: "" timeout: description: Configure a custom timeout limit type: string @@ -48,4 +52,5 @@ steps: TF_PARAM_BACKEND_CONFIG: <> TF_PARAM_BACKEND_CONFIG_FILE: <> TF_PARAM_CLI_CONFIG_FILE: <> + TF_PARAM_PLAN: <> command: <> diff --git a/src/commands/plan.yml b/src/commands/plan.yml index 0d28262..4653445 100644 --- a/src/commands/plan.yml +++ b/src/commands/plan.yml @@ -31,6 +31,10 @@ parameters: type: "string" description: "Path to terraform cli config file" default: "" + out: + type: string + description: The file path to save your terraform plan to. + default: "plan.out" timeout: description: Configure a custom timeout limit type: string @@ -48,4 +52,5 @@ steps: TF_PARAM_BACKEND_CONFIG: <> TF_PARAM_BACKEND_CONFIG_FILE: <> TF_PARAM_CLI_CONFIG_FILE: <> + TF_PARAM_OUT: << parameters.out >> command: <> diff --git a/src/jobs/apply.yml b/src/jobs/apply.yml index 006dd16..e9618c2 100644 --- a/src/jobs/apply.yml +++ b/src/jobs/apply.yml @@ -51,6 +51,10 @@ parameters: type: "string" description: "Path to terraform cli config file" default: "" + plan: + type: string + description: Optionally provide a plan file to supply to the 'apply' command. + default: "" tag: description: "Specify the Terraform Docker image tag for the executor" type: "string" @@ -92,6 +96,7 @@ steps: backend_config: << parameters.backend_config >> backend_config_file: << parameters.backend_config_file >> cli_config_file: << parameters.cli_config_file >> + plan: <> timeout: <> - when: condition: << parameters.persist-workspace >> diff --git a/src/jobs/plan.yml b/src/jobs/plan.yml index 08e373e..ccfff73 100644 --- a/src/jobs/plan.yml +++ b/src/jobs/plan.yml @@ -55,6 +55,10 @@ parameters: description: "Specify the Terraform Docker image tag for the executor" type: "string" default: "1.0.0" # update commands/install when updating this + out: + type: string + description: The file path to save your terraform plan to. + default: "plan.out" timeout: description: "Configure a custom timeout limit" type: "string" @@ -93,6 +97,7 @@ steps: backend_config: << parameters.backend_config >> backend_config_file: << parameters.backend_config_file >> cli_config_file: << parameters.cli_config_file >> + out: << parameters.out >> timeout: <> - when: condition: << parameters.persist-workspace >> diff --git a/src/scripts/apply.sh b/src/scripts/apply.sh index 5633430..66efaa4 100644 --- a/src/scripts/apply.sh +++ b/src/scripts/apply.sh @@ -63,4 +63,4 @@ else echo "[INFO] Remote State Backend Enabled" fi # shellcheck disable=SC2086 -terraform -chdir="$module_path" apply -auto-approve $PLAN_ARGS +terraform -chdir="$module_path" apply -auto-approve $PLAN_ARGS ${TF_PARAM_PLAN} diff --git a/src/scripts/plan.sh b/src/scripts/plan.sh index 59ad804..3cba3a5 100644 --- a/src/scripts/plan.sh +++ b/src/scripts/plan.sh @@ -66,4 +66,4 @@ if [[ -n "${TF_PARAM_VAR_FILE}" ]]; then fi export PLAN_ARGS # shellcheck disable=SC2086 -terraform -chdir="$module_path" plan -input=false -out=plan.out $PLAN_ARGS +terraform -chdir="$module_path" plan -input=false -out=${TF_PARAM_OUT} $PLAN_ARGS