Channels
  • Ondrej Bilcik

    Ondrej Bilcik

    1 year ago
    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
    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
    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"
  • Alistair (Infracost)

    Alistair (Infracost)

    1 year ago
    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
  • Ali (Infracost)

    Ali (Infracost)

    1 year ago
    @Alistair (Infracost) 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?
  • Alistair (Infracost)

    Alistair (Infracost)

    1 year ago
    Ah yeah that's a good spot.
  • Ondrej Bilcik

    Ondrej Bilcik

    1 year ago
    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:
    - 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!
  • Alistair (Infracost)

    Alistair (Infracost)

    1 year ago
    Ah, yeah that makes sense. Thanks @Ondrej Bilcik!
  • Ali (Infracost)

    Ali (Infracost)

    1 year ago
    @Ondrej Bilcik 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?
  • Ondrej Bilcik

    Ondrej Bilcik

    1 year ago
    Sorry for the late reply @Ali (Infracost). 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.