This message was deleted.
# general
b
This message was deleted.
c
actually, I didn't change state but infracost started throwing this error
l
hmm, this looks odd. Infracost should run init automatically if it's required. What's your gh-action configuration?
From the error message it looks like it's recognising the S3 backend as a new backend, so I'm wondering if it doesn't have access to that bucket or something.
c
Copy code
# Copied from <https://github.com/marketplace/actions/run-infracost>
on:
  push:
    paths:
      - '**.tf'
      - '**.tfvars'
      - '**.tfvars.json'
jobs:
  infracost:
    runs-on: ubuntu-latest
    name: Show infracost diff
    steps:
    - name: Check out repository
      uses: actions/checkout@v2
    - name: Infracost
      uses: infracost/infracost-gh-action@v0.7.0
      env:
        INFRACOST_API_KEY: ${{ secrets.INFRACOST_API_KEY }}
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        entrypoint: /scripts/ci/diff.sh # Do not change
        config_file: 'infracost.yml'
yep, it did run init before, but now only
Copy code
terraform plan
full logs
Copy code
Running infracost breakdown using:
  $ infracost breakdown --no-color --format json --config-file infracost.yml
time="2021-06-18T04:39:40Z" level=info msg="Detected Terraform directory at website/production/"
time="2021-06-18T04:39:41Z" level=warning msg="Can't sync usage file as it's not specified"
time="2021-06-18T04:39:41Z" level=info msg="starting: Running terraform plan"
time="2021-06-18T04:39:41Z" level=info msg="Running command: /usr/bin/terraform plan -input=false -lock=false -no-color -out=/tmp/tfplan768928249"
l
I think I've found what might be causing it. There's no easy way to detect if we need to run init without parsing the output from
terraform plan
. So currently, we check for certain errors from that. Terraform has recently added a new error https://github.com/hashicorp/terraform/commit/9b1bd19ca5ac15325fb663743503e83e0d8a0689#diff-2bb17b35251ba77935e5edc3[…]1d268c10d1ef0eaeca2ab832eR576. So we need to add support for that here: https://github.com/infracost/infracost/blob/master/internal/providers/terraform/dir_provider.go#L223-L227. I'll add that just now so it makes the next release. In the meantime, I think it can be worked round by forcing an init in the action before the Infracost step runs
Copy code
- name: "Install terraform"
      uses: hashicorp/setup-terraform@v1

    - name: "Terraform init"
      id: init
      run: terraform init
      working-directory: path/to/code
c
thanks @little-author-61621 Am I right that this work around solution will not work with
config_file
option?
l
It should work, but the init would need to be run for each project you specify in the config file
What I can actually do just now is push a custom image, so you can just change to the action to
uses: infracost/infracost-gh-action@fix-init
until this is released properly.
^ that's pushed now if you want to use it
c
thanks, very appreciate