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

able-raincoat-53539

11/09/2023, 8:57 AM
<!here> Hello everyone, I'm seeking assistance in crafting an Infracost config file that aligns with my Terraform directory structure, as shown below. Any guidance or suggestions would be greatly appreciated.
Copy code
├── envs
│   └── stage
│       └── project-stage
│           ├── service
│           │   ├── <http://backend.tf|backend.tf>
│           │   ├── <http://main.tf|main.tf>
│           │   ├── <http://providers.tf|providers.tf>
│           │   ├── terraform.tfvars
│           │   ├── <http://variables.tf|variables.tf>
│           │   └── <http://vpc.tf|vpc.tf>
│           ├── postgresql
│           │   ├── <http://backend.tf|backend.tf>
│           │   ├── <http://main.tf|main.tf>
│           │   ├── <http://providers.tf|providers.tf>
│           │   ├── terraform.tfvars
│           │   └── <http://variables.tf|variables.tf>
│           ├── redis
│           │   ├── <http://backend.tf|backend.tf>
│           │   ├── <http://main.tf|main.tf>
│           │   ├── <http://providers.tf|providers.tf>
│           │   ├── terraform.tfvars
│           │   └── <http://variables.tf|variables.tf>
│           └── testing-machine
│               ├── <http://backend.tf|backend.tf>
│               ├── <http://main.tf|main.tf>
│               ├── <http://providers.tf|providers.tf>
│               ├── terraform.tfvars
│               └── <http://variables.tf|variables.tf>
├── modules
   ├── bucket
   │   ├── <http://main.tf|main.tf>
   │   └── <http://variables.tf|variables.tf>
   ├── cloud_sql
   │   ├── <http://main.tf|main.tf>
   │   ├── <http://outputs.tf|outputs.tf>
   │   └── <http://variables.tf|variables.tf>
   ├── compute_engine
   │   ├── <http://main.tf|main.tf>
   │   ├── <http://outputs.tf|outputs.tf>
   │   └── <http://variables.tf|variables.tf>
   ├── secrets
   │   ├── <http://main.tf|main.tf>
   │   └── <http://variables.tf|variables.tf>
   └── vpc
       ├── <http://main.tf|main.tf>
       ├── <http://outputs.tf|outputs.tf>
       └── <http://variables.tf|variables.tf>
l

little-author-61621

11/09/2023, 11:03 AM
@able-raincoat-53539 something like this might work:
Copy code
version: 0.1
projects:
{{- range $project := matchPaths "envs/:env/:stage/:service" }}
  name: {{ $project.env }}-{{ $project.stage }}-{{ $project.service }}
  path: {{ $project._path }}
  terraform_var_files:
    - terraform.tfvars
{{- end }}
Let me know what you think.
(side note: please don’t use
@here
on this channel. It will notify 480 people)
a

able-raincoat-53539

11/09/2023, 11:05 AM
Thanks, @little-author-61621 will check. sorry will not use it😅
@little-author-61621 from the above-mentioned structure when I run infracost breakdown & diff on my master branch and PR branch on the service level eg.
envs/stage/project-stage/service
it doesn't show any diff. But if I run it on path
envs/stage/project-stage
it shows proper diff on all services including the
service
, do you have any idea what I am missing. can you help me with this pls.
l

little-author-61621

11/09/2023, 11:26 AM
How are you running infracost?
a

able-raincoat-53539

11/09/2023, 1:19 PM
In cli
l

little-author-61621

11/09/2023, 3:33 PM
What commands are you running?
a

able-raincoat-53539

11/09/2023, 5:29 PM
@little-author-61621 This will be executed on base branch
Copy code
infracost breakdown --path=/tmp/base/envs/stage/project-stage --format=json --out-file=infracost-base.json
This will be executed on the PR branch
Copy code
infracost diff --path=/envs/stage/project-stage --compare-to=infracost-base.json --format=json --out-file=infracost.json
Finally to post it to the comment
Copy code
infracost comment bitbucket --path=infracost.json --repo=$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG --pull-request=$BITBUCKET_PR_ID --bitbucket-token=$BITBUCKET_TOKEN --behavior=update
l

little-author-61621

11/09/2023, 9:26 PM
@able-raincoat-53539 I’m not seeing anything obvious from that that will be causing it, sorry. When you run the diff are you always using the equivalent path as the breakdown?
2 Views