Hi :slightly_smiling_face: I'm just doing some PoC...
# help
a
Hi 🙂 I'm just doing some PoC stuff and I've followed the example here But the Gitlab MR comment that infracost posts is giving me a separate row for each as before and after based on the module path. Here is a screenshot. I expect it to use the project name to figure out what it is comparing with but it seems to be doing it on module path. Any common tips on why I might be seeing this, rather than one row each for
bucket-service-production
,
bucket-service-staging
and
ecr-productions
?
l
Hi @ambitious-piano-76477, what does your config file look like?
a
Thanks for reply. Its generated dyanamically, but this is the final config for this repo:
Copy code
version: 0.1
projects:
    - path: terraform/bucket-service
      name: bucket-service-production
      terraform_var_files:
        - env/production/config.tfvars
    - path: terraform/bucket-service
      name: bucket-service-staging
      terraform_var_files:
        - env/staging/config.tfvars
    - path: terraform/ecr
      name: ecr-production
      terraform_var_files:
        - env/production/config.tfvars
l
👍 thanks, I'm in a meeting just now but will have a look when in about an hour and a half and see if I can reproduce it.
@ambitious-piano-76477 do you have the code that generates that config?
a
Sure, this is it:
Copy code
if [ ! -f infracost.yml ]; then
      cat <<EOF>> infracost.yml.tmpl
      version: 0.1
      projects:
      {{- range \$project := matchPaths "terraform/:stack/env/:environment/config.tfvars" }}
          - path: terraform/{{ \$project.stack }}
            name: {{ \$project.stack }}-{{ \$project.environment }}
            terraform_var_files:
              - env/{{ \$project.environment }}/config.tfvars
      {{- end }}
      EOF

      # Generate config file from template for current

      infracost generate config --repo-path=. \
        --template-path=infracost.yml.tmpl \
        --out-file=infracost.yml
      fi;
l
@ambitious-piano-76477 so far I’ve not been able to reproduce. It looks like something odd is going on when it’s working out the base branch paths. Are you able to paste the full gitlab-ci file you’re using? Alternatively I’m happy to Zoom-pair to help debug if you schedule it via https://calendly.com/aiscott.
a
Hi Alistair - thanks for taking a look! I've just managed to get the behaviour I expected by following the breadcrumbs of what is different. Essentially in this shared pipeline file, I wanted to have a default behaviour for our standard Terraform structure of generating an infracost.yml config file if one didn't exist in the repository consuming the pipeline. So that generation happens in the pipeline. From there I just referenced the file from the current checked out branch by assigning the filepath to a variable before CDing to the
/tmp/base
directory to do the initial
infracost breakdown
. To fix, once main branch was cloned at
/tmp/base
I have just
cp infracost.yml /tmp/base
and then pass
infracost.yml
to the
--config-file
flag in both places. Seems that referencing a config file elsewhere was causing some internal shenanigans with how the paths were interpreted.
l
Awesome, thanks for the update @ambitious-piano-76477! I think we’ll need more examples with the generated config file in the docs.