Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

- [Issue #432](https://github.com/manheim/terraform-pipeline/issues/432) pass TagPlugin through `-var-file={env}-tags.tfvars`
- [Issue #432](https://github.com/manheim/terraform-pipeline/issues/432) pass TagPlugin through `-var-file={env}-tags.tfvars`
- [Issue #417](https://github.com/manheim/terraform-pipeline/issues/417) DestroyPlugin & PassPlanFilePlugin - Terraform Destroy can't be called with a plan file

# v5.19

Expand Down
9 changes: 8 additions & 1 deletion src/TerraformApplyCommand.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ class TerraformApplyCommand implements TerraformCommand, Resettable {
if (directory && chdir_flag) {
pieces << "-chdir=${directory}"
}
pieces << command
// If we have a plan file, apply is the only command that works.
// Even on destroy, you must use `terraform apply` for a plan file
// created with the `-destroy` argument.
if (planFile) {
pieces << "apply"
} else {
pieces << command
}
if (!input) {
pieces << "-input=false"
}
Expand Down
9 changes: 9 additions & 0 deletions test/TerraformApplyCommandTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ class TerraformApplyCommandTest {
def actualCommand = command.toString()
assertThat(actualCommand, endsWith(" foobar"))
}

@Test
void forcesApplyIfPlanFilePresent() {
def command = new TerraformApplyCommand().withPlanFile("foobar")
.withCommand("destroy")

def actualCommand = command.toString()
assertThat(actualCommand, startsWith("terraform apply"))
}
}

@Nested
Expand Down