infracost/actions

Empty Infracost output

dcarbone opened this issue · 8 comments

I'm attempting to use v2 of the infracost action from a plan output json and running into a bizarre issue. The step runs successfully, is able to identify input and output files, but the comment step always produces an empty comment:

Screen Shot 2022-06-22 at 1 48 50 PM

The step code looks something like this:

steps:
  - name: Generate Infracost diff
    id: infracost-diff
    run: |
      # define vars
      _infile="${{ steps.terraform-show.outputs.outfile }}"
      _outfile="/tmp/infracost.json"
      
      # execute infracost
      infracost diff \
        --path="${_infile}" \
        --format=json \
        --out-file="${_outfile}"
      
      # set outputs
      echo "::set-output name=outfile::${_outfile}"

Any pointers? The entirely empty output is puzzling!

@dcarbone puzzling indeed! Here are some questions/pointers:

  1. Are you generating a TF plan JSON file using terraform show -json, e.g. shown in this example? Notice how that example shows the TF plan JSON file is generated from the TF plan binary file.

  2. Can you please add --log-level debug to that diff command, then see if the GH Action logs provide any clues?

  3. What exact CLI version is being installed? That's shown in the Setup action logs, e.g. this.

@alikhajeh1: At this point I have tried using both base -> diff and plan -> show -> diff procedures, both produce the same empty comment output.

I will execute again with --debug and report back :)

Hmm, so looks like I get quite a few errors and stacktraces.

Below is the first one, I can provide others if need be.

Error:

time="2022-06-23T19:09:17Z" level=debug parser=terraform_hcl msg="could not evaluate value for attr: for_each err: value is not a collection

Trace:

runtime/debug.Stack()
	/opt/hostedtoolcache/go/1.18.3/x64/src/runtime/debug/stack.go:24 +0x65
github.com/infracost/infracost/internal/hcl.(*Attribute).value.func1()
	/home/runner/work/infracost/infracost/internal/hcl/attribute.go:71 +0x79
panic({0x1c4a6a0, 0x26b9350})
	/opt/hostedtoolcache/go/1.18.3/x64/src/runtime/panic.go:838 +0x207
github.com/zclconf/go-cty/cty.Value.LengthInt({{{0x26d60c0?, 0xc0001f21cd?}}, {0x1c4a6a0?, 0xc00060c860?}})
	/home/runner/go/pkg/mod/github.com/zclconf/go-cty@v1.10.0/cty/value_ops.go:1087 +0x20d
github.com/zclconf/go-cty/cty.Value.AsValueMap({{{0x26d60c0?, 0xc0001f21cd?}}, {0x1c4a6a0?, 0xc00060c860?}})
	/home/runner/go/pkg/mod/github.com/zclconf/go-cty@v1.10.0/cty/value_ops.go:1318 +0x71
github.com/infracost/infracost/internal/hcl.buildObject({0xc0005ca1e0, 0x3, 0x3}, 0x40d687?, {{{0x26d60c0?, 0xc0001f21cd?}}, {0x1c4a6a0?, 0xc00060cb30?}}, 0x1)
	/home/runner/work/infracost/infracost/internal/hcl/attribute.go:242 +0xdaf
github.com/infracost/infracost/internal/hcl.buildObject({0xc0005ca1e0, 0x3, 0x3}, 0xc0005ca030?, {{{0x26d60c0?, 0xc0001f21cd?}}, {0x1c4a6a0?, 0xc00060cb30?}}, 0x0)
	/home/runner/work/infracost/infracost/internal/hcl/attribute.go:267 +0x5d7
github.com/infracost/infracost/internal/hcl.traverseVarAndSetCtx(0xc00060f3c0?, {0xc0005ca1e0, 0x3, 0x3}, {{{0x26d60c0?, 0xc0001f21cd?}}, {0x1c4a6a0?, 0xc00060cb30?}})
	/home/runner/work/infracost/infracost/internal/hcl/attribute.go:175 +0x27a
github.com/infracost/infracost/internal/hcl.(*Attribute).value(0xc00060f3c0, 0x2)
	/home/runner/work/infracost/infracost/internal/hcl/attribute.go:102 +0x6f1
