broad-zoo-34077
10/12/2021, 1:19 PMlittle-author-61621
numerous-plastic-31859
10/12/2021, 1:24 PM1.0.5
little-author-61621
little-author-61621
- name: Terraform show
if: github.ref != 'refs/heads/master' && steps.tfplan.outcome == 'success'
id: show
run: terraform show -json plan.tfplan > plan.json
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: "Save Plan JSON"
run: echo '${{ steps.show.outputs.stdout }}' > plan.json
numerous-plastic-31859
10/12/2021, 1:32 PMError: The template is not valid. System.InvalidOperationException: Maximum object size exceeded
at GitHub.DistributedTask.ObjectTemplating.TemplateMemory.AddBytes(Int32 bytes)
at GitHub.DistributedTask.ObjectTemplating.TemplateMemory.AddBytes(LiteralToken literal)
at GitHub.DistributedTask.ObjectTemplating.TemplateUnraveler.LiteralState..ctor(ReaderState parent, LiteralToken literal, TemplateContext context, Int32 removeBytes)
at GitHub.DistributedTask.ObjectTemplating.TemplateUnraveler.ReaderState.CreateState(ReaderState parent, TemplateToken value, TemplateContext context, Int32 removeBytes)
at GitHub.DistributedTask.ObjectTemplating.TemplateUnraveler.BasicExpressionState.Next(TemplateToken value, Int32 removeBytes)
at GitHub.DistributedTask.ObjectTemplating.TemplateUnraveler.MappingValueBasicExpression()
at GitHub.DistributedTask.ObjectTemplating.TemplateUnraveler.Unravel(Boolean expand)
at GitHub.DistributedTask.ObjectTemplating.TemplateUnraveler.AllowScalar(Boolean expand, ScalarToken& scalar)
at GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.Evaluate(DefinitionInfo definition)
at GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.HandleMappingWithAllLooseProperties(DefinitionInfo mappingDefinition, DefinitionInfo keyDefinition, DefinitionInfo valueDefinition, MappingToken mapping)
at GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.Evaluate(DefinitionInfo definition)
at GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.Evaluate(TemplateContext context, String type, TemplateToken template, Int32 removeBytes, Nullable`1 fileId, Boolean omitHeader)
numerous-plastic-31859
10/12/2021, 1:33 PMlittle-author-61621
- name: "Check if plan JSON exists"
run: ls -lah plan.json
numerous-plastic-31859
10/12/2021, 1:41 PM0s
Run ls -lha
ls -lha
shell: /usr/bin/bash -e {0}
env:
AWS_DEFAULT_REGION: eu-central-1
TERRAFORM_CLI_PATH: /home/runner/work/_temp/d6ceddc9-582a-43b5-aa21-ebdec5ea32e5
total 8.1M
drwxr-xr-x 8 runner docker 4.0K Oct 12 13:26 .
drwxr-xr-x 3 runner docker 4.0K Oct 12 13:24 ..
drwxr-xr-x 2 runner docker 4.0K Oct 12 13:24 .devcontainer
drwxr-xr-x 8 runner docker 4.0K Oct 12 13:24 .git
drwxr-xr-x 3 runner docker 4.0K Oct 12 13:24 .github
-rw-r--r-- 1 runner docker 861 Oct 12 13:24 .gitignore
drwxr-xr-x 4 runner docker 4.0K Oct 12 13:25 .terraform
-rw-r--r-- 1 runner docker 1.2K Oct 12 13:24 .terraform.lock.hcl
drwxr-xr-x 2 runner docker 4.0K Oct 12 13:24 .vscode
-rw-r--r-- 1 runner docker 190 Oct 12 13:24 README.md
drwxr-xr-x 5 runner docker 4.0K Oct 12 13:24 aws
-rw-r--r-- 1 runner docker 547 Oct 12 13:24 <http://core.tf|core.tf>
-rw-r--r-- 1 runner docker 15K Oct 12 13:24 <http://external.tf|external.tf>
-rw-r--r-- 1 runner docker 1.6K Oct 12 13:24 <http://main.tf|main.tf>
-rw-r--r-- 1 runner docker 7.6M Oct 12 13:26 plan.json
-rw-r--r-- 1 runner docker 385K Oct 12 13:26 plan.tfplan
^ this was from when I just wrote to plan.json directly from terraform show
numerous-plastic-31859
10/12/2021, 1:42 PM-v "/home/runner/work/terraform/terraform":"/github/workspace"
little-author-61621
format_version
and planned_values
. That's what we use to detect a plan JSON file.numerous-plastic-31859
10/12/2021, 1:48 PMnumerous-plastic-31859
10/12/2021, 1:48 PMnumerous-plastic-31859
10/12/2021, 1:57 PMplan.json
with json_pp
and that returns “malformed JSON string”, so there is probably something about the output redirection as you mentioned before, but then we’re back to Maximum object size exceeded
😕little-author-61621
little-author-61621
infracost/infracost-gh-action@test
. And set the env INFRACOST_LOG_LEVEL: debug
then you should see some more output when we're trying to detect the file typenumerous-plastic-31859
10/12/2021, 2:20 PMRunning infracost breakdown using:
$ infracost breakdown --no-color --format json --path plan.json
time="2021-10-12T14:19:13Z" level=debug msg="File not detected as Terraform Plan JSON. Error unmarshaling file: invalid character 'c' looking for beginning of value"
time="2021-10-12T14:19:13Z" level=debug msg="File not detected as Terraform State JSON. Error unmarshaling file: invalid character 'c' looking for beginning of value"
time="2021-10-12T14:19:13Z" level=debug msg="File not detected as Terraform Plan. Error opening file: zip: not a valid zip file"
Error: Could not detect path type for plan.json
numerous-plastic-31859
10/12/2021, 2:21 PMlittle-author-61621
numerous-plastic-31859
10/12/2021, 2:22 PM${{ steps.show.outputs.stdout }}
failslittle-author-61621
little-author-61621
numerous-plastic-31859
10/12/2021, 2:36 PMlittle-author-61621
infracost
and it will handle the generating of the plan JSON internally, e.g:
- name: Run infracost diff
if: github.ref != 'refs/heads/master'
uses: infracost/infracost-gh-action@master
env:
INFRACOST_API_KEY: ${{ secrets.INFRACOST_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
with:
path: .
numerous-plastic-31859
10/12/2021, 2:54 PM- name: Terraform show
if: github.ref != 'refs/heads/master' && steps.tfplan.outcome == 'success'
id: show
run: terraform show -json plan.tfplan 1> plan.json
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Extract only plan info from plan.json
run: sed -i '2q;d' plan.json
little-author-61621
numerous-plastic-31859
10/12/2021, 2:56 PM