Hello, I’m new to infracost, and I’ve opted to use...
# help
b
Hello, I’m new to infracost, and I’ve opted to use the GitHub plugging for our implementation. I’m currently having an issue with how our Terraform repository is structured. After setting up the plugin, I’m asked to create a PR; after I do, I can see our Atlantis runs its default workflow for path `dir:
applications/give-site/give-ep/cloudops/stage/api-gateway
workspace:
default
but infracost does not find a valid terraform file. From what I can tell, it looks at the root of our repo
CruGlobal/cru-terraform,
not the path from which Atlantis ran its plan. How do I set up the infracost.yml so that Infracots runs on the same path used by Atlantis and not from the root of the repo? I tried the following
Copy code
version: 0.1
projects:
  - path: .*
    include_all_paths: true # include root and non-root modules
dependency_paths:
  - *./terrafrom.tf
Thanks for your help
b
Hello! Sorry for silly question, but have you tried to specify the path to be
- path: applications/give-site/give-ep/cloudops/stage/api-gateway
? Are you using Infracost with the JSON plan or do you want it to parse your TF code?
b
I can try that, but I don’t think that would have the desired result as it will only run infracost for that single path. I need to have infracost run for only the files that have been changed per pull request. Our directory structure is a bit non-standard; it is something like so
Copy code
|
├── app-name-1 (directoruy)
│  ├── <http://terraform.tf|terraform.tf>
|    |——- <http://aws.tf|aws.tf> (file defining general app resources)
│  ├── staging (directory)
|    |            |—— <http://terraform.tf|terraform.tf>
|    |            |—— <http://aws.tf|aws.tf> (file defining environment-specific resources)
│  └── production (directory)
|                |——-<http://terraform.tf|terraform.tf>
|                |——- <http://aws.tf|aws.tf>
├── app-name-2 (directoruy)
│  ├── <http://terraform.tf|terraform.tf>
|    |——- <http://aws.tf|aws.tf> (file defining general app resources)
│  ├── staging (directory)
|    |            |—— <http://terraform.tf|terraform.tf>
|    |            |—— <http://aws.tf|aws.tf> (file defining environment-specific resources)
│  └── production (directory)
|                |——-<http://terraform.tf|terraform.tf>
|                |——- <http://aws.tf|aws.tf>
├── other_infrastructure
It is a single repository — but not a mono repo. I’m starting to think that it might be best to integrate infracost into our Atlantis docker instance with a custom workflow might be best.
b
Thank you for the structure example! Infracost can generate a config file from a template. Given your structure the template like this:
Copy code
version: 0.1
projects:
{{- range $project := matchPaths ":app/:env/terraform.tf" }}
  - path: {{ $project._dir }}
    name: {{ $<http://project.app|project.app> }}/{{ $project.env }}
    dependency_paths:
      - {{ $project._dir }}/../terraform.tf
{{- end }}
will generate a config file like
Copy code
version: 0.1
projects:
  - path: app-name-1/production
    name: app-name-1/production
    dependency_paths:
      - app-name-1/production/../terraform.tf
  - path: app-name-1/staging
    name: app-name-1/staging
    dependency_paths:
      - app-name-1/staging/../terraform.tf
Can you try it? Save the template to
infracost.yml.tmpl
and run
infracost generate config --repo-path . --template-path infracost.yml.tmpl --out-file infracost.yml
I need to have infracost run for only the files that have been changed per pull request.
Our example has two Infracost runs: 1. On target branch to get the baseline 2. On feature branch against the baseline to get the diff just for the PR As everything lives in one repo, I think it should be quick enough
b
Thanks, Vadim. I’ll give that a try.
b
Let me know how this goes, maybe it needs tuning 🙂
w
@big-pencil-62615 just FYI that when you use a config file, the Infracost GitHub App only runs changed projects (taking into account the dependency_paths too). But if you see it’s still slow, let us know so we can investigate.
b
I think Luis is using Atlantis. But if they add a GitHub app integration, the process might be smoother 🙂
w
Yeah that’s what I’d recommend, use the free GitHub App integration so you don’t have to keep updating the CLI version in the Atlantis image or worry about backward compatibility
b
Hello guys; thanks for the feedback — I’m still working on translating our Terraform git structure to an infracost.yml config file, but I’m getting closer 🙂
So I’m bumping into an issue. When I run infracost locally using a config file generated from a template, it traverses our terraform directory fine, and it is able to calculate the overall cost, but then If I upload that same configuration file to the repository settings page as the default, it fails, and the infracost GitHub plugin stops working. The same thing happens if I commit the file to the repository. Attached is the config file, which works locally but not when set as the config file on the console’s repo settings page. Any Idea what I’m doing wrong?
w
@big-pencil-62615 it’s easier to debug this over a quick screenshare 🙂 I just DM’d you a link so we can schedule it