Title
#general
xuan duy dinh

xuan duy dinh

06/07/2022, 11:37 AM
Hi everyone, does anyone know how infracost add var file ?
Alistair (Infracost)

Alistair (Infracost)

06/07/2022, 11:39 AM
Hi, you should be able to pass a
--terraform-var-file=myvars.tfvar
flag to the
infracost breakdown
or
infracost diff
command. Does that work for you?
xuan duy dinh

xuan duy dinh

06/07/2022, 11:44 AM
thank you, how about I have multiple file
Alistair (Infracost)

Alistair (Infracost)

06/07/2022, 11:46 AM
You can repeat that flag, e.g.
infracost breakdown --path=. --terraform-var-file=myvars1.tfvar --terraform-var-file=myvars2.tfvar
xuan duy dinh

xuan duy dinh

06/07/2022, 11:47 AM
11:47 AM
I used infracost.yml
11:47 AM
infracost breakdown --config-file infracost.yml
11:47 AM
is my file correctly ?
Alistair (Infracost)

Alistair (Infracost)

06/07/2022, 11:47 AM
👍 looks like that should work
xuan duy dinh

xuan duy dinh

06/07/2022, 11:48 AM
11:48 AM
this is my project structure
11:49 AM
but it still does not recognize file
11:52 AM
Alistair (Infracost)

Alistair (Infracost)

06/07/2022, 11:52 AM
hmm, odd… are there any more details if you run with
--log-level=debug
?
xuan duy dinh

xuan duy dinh

06/07/2022, 11:59 AM
I saw it
12:00 PM
seem like it does not understand some git ssh module
12:01 PM
time="2022-06-07T18:57:34+07:00" level=warning parser=terraform_hcl msg="Failed to load module err: missing module with source 'registry.terraform.io/git@git.company.org:cost_be/terraform-core-modules/api-gateway.git?ref=1.0.2 git@git.company.org:cost_be/terraform-core-modules/api-gateway.git?ref=1.0.2' - try to 'terraform init' first" time="2022-06-07T18:57:34+07:00" level=warning parser=terraform_hcl msg="Failed to load module err: missing module with source 'registry.terraform.io/../cognito ../cognito' - try to 'terraform init' first"
Alistair (Infracost)

Alistair (Infracost)

06/07/2022, 12:03 PM
Thanks, that looks similar to the issue that was just reported here: https://github.com/infracost/infracost/issues/1730. We’ll try and get a patch in for the next version sometime this week. In the meantime you can run Infracost with the
--terraform-force-cli
flag as a workaround which runs it in the old way by calling out to the Terraform/Terragrunt binary.
xuan duy dinh

xuan duy dinh

06/07/2022, 12:04 PM
ah, my bad I searched but didn't find it
12:04 PM
thank you very much
Alistair (Infracost)

Alistair (Infracost)

06/07/2022, 12:04 PM
No worries, I’ll reach back out to you when the issue is fixed. Let me know if you have any more issues.
xuan duy dinh

xuan duy dinh

06/07/2022, 12:06 PM
I will 😄
Alistair (Infracost)

Alistair (Infracost)

06/07/2022, 1:18 PM
I’ve got a potential fix in https://github.com/infracost/infracost/pull/1731, but another workaround for just now might just be changing the
source
attribute in your HCL module block to match whatever Terraform has written out as the source for that module in the
.terraform/modules/modules.json
file.
xuan duy dinh

xuan duy dinh

06/07/2022, 2:28 PM
thank you, with flag --terraform-force-cli, I got the estimation of my project 😄
2:29 PM
currently my format for module git is "git@git.company.org:cost_be/terraform-core-modules/api-gateway.git"
2:29 PM
when I tried to change to "git::ssh://git@git.company.org:cost_be/terraform-core-modules/api-gateway.git"
2:29 PM
I got the error
2:30 PM
so I think it doesn't work for my case as well
Alistair (Infracost)

Alistair (Infracost)

06/07/2022, 2:59 PM
Interesting, what does your
.terraform/modules/modules.json
file show?