Terraform: plan -detailed-exitcode -destroy return "2" when nothing to destroy

Created on 15 Nov 2019  路  5Comments  路  Source: hashicorp/terraform

Terraform Version

$ terraform -v
Terraform v0.12.15

Expected Behavior

as per help, terraform plan -detailed-exitcode should return:

                      0 - Succeeded, diff is empty (no changes)
                      1 - Errored
                      2 - Succeeded, there is a diff

Actual Behavior

terraform plan -detailed-exitcode -destroy returns '2' on already destroyed infra.

Steps to Reproduce

On an already destroyed infra (I'm using shared state/lock on S3/DynamoDB):

  1. terraform init
  2. terraform plan -detailed-exitcode -destroy -out=./planfile
  3. $?. It returns 2 code, and the following message to stdout:
------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

Plan: 0 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Then, upon acting on the plan...

$ terraform show ./planfile
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

Plan: 0 to add, 0 to change, 0 to destroy.

Additional Context

This behaviour has changed a bit since Terraform v0.12.10: while the plan step produced the same stdout, and exit code, terraform show offered a different message:

$ terraform show ./planfile
This plan does nothing.

References

This behaviour is neither the first, nor the second, nor the third time it gets described:

  • #16055
  • #18453
  • #18224
bug cli v0.10 v0.11 v0.12

Most helpful comment

Hey @danieldreier I'm a new contributor and I'm willing to contribute on this. Please advise if I can proceed to start working on it. Thanks

All 5 comments

Hey @danieldreier I'm a new contributor and I'm willing to contribute on this. Please advise if I can proceed to start working on it. Thanks

I'm experiencing the same issue on terraform plan -detailed-exitcode -destroy this is my output:

An execution plan has been generated and is shown below.

Resource actions are indicated with the following symbols:



Terraform will perform the following actions:



Plan: 0 to add, 0 to change, 0 to destroy.

script returned exit code 2

Hello same issue

```------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

Plan: 0 to add, 0 to change, 0 to destroy.

Changes to Outputs:


Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.```

echo $?
2

on terraform 0.13.0 on 0.12.26 it was OK

I can confirm this bug is still present on terraform v0.13.0.

I can confirm it is present in terraform v0.13.5. We had one check that flagged a change in a datasource which caused exit code 2

Was this page helpful?
0 / 5 - 0 ratings