Hi, I’m running into some issues with the Atlantis...
# general
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
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.
Copy code
      - 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:
          command: 'echo "/usr/local/bin/terragrunt --terragrunt-tfpath /atlantis-data/bin/terraform${ATLANTIS_TERRAFORM_VERSION}"'
      - run: "/home/atlantis/infracost_atlantis_diff.sh"
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
and also passing in a separate env var for
@little-author-61621 do we even need
here? since there is a $PLANFILE already, infracost would run
terraform show
and that switches plan binary to json, right?
Ah yeah that's a good spot.
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:
          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
Ah, yeah that makes sense. Thanks @gray-school-17920!
@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.
. • a relative path from the directory in which Atlantis keeps the Terraform binary in, e.g.
. Terragrunt users should use this, e.g.
'echo "/atlantis-data/bin/terraform${ATLANTIS_TERRAFORM_VERSION}"'
Any other suggestion on how to improve the readme?
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
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.
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
altogether. Feel free to watch that ticket or comment if you have ideas/use-cases.
👍 1