https://infracost.io logo
#help
Title
# help
h

hallowed-architect-17276

11/16/2023, 10:12 AM
Hi team. I'm after some help creating a config file to support a structure similar to below. These are the commands I'd use to run the config: terraform apply -var-file="config/global.tfvars" -var-file="config/azeun/dev/dev.tfvars" terraform apply -var-file="config/global.tfvars" -var-file="config/azeun/sbox/sbox.tfvars" Main.tf references remote modules e.g git::https://rhodri.visualstudio.com/demo1/_git/log-analytics?ref=1.0.0 ├── config │ ├── global.tfvars │ ├── azeun │ │ └── dev │ │ └── dev.tfvars │ │ └── sbox │ │ └── sbox.tfvars │ └── azeuw │ └── dev │ └── dev.tfvars ├── infracost.yml.tmpl └── main.tf
b

busy-agent-35515

11/16/2023, 5:45 PM
Hey Rhodri! Is it possible to share the TF code?
h

hallowed-architect-17276

11/17/2023, 9:45 AM
Hi @busy-agent-35515. Thanks for getting back to me. I created the template manually in the end, but would be good to understand what I was doing wrong. This is the repo https://dev.azure.com/rhod3rz01/Temp/_git/infracost
b

busy-agent-35515

11/17/2023, 9:52 AM
Thanks for the link! What's the final template you got? I can create my own and then we'll compare 🙂
h

hallowed-architect-17276

11/20/2023, 8:24 AM
Morning, this is the one I created manually ... https://dev.azure.com/rhod3rz01/Temp/_git/infracost?path=/infracost.yml
In terms of infracost.yml.tmpl, I didn't get this to work at all.
Hi @busy-agent-35515 ... any more thoughts on this please?
b

busy-agent-35515

11/21/2023, 4:25 PM
Hey! Sorry, I saw your message yesterday but haven't had time to tinker with the repo myself. I'll ping you when I have something
Copy code
version: 0.1
projects:
{{- range $project := matchPaths "config/:app/:env" }}
  - path: .
    name: {{ $<http://project.app|project.app> }}-{{ $project.env }}
    terraform_var_files:
      - config/{{ $<http://project.app|project.app> }}/{{ $project.env }}/{{ $project.env }}.tfvars

{{- end }}
Can you try this?
Noticed a typo in your config file on line 19 - for project
euw-dev
the path should be
config/euw...
h

hallowed-architect-17276

11/26/2023, 12:05 PM
Thanks @busy-agent-35515, but it's not working. I've used your .tmpl file with this command: infracost generate config --repo-path=. --template-path=infracost.yml.tmpl --out-file=infracost.yml but it just creates an empty file (with the exception of a couple of lines header). All here if you want to look. https://dev.azure.com/rhod3rz01/Temp/_git/infracost
b

busy-agent-35515

11/29/2023, 10:42 AM
@hallowed-architect-17276 Apologies, I again missed your message 😞 That's strange, I just ran the same command and it generated it fine. Here's the full listing of what I've done:
Copy code
❯ ls
config             infracost.yml.tmpl <http://main.tf|main.tf>
❯ cat infracost.yml.tmpl
version: 0.1
projects:
{{- range $project := matchPaths "config/:app/:env" }}
  - path: .
    name: {{ $<http://project.app|project.app> }}-{{ $project.env }}
    terraform_var_files:
      - config/{{ $<http://project.app|project.app> }}/{{ $project.env }}/{{ $project.env }}.tfvars

{{- end }}
❯ infracost generate config --repo-path=. --template-path=infracost.yml.tmpl --out-file=infracost.yml
❯ cat infracost.yml
version: 0.1
projects:
  - path: .
    name: eun-dev
    terraform_var_files:
      - config/eun/dev/dev.tfvars
  - path: .
    name: eun-prd
    terraform_var_files:
      - config/eun/prd/prd.tfvars
  - path: .
    name: euw-dev
    terraform_var_files:
      - config/euw/dev/dev.tfvars
  - path: .
    name: euw-prd
    terraform_var_files:
      - config/euw/prd/prd.tfvars
h

hallowed-architect-17276

12/03/2023, 12:43 PM
@busy-agent-35515 thanks for your help with this. I was running via windows/powershell and it just spits out an empty file. I saw you were using bash so ran via WSL, installed infracost and it worked fine 🙂
3 Views