Skip to content

Commit

Permalink
Add variable files support #30
Browse files Browse the repository at this point in the history
Add variable files support
  • Loading branch information
drsherluck authored Sep 26, 2022
2 parents 028cb3e + 1ecb9b0 commit f92f940
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ inputs:
terraform_variables:
required: false
description: 'A JSON string containing variables that should be passed to terraform. For example: {"my_var": "my_value"}'
terraform_variable_files:
required: false
description: A multiline string containing .tfvars that should be passed to terraform (one per line)
terraform_workspace:
required: false
description: The name of the workspace that resources should be applied in
Expand Down
9 changes: 5 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15161,6 +15161,7 @@ async function terraform(terraformDirectory, args) {
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 terraformVariableFiles = core.getMultilineInput('terraform_variable_files').map((file) => `-var-file=${file}`);
const terraformWorkspace = core.getInput('terraform_workspace');
const reportDrift = core.getBooleanInput('report_drift');
const slackChannel = core.getInput('slack_channel_id');
Expand Down Expand Up @@ -15312,7 +15313,7 @@ async function terraform(terraformDirectory, args) {
core.startGroup('Run terraform plan');
let exitCode = 0;
const slack = new WebClient(slackBotToken);
const tfd = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-no-color', '-detailed-exitcode'].concat(terraformTargets));
const tfd = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-no-color', '-detailed-exitcode'].concat(terraformTargets).concat(terraformVariableFiles));
switch (tfd.status) {
case 0:
break;
Expand Down Expand Up @@ -15340,7 +15341,7 @@ async function terraform(terraformDirectory, args) {
}

core.startGroup('Run terraform plan');
const tfp = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan'].concat(terraformTargets).concat(terraformPlanDestroy));
const tfp = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan'].concat(terraformTargets).concat(terraformVariableFiles).concat(terraformPlanDestroy));
core.endGroup();
if (tfp.status > 0) {
tf_plan = status_failed;
Expand All @@ -15352,7 +15353,7 @@ async function terraform(terraformDirectory, args) {

core.startGroup('Run terraform apply');
if (terraformDoApply === true) {
const tfa = await terraform(terraformDirectory, ['apply', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve'].concat(terraformTargets).concat('terraform.plan'));
const tfa = await terraform(terraformDirectory, ['apply', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve'].concat(terraformTargets).concat(terraformVariableFiles).concat('terraform.plan'));
core.endGroup();
if (tfa.status > 0) {
tf_apply = status_failed;
Expand All @@ -15368,7 +15369,7 @@ async function terraform(terraformDirectory, args) {
/* DESTROY START */
core.startGroup('Run terraform destroy');
if (terraformDoDestroy === true) {
const tfd = await terraform(terraformDirectory, ['destroy', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve'].concat(terraformTargets));
const tfd = await terraform(terraformDirectory, ['destroy', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve'].concat(terraformTargets).concat(terraformVariableFiles));
core.info(tfd.stdout);
core.endGroup();
if (tfd.status > 0) {
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function terraform(terraformDirectory, args) {
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 terraformVariableFiles = core.getMultilineInput('terraform_variable_files').map((file) => `-var-file=${file}`);
const terraformWorkspace = core.getInput('terraform_workspace');
const reportDrift = core.getBooleanInput('report_drift');
const slackChannel = core.getInput('slack_channel_id');
Expand Down Expand Up @@ -199,7 +200,7 @@ async function terraform(terraformDirectory, args) {
core.startGroup('Run terraform plan');
let exitCode = 0;
const slack = new WebClient(slackBotToken);
const tfd = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-no-color', '-detailed-exitcode'].concat(terraformTargets));
const tfd = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-no-color', '-detailed-exitcode'].concat(terraformTargets).concat(terraformVariableFiles));
switch (tfd.status) {
case 0:
break;
Expand Down Expand Up @@ -227,7 +228,7 @@ async function terraform(terraformDirectory, args) {
}

core.startGroup('Run terraform plan');
const tfp = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan'].concat(terraformTargets).concat(terraformPlanDestroy));
const tfp = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan'].concat(terraformTargets).concat(terraformVariableFiles).concat(terraformPlanDestroy));
core.endGroup();
if (tfp.status > 0) {
tf_plan = status_failed;
Expand All @@ -239,7 +240,7 @@ async function terraform(terraformDirectory, args) {

core.startGroup('Run terraform apply');
if (terraformDoApply === true) {
const tfa = await terraform(terraformDirectory, ['apply', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve'].concat(terraformTargets).concat('terraform.plan'));
const tfa = await terraform(terraformDirectory, ['apply', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve'].concat(terraformTargets).concat(terraformVariableFiles).concat('terraform.plan'));
core.endGroup();
if (tfa.status > 0) {
tf_apply = status_failed;
Expand All @@ -255,7 +256,7 @@ async function terraform(terraformDirectory, args) {
/* DESTROY START */
core.startGroup('Run terraform destroy');
if (terraformDoDestroy === true) {
const tfd = await terraform(terraformDirectory, ['destroy', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve'].concat(terraformTargets));
const tfd = await terraform(terraformDirectory, ['destroy', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve'].concat(terraformTargets).concat(terraformVariableFiles));
core.info(tfd.stdout);
core.endGroup();
if (tfd.status > 0) {
Expand Down

0 comments on commit f92f940

Please sign in to comment.