infracost: Error loading Terraform modules: can't make path relative

In my Gitlab CI pipeline, I was using infracost/infracost:ci-0.10 version and since the last upgrade went in 3 days back .16 my pipeline has been failing with the following error.

$ cd /tmp/base # collapsed multi-line command
time="2023-01-19T10:25:23Z" level=info msg="Evaluating Terraform directory at ."
time="2023-01-19T10:25:23Z" level=info msg="Starting: Downloading Terraform modules"
time="2023-01-19T10:25:23Z" level=info msg="Evaluating Terraform directory at ."
time="2023-01-19T10:25:23Z" level=info msg="Starting: Downloading Terraform modules"
time="2023-01-19T10:25:23Z" level=info msg="Evaluating Terraform directory at ."
time="2023-01-19T10:25:23Z" level=info msg="Starting: Downloading Terraform modules"
time="2023-01-19T10:25:23Z" level=info msg="Evaluating Terraform directory at ."
time="2023-01-19T10:25:23Z" level=info msg="Starting: Downloading Terraform modules"
Error: Error loading Terraform modules: could not load modules for path . Rel: can't make cloudwatch relative to /builds/swateekj/c[36](https://gitlab.com/swateekj/my-infra/-/jobs/3628005383#L36)0/my-infra/

Everytime I retry the pipeline, the module complained about is different (like cloudwatch in the example above).

From the CI file, the command which runs is

cd /tmp/base
infracost breakdown --config-file=${CI_PROJECT_DIR}/${INFRACOST_CONFIG_FILE} \
                    --format=json \
                    --out-file=infracost-base.json

Workaround For now, I have moved it to the previous infracost/infracost:ci-0.10.15 and it is working fine.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 18 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for reporting this @swateek and the help debugging @nick-ppcprotect, a fix for this issue has been merged into master and will go out with the next release. I’ll ping you here when it’s live.

I was having the same issue - fixing version to 0.10.15 worked for me!

@nick-ppcprotect sorry about that - as a workaround until we get a fix out, you can use the version key in infracost/actions/setup to force the old CLI version to be used:

Workaround until this issue is fixed

uses: infracost/actions/setup@v2
with:
  api-key: ${{ secrets.INFRACOST_API_KEY }}
  version: 0.10.15

If you’re using the CLI binary directly, use this version, and for Docker use infracost/infracost:ci-0.10.15.

Hello @swateek , @nick-ppcprotect & @confiq - I can confirm that the fix for this issue has been released as part of the v0.10.17 infracost CLI. Thanks for bringing this to our attention. I’m going to close this issue now, but please comment if you still are experiencing problems.

@hugorut looks like that fixed it. I was able to run locally without the error. Thank you!

@nick-ppcprotect / @swateek I’m struggling to replicate this issue locally, any additional information you could give would be great.

Here’s what I’ve tried so far. I have a project like so:

infrastructure/
└── terraform
    ├── dev.tfvars
    ├── main.tf
    └── modules
        └── terraform-elasticache-redis
            └── main.tf
infracost.yml

and my infracost.yml file has the following:

version: 0.1
projects:
    - path: infrastructure/terraform
      name: dev
      terraform_var_files:
        - dev.tfvars

running infracost breakdown --config-file infracost.yml gives me a successful output.

Some further questions for you both:

  1. @swateek if you could post your project structure that would be great
  2. @nick-ppcprotect: what does your terraform-elasticache-redis module look like? Does it include any third party modules?