github.com/infracost/infracost/internal/hcl.(*Attribute).value(0xc00060f3c0, 0x1)
	/home/runner/work/infracost/infracost/internal/hcl/attribute.go:124 +0x9f1
github.com/infracost/infracost/internal/hcl.(*Attribute).value(0xc00060f3c0, 0x0)
	/home/runner/work/infracost/infracost/internal/hcl/attribute.go:124 +0x9f1
github.com/infracost/infracost/internal/hcl.(*Attribute).Value(...)
	/home/runner/work/infracost/infracost/internal/hcl/attribute.go:65
github.com/infracost/infracost/internal/hcl.(*Evaluator).expandBlockForEaches(0xc000365c20, {0xc00060f320, 0x3, 0x3?})
	/home/runner/work/infracost/infracost/internal/hcl/evaluator.go:288 +0x174
github.com/infracost/infracost/internal/hcl.(*Evaluator).expandBlocks(0xc00039b500?, {0xc0003d19c0?, 0x26d61a0?, 0xc00017c180?})
	/home/runner/work/infracost/infracost/internal/hcl/evaluator.go:252 +0x38
github.com/infracost/infracost/internal/hcl.(*Evaluator).loadModules(0xc000365c20)
	/home/runner/work/infracost/infracost/internal/hcl/evaluator.go:634 +0x5b
github.com/infracost/infracost/internal/hcl.(*Evaluator).Run(0xc000365c20)
	/home/runner/work/infracost/infracost/internal/hcl/evaluator.go:144 +0xd2
github.com/infracost/infracost/internal/hcl.(*Parser).ParseDirectory(0xc00056e0b0)
	/home/runner/work/infracost/infracost/internal/hcl/parser.go:329 +0x4b0
github.com/infracost/infracost/internal/providers/terraform.(*HCLProvider).Modules(0xc00056d440)
	/home/runner/work/infracost/infracost/internal/providers/terraform/hcl_provider.go:248 +0x139
github.com/infracost/infracost/internal/providers/terraform.(*HCLProvider).LoadPlanJSONs(0xc00056d440)
	/home/runner/work/infracost/infracost/internal/providers/terraform/hcl_provider.go:216 +0x4a
github.com/infracost/infracost/internal/providers/terraform.(*HCLProvider).LoadResources(0xc000184f00?, 0x4?)
	/home/runner/work/infracost/infracost/internal/providers/terraform/hcl_provider.go:171 +0x35
main.(*parallelRunner).runProjectConfig(0xc0005dd3e0, 0xc0005e4780)
	/home/runner/work/infracost/infracost/cmd/infracost/run.go:474 +0x1269
main.(*parallelRunner).run.func1()
	/home/runner/work/infracost/infracost/cmd/infracost/run.go:310 +0x1c5
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:57 +0x67
created by golang.org/x/sync/errgroup.(*Group).Go
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:54 +0x8d

Hey @dcarbone, this is interesting, it looks like the for_each has an expression that can't be evaluated for some reason. Do you have any inkling as to which Terraform block this might be for? It's normally one that has a complex expression or uses a data block? The debug log might have some further information to help track it down, but we try and omit actual block names from there, as it would get very long. If you can locate the problem block and its for_each attribute it will be super helpful for us to try and fix this for you.

But I would add that using the terraform show method and providing Infracost a plan JSON shouldn't run into this issue. So you could also try and run that method again with --debug and posting the logs here. There might be something more sinister going on that we're not catching.

Hmm yeah so using the tf plan -> show operation results in the same output, but no obvious errors in the logs.

Unfortunately I don't have much time to spare debugging this much more. V1 works just fine for us, so I will unfortunately have to just stick with V1 for now until I can get more time to dedicate towards debugging this.

@dcarbone in case you'd like to screenshare in the future, I'm happy to jump on a zoom call to debug - email me at ali.hosseini@infracost.io if you'd like to arrange that.

Closing this issue as we can't reproduce the issue but feel free to email me or join https://www.infracost.io/community-chat to debug