broad-zoo-34077
12/19/2023, 5:31 PMlittle-author-61621
.DetectedProjects
variable coming soon that could help with this use case. It currently works with Infracost Cloud, but isn’t released in a CLI version yet. If you send me your full config file I can have a look and see if it would help.narrow-dinner-45042
12/19/2023, 6:28 PMprojects:
{{- range $project := matchPaths "deploy/terraform/:name(.*)" }}
{{- if isDir $project._path }}
{{- if pathExists $project._path "*.tf" }}
- path: {{ $project._path }}
name: {{ $project.name }}
{{- end}}
{{- end}}
{{- end }}
I was trying to match every directory in deploy/terraform
that contains a terraform file. Originally I did not have the pathExists
check, but that causes some errors because some directories are being matched that only contain subdirectories, no tf filesnarrow-dinner-45042
12/19/2023, 6:30 PMprojects:
{{- range $project := matchPaths "deploy/terraform/:name(.*)/:file.tf" }}
- path: {{ $project._dir }}
name: {{ $project.name }}
{{- end }}
but creates many duplicate projects since there are many directories with multiple files ending in .tf
. Perhaps thats fine, but was looking for a cleaner solution if possiblelittle-author-61621
version: 0.1
projects:
{{- range $project := .DetectedProjects }}
- path: {{ $project.Path }}
name: {{ $project.Name }}
{{- end }}
It will only work in Infracost Cloud and using the latest master build of Infracost though just now.narrow-dinner-45042
12/19/2023, 6:44 PMlittle-author-61621
little-author-61621
narrow-dinner-45042
12/19/2023, 6:44 PMnarrow-dinner-45042
12/19/2023, 10:28 PM.DetectedProjects
determine which paths are project and which arent? Ive noticed some paths not appearing in the infracost cloud repo view, but its unclear to me whylittle-author-61621
narrow-dinner-45042
12/20/2023, 8:19 PM.DetectedProjects
when the next CLI release comes out and provide additional feedback
# See <https://www.infracost.io/docs/features/config_file/>
version: 0.1
# We match every subdirectory within `deploy/terraform` that contains a *.tf file, excluding modules/
projects:
{{ $lastProject := "" }} # keep track of most recent project to avoid duplicate entries
{{- range $project := matchPaths "deploy/terraform/:subdir(.*)/:<http://file.tf|file.tf>" }}
{{- if not (startsWith $project.subdir "modules/") }}
{{- if ne $project.subdir $lastProject }}
{{ $lastProject = $project.subdir }}
- path: {{ $project._dir }}
name: {{ $project.subdir }}
{{- end}}
{{- end}}
{{- end }}