<!here> Hello everyone, I'm seeking assistance in ...
# help
a
<!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
@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
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
How are you running infracost?
a
In cli
l
What commands are you running?
a
@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
@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?