Hello Infracost team! :wave: I am trying to use `c...
# help
w
Hello Infracost team! đź‘‹ I am trying to use
config
feature to get a single comment for different environments of the same terraform folder (feeding different .tfvar files) on CircleCI. I followed docs https://www.infracost.io/docs/features/config_file/ and https://github.com/infracost/infracost-circleci and have somewhat working comment posted in PR. But this comment consists of duplicate pairs of my “projects”. I suspect this is because my baseline “project” has different path where it was estimated? Would appreciate any advise on how to make this look properly, i.e merged and get a proper diff? Thanks in advance 🤝
w
đź‘‹ Hi @wonderful-lizard-93382, two things to check: 1. Locally in your dev machine, when you run this, do you see the correct project list? i.e. no duplicates and the correct project paths/names?
Copy code
infracost generate config --repo-path=. \
    --template-path=infracost.yml.tmpl
2. In CircleCI, does the main branch have the same config file? i.e. in CircleCI it would be doing this:
Copy code
git clone $CIRCLE_REPOSITORY_URL --branch=$BASE_BRANCH --single-branch /tmp/base 

# Breakdown using generated config file from main branch
infracost generate config --repo-path=/tmp/base \
    --template-path=/tmp/base/infracost.yml.tmpl \
    --out-file=/tmp/base/infracost.yml

infracost breakdown --config-file=/tmp/base/infracost.yml \
                    --format=json \
                    --out-file=/tmp/infracost-base.json

# Diff using generated config file from feature branch
infracost generate config --repo-path=${TF_ROOT} \
    --template-path=${TF_ROOT}/infracost.yml.tmpl \
    --out-file=${TF_ROOT}/infracost.yml

infracost diff --config-file=${TF_ROOT}/infracost.yml \
               --format=json \
               --compare-to=/tmp/infracost-base.json \
               --out-file=/tmp/infracost.json

infracost comment --path=/tmp/infracost.json
w
Hello @white-airport-8778, thank you for such a quick response. In my setup I am generating the config file just from feature branch, and using it for both “base” and “feature” branches, I will generate them separately and check whether it helps 🤝
w
@wonderful-lizard-93382 sure, separately should work better for cases when the feature branch gets a new project that’s not on main
w
I fixed my build, thank you. I had to use
working_directory:
key in CircleCI config to run commands from relevant directories (one for BASE and one for FEATURE branches) also making sure “path” parameter in config file in project is set properly (it was “.” like in the example) thats what I think was the root of the issue. Resulting comment looks awesome!