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 plan produces invalid out file #42

Closed
tr00p86 opened this issue Aug 28, 2020 · 6 comments
Closed

Terraform plan produces invalid out file #42

tr00p86 opened this issue Aug 28, 2020 · 6 comments
Labels
question Further information is requested

Comments

@tr00p86
Copy link

tr00p86 commented Aug 28, 2020

Hi,

I am trying to use the out file of terraform plan to convert to .json in order to apply some policy-as-code.

  • Terraform show -json out.file > out.file.json from the github action produces invalid JSON.
  • I am trying to use another tool called jfson that tells me the out file is not a valid plan file.

Anyone is able to produce a valid out file from this github action and convert to JSON?

@heathsnow
Copy link

heathsnow commented Aug 31, 2020

I'm trying to consume the out file as part of executing terraform-compliance and i get the following error:

ERROR: Failed to convert terraform plan file to JSON format via terraform. Here is the error :

. Converting terraform plan file.
None

Error: Error loading state: state snapshot was created by Terraform v0.13.1, which is newer than current v0.13.0; upgrade to Terraform v0.13.1 or greater to work with this state

My state file was saved with Terraform 0.13.1 and my GitHub Action is executing with Terraform 0.13.1 so I'm not sure what's up here.

Edit: See comment below: #42 (comment)

@chenrui333
Copy link
Contributor

@heathsnow I think you need to declare the terraform_version?

steps:
- uses: hashicorp/setup-terraform@v1
  with:
    terraform_version: 0.13.1

@heathsnow
Copy link

@chenrui333

I think my issue was on the terraform-compliance side of things so safe to ignore my comment above :). That and I don't remember what my workflow was at the time :P

@aeschright aeschright added the question Further information is requested label Apr 20, 2021
@andy-caruso
Copy link

If you need to use the output of the command somewhere else you'll need to do the following:

    - uses: hashicorp/setup-terraform@v1
       with:
         terraform_wrapper: false

... Some stuff...

      - name: Terraform Plan
        run: terraform -chdir=terraform/workspace plan -out=tf.plan
      - name: Terraform JSON output
        run: terraform -chdir=terraform/workspace show -json tf.plan > tfplan.json
      - name: Do something with the plan
        uses: actions/terraform-plan-user
        with:
          tf-plan-json-file: tfplan.json

Otherwise the JSON will have gone through sanitization and will look like:

***"format_version":"0.1","terraform_version":"0.14.11","planned_values":***"outputs":***"project_number":***"sensitive":false,"value":"7109834098491"***,"root_module":***"child_modules":[***"resources":...

Which is really confusing since all the docs say that terraform_wrapper: true will help with output usage in subsequent steps when it does the opposite.

@austinvalle
Copy link
Member

This issue should be fixed in an upcoming v3.0.0 release next week. Please see this comment for more info

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants