https://infracost.io logo
#general
Title
# general
g

gray-school-17920

06/11/2021, 9:55 AM
Hi, I’m running into some issues with the Atlantis integration using Terragrunt and thought i’d ask here for help. Infracost can’t find the terraform binary for some reason even with an absolute path set, however Atlantis can init/plan in the other steps just fine using it. Snippets in the🧵 Thanks in advance
1
Copy code
Running infracost breakdown using:
  $ infracost breakdown --no-color --format json --path /atlantis-data/repos/productboard/pb-infrastructure/464/default/aws/pb-ops-843222783279/us-east-1/elasticache-redis/default.tfplan
time="2021-06-10T13:22:12Z" level=info msg="Detected Terraform plan file at /atlantis-data/repos/productboard/pb-infrastructure/464/default/aws/pb-ops-843222783279/us-east-1/elasticache-redis/default.tfplan"
time="2021-06-10T13:22:12Z" level=warning msg="Can't sync usage file as it's not specified"
time="2021-06-10T13:22:12Z" level=debug msg="Checking if /atlantis-data/repos/productboard/pb-infrastructure/464/default/aws/pb-ops-843222783279/us-east-1/elasticache-redis/default.tfplan is a git repo"
time="2021-06-10T13:22:12Z" level=debug msg="Could not detect Terraform workspace for /atlantis-data/repos/productboard/pb-infrastructure/464/default/aws/pb-ops-843222783279/us-east-1/elasticache-redis/default.tfplan"
Error: Terraform binary "/usr/local/bin/terragrunt --terragrunt-tfpath /atlantis-data/bin/terraform1.0.0" could not be found.
Set a custom Terraform binary in your Infracost config or using the environment variable INFRACOST_TERRAFORM_BINARY.

[terragrunt] [/atlantis-data/repos/productboard/pb-infrastructure/464/default/aws/pb-ops-843222783279/us-east-1/elasticache-redis] 2021/06/10 13:20:55 Running command: terraform1.0.0 --version
[terragrunt] 2021/06/10 13:20:56 Terraform version: 1.0.0
[terragrunt] 2021/06/10 13:20:56 Reading Terragrunt config file at /atlantis-data/repos/productboard/pb-infrastructure/464/default/aws/pb-ops-843222783279/us-east-1/elasticache-redis/terragrunt.hcl
[terragrunt] 2021/06/10 13:20:56 Generated file /atlantis-data/repos/productboard/pb-infrastructure/464/default/aws/pb-ops-843222783279/us-east-1/elasticache-redis/backend.tf.
[terragrunt] [/atlantis-data/repos/productboard/pb-infrastructure/464/default/aws/pb-ops-843222783279/us-east-1/elasticache-redis] 2021/06/10 13:20:56 Initializing remote state for the s3 backend
[terragrunt] [/atlantis-data/repos/productboard/pb-infrastructure/464/default/aws/pb-ops-843222783279/us-east-1/elasticache-redis] 2021/06/10 13:20:57 Running command: terraform1.0.0 init
Initializing modules...

Initializing the backend...

Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Workflow
Copy code
workflows:
  terragrunt:
    plan:
      steps:
      - env:
          name: INFRACOST_LOG_LEVEL
          value: debug
      - env:
          name: atlantis_debug
          value: true
      - env:
          name: TERRAGRUNT_TFPATH
          command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
      - env:
          name: TF_CLI_ARGS
          value: "-no-color"
      - init:
          # <https://github.com/runatlantis/atlantis/issues/1408>
          extra_args: ["-upgrade=false"]
      - run: terragrunt plan -out $PLANFILE
      - env:
          name: INFRACOST_TERRAFORM_BINARY
          command: 'echo "/usr/local/bin/terragrunt --terragrunt-tfpath /atlantis-data/bin/terraform${ATLANTIS_TERRAFORM_VERSION}"'
      - run: "/home/atlantis/infracost_atlantis_diff.sh"
l

little-author-61621

06/11/2021, 10:32 AM
Hi! It looks like it's not being detected because it's trying to find a binary called
"/usr/local/bin/terragrunt --terragrunt-tfpath /atlantis-data/bin/terraform1.0.0"
. I'm guessing it's the flag that's causing the issue. I wonder if this can be solved by setting
INFRACOST_TERRAFORM_BINARY=/usr/local/bin/terragrunt
and also passing in a separate env var for
TERRAGRUNT_TFPATH=/atlantis-data/bin/terraform1.0.0
w

white-airport-8778

06/11/2021, 10:33 AM
@little-author-61621 do we even need
INFRACOST_TERRAFORM_BINARY
here? since there is a $PLANFILE already, infracost would run
terraform show
and that switches plan binary to json, right?
l

little-author-61621

06/11/2021, 10:34 AM
Ah yeah that's a good spot.
g

gray-school-17920

06/11/2021, 11:37 AM
Thanks for the tips. Looks like I had it set up almost correctly previously but then got lost in the weeds of troubleshooting 😅 This configuration of the env works:
Copy code
- env:
          name: INFRACOST_TERRAFORM_BINARY
          command: 'echo "/atlantis-data/bin/terraform${ATLANTIS_TERRAFORM_VERSION}"'
Removing INFRACOST_TERRAFORM_BINARY didn’t work for me because it looks like we have terraform 0.15.1 at /usr/loca/bin/terraform so it tried to read the planfile with a different TF version Thanks for the quick help!
🚀 1
l

little-author-61621

06/11/2021, 1:58 PM
Ah, yeah that makes sense. Thanks @gray-school-17920!
w

white-airport-8778

06/11/2021, 2:07 PM
@gray-school-17920 would this be clearer if I change this doc to: • the absolute path of one of the Terraform binaries that the Atlantis image supports, e.g.
/usr/local/bin/terraform0.12.30
. • a relative path from the directory in which Atlantis keeps the Terraform binary in, e.g.
<data-dir>/bin/terraform<version>
. Terragrunt users should use this, e.g.
'echo "/atlantis-data/bin/terraform${ATLANTIS_TERRAFORM_VERSION}"'
Any other suggestion on how to improve the readme?
1
g

gray-school-17920

06/16/2021, 11:39 AM
Sorry for the late reply @white-airport-8778. Yes the edits make it clearer. One thing which isn’t quite clear to me from the Readme is when should the
terragrunt
binary be used for Infracost. In my case, it’s enough to set _`INFRACOST_TERRAFORM_BINARY`_ to the TF binary directly, since terragrunt outputs the Planfile in our workflow. The terragrunt specific docs don’t really help in that regard.
w

white-airport-8778

06/16/2021, 11:41 AM
Good point, I’ve created https://github.com/infracost/infracost/issues/807 so we support Terragrunt as a project team, to see if we can remove the need to set
INFRACOST_TERRAFORM_BINARY
altogether. Feel free to watch that ticket or comment if you have ideas/use-cases.
👍 1
7 Views