-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for specifying terraform targets #14
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,11 @@ async function terraform(args) { | |
|
||
(async () => { | ||
const terraformDirectory = core.getInput('terraform_directory'); | ||
let terraformDoApply = core.getInput('terraform_do_apply') === 'true'; | ||
let terraformDoDestroy = core.getInput('terraform_do_destroy') === 'true'; | ||
const terraformLock = core.getInput('terraform_lock'); | ||
let terraformDoApply = core.getBooleanInput('terraform_do_apply'); | ||
let terraformDoDestroy = core.getBooleanInput('terraform_do_destroy'); | ||
const terraformLock = core.getBooleanInput('terraform_lock'); | ||
const terraformParallelism = core.getInput('terraform_parallelism'); | ||
const terraformTargets = core.getMultilineInput('terraform_targets'); | ||
const terraformVariables = core.getInput('terraform_variables'); | ||
const terraformWorkspace = core.getInput('terraform_workspace'); | ||
|
||
|
@@ -57,10 +58,6 @@ async function terraform(args) { | |
let tf_workspace_deletion = status_skipped; | ||
|
||
core.startGroup('Sanity checking inputs'); | ||
if (terraformLock !== 'true' && terraformLock !== 'false') { | ||
core.setFailed(`Sanity checks failed. Unknown value for 'terraform_lock': ${terraformLock}`); | ||
process.exit(1); | ||
} | ||
Comment on lines
-60
to
-63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obsoleted by using |
||
if (/^\d+$/.test(terraformParallelism) === false) { | ||
core.setFailed(`Sanity checks failed. Non-integer value for 'terraform_parallelism': ${terraformParallelism}`); | ||
process.exit(1); | ||
|
@@ -178,7 +175,7 @@ async function terraform(args) { | |
} | ||
|
||
core.startGroup('Run terraform plan'); | ||
const tfp = await terraform(['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan']); | ||
const tfp = await terraform(['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-out=terraform.plan'].concat(terraformTargets)); | ||
core.endGroup(); | ||
if (tfp.status > 0) { | ||
tf_plan = status_failed; | ||
|
@@ -190,7 +187,7 @@ async function terraform(args) { | |
|
||
core.startGroup('Run terraform apply'); | ||
if (terraformDoApply === true) { | ||
const tfa = await terraform(['apply', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve', 'terraform.plan']); | ||
const tfa = await terraform(['apply', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve', 'terraform.plan'].concat(terraformTargets)); | ||
core.endGroup(); | ||
if (tfa.status > 0) { | ||
tf_apply = status_failed; | ||
|
@@ -206,7 +203,7 @@ async function terraform(args) { | |
/* DESTROY START */ | ||
core.startGroup('Run terraform destroy'); | ||
if (terraformDoDestroy === true) { | ||
const tfd = await terraform(['destroy', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve']); | ||
const tfd = await terraform(['destroy', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, '-auto-approve'].concat(terraformTargets)); | ||
EvyBongers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
core.info(tfd.stdout); | ||
core.endGroup(); | ||
if (tfd.status > 0) { | ||
|
@@ -215,7 +212,7 @@ async function terraform(args) { | |
} else { | ||
tf_destroy = status_success; | ||
|
||
if (terraformWorkspace && terraformWorkspace !== 'default') { | ||
if (terraformWorkspace && terraformWorkspace !== 'default' && !terraformTargets) { | ||
core.startGroup('Run terraform workspace deletion'); | ||
await terraform(['workspace', 'select', 'default']); // have to switch to different workspace before deleting workspace defined in `terraformWorkspace` | ||
const tfwd = await terraform(['workspace', 'delete', terraformWorkspace]); // have to switch to different workspace before deleting workspace defined in `terraformWorkspace` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found this method by chance. It validates values against the YAML 1.2 "Core Schema" specification.
https://github.com/actions/toolkit/blob/main/packages/core/src/core.ts#L161-L181