Skip to content
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

terraform show on v0.12 only display resource addresses #23106

Closed
remipichon opened this issue Oct 17, 2019 · 6 comments · Fixed by #23292
Closed

terraform show on v0.12 only display resource addresses #23106

remipichon opened this issue Oct 17, 2019 · 6 comments · Fixed by #23292
Labels
bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@remipichon
Copy link

Terraform Version

0.12.10

Terraform Configuration Files

provider "aws" {
  region = "eu-west-1"
  version = "2.32.0"
}


resource "aws_s3_bucket" "bucket" {
  bucket = "test"

  tags = {
    test = "test"
  }
}

Expected Behavior

terraform show should display the full plan, the exact same output as the terraform plan

Terraform will perform the following actions:

  # aws_s3_bucket.bucket will be created
  + resource "aws_s3_bucket" "bucket" {
      + acceleration_status         = (known after apply)
      + acl                         = "private"
      + arn                         = (known after apply)
      + bucket                      = "test"
      + bucket_domain_name          = (known after apply)
      + bucket_regional_domain_name = (known after apply)
      + force_destroy               = false
      + hosted_zone_id              = (known after apply)
      + id                          = (known after apply)
      + region                      = (known after apply)
      + request_payer               = (known after apply)
      + tags                        = {
          + "test" = "test"
        }
      + website_domain              = (known after apply)
      + website_endpoint            = (known after apply)

      + versioning {
          + enabled    = (known after apply)
          + mfa_delete = (known after apply)
        }
    }

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

Actual Behavior

terraform show only outputs the resource name, which is not very useful

  + aws_s3_bucket.bucket

it works perfectly on 0.11 and I always had this issue with 0.12 (any of the versions)

Steps to Reproduce

Please list the full steps required to reproduce the issue, for example:

  1. $HOME/terraform_0.12.10 init
  2. $HOME/terraform_0.12.10 plan -out test.plan
  3. $HOME/terraform_0.12.10 show test.plan

References

@hashibot hashibot added bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases labels Oct 17, 2019
@eduardZA
Copy link

I've been struggling with this exact same issue since 0.12.0.

Additionally, the -json flag doesn't seem to do what the documentation says it should:

For Terraform plan files, terraform show -json will show a JSON representation of the plan, configuration, and current state.

The structure of the -json output resembles the following:

{
  "format_version": "0.1",
  "terraform_version": "0.12.12",
  "variables": {...
  },
  "planned_values": {...
  },
  "resource_changes": [...
  ],
  "prior_state": {...
  },
  "configuration": {...
  }
}

planned_values contains all resources. resource_changes contains all resources and lists them with a change.before (null for new resources) and change.after attribute. I've not been able to find a namespace in that structure that only contains the effective plan or diff.

We use this with 0.11 to post the plan as a comment on pull requests. Losing this functionality would really be a shame. Am I doing it wrong? Must we fall back to either teeing and scraping the output of terraform plan, or parsing the JSON file with jq?

@remipichon
Copy link
Author

@apparentlymart can you confirm it's either a bug or document miss-understanding and if there is a workaround ?

@eduardZA to overcome this issue, I wrote a small wrapper which captures the plan output and stores it along the Json plan. Not ideal though.

@eduardZA
Copy link

eduardZA commented Nov 5, 2019

@remipichon, yeah, I'm heading in the same direction:

terraform plan \
  -var "environment=$ENVIRONMENT" \
  -var-file=env.$ENVIRONMENT.tfvars \
  -var-file=_$ENVIRONMENT/environment.tfvars \
  -out=_$ENVIRONMENT/proposed.plan \
  | tee "_${ENVIRONMENT}/proposed_raw.plan"

# Find text between -{72} and -{72} or "This means that..."
# Reference:  https://stackoverflow.com/questions/38972736/how-to-print-lines-between-two-patterns-inclusive-or-exclusive-in-sed-awk-or
grep -Pzo "(?s)((?<=[-]{72}\n)(.*?)(?=(\n[-]{72}|This means that Terraform did not detect any differences between your)))" "_${ENVIRONMENT}/proposed_raw.plan" > "_${ENVIRONMENT}/proposed_parsed.plan"

As you say, not ideal :(

@remipichon
Copy link
Author

I like your one liner ! Thanks, much more concise than my wrapper 👍

@eduardZA
Copy link

eduardZA commented Nov 5, 2019

Pleasure! Now to figure out how to post the content as a PR comment on Bitbucket. Can't seem to figure out their v2.0 API :/

@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants