Skip to content

plan -detailed-exitcode -destroy return "2" when nothing to destroy #23387

@next-jesusmanuelnavarro

Description

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:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions