Title
#general
p

Paulo Correia

09/27/2022, 10:32 AM
Hi everyone, Before I jump into opening an issue, I will run a case trough you guys. I'm running infracost against some resources that use for_each, meaning, they're indexed by a string. like
azurerm_storage_account.hat_test_reports[\"uksouth\"]
What I'm seeing when running breakdown is something like this:
time="2022-09-27T11:24:39+01:00" level=warning msg="Using eastus for resource azurerm_storage_account.hat_function_app[\"ukwest\"] as its 'location' property could not be found."
time="2022-09-27T11:24:39+01:00" level=warning msg="Skipping resource azurerm_storage_account.hat_function_app[\"ukwest\"]. Infracost only supports StorageV2, BlockBlobStorage and FileStorage account kinds"
For the first message, location is there as it's mandatory by terraform for the second message, it's a StorageV2 😮 code in screenshot Worth opening an issue? Running on last infracost version Terraform Core 1.2.9
Alistair (Infracost)

Alistair (Infracost)

09/27/2022, 10:35 AM
Hi @Paulo Correia. Looking at the code I'm seeing you're using a data resource to retrieve the location. Unfortunately our HCL parsing can't evaluate data resources since they require communicating with the cloud APIs. One thing to try is to generate a plan JSON file and pass that as the
path
to infracost.
p

Paulo Correia

09/27/2022, 10:36 AM
Yep that would work, and hat it
10:37 AM
but doing that will prevent me from having the costs for all 3 environments and can also lead to remote state file locking when running in the pipeline while devs are testing as well
10:37 AM
got your point...
10:37 AM
what about the second message?
10:38 AM
it's a storage v2, but it's not able to get it
10:38 AM
Hmm just saw it
Alistair (Infracost)

Alistair (Infracost)

09/27/2022, 10:38 AM
The storage one looks like a bug. It looks like passing
Storage
as the attribute value now uses v2 by default so we need to update this in Infracost.
p

Paulo Correia

09/27/2022, 10:39 AM
it's not setup as storage
10:39 AM
apologies my fault 😐
Alistair (Infracost)

Alistair (Infracost)

09/27/2022, 10:39 AM
Ah, ok. I'm seeing updates to the terraform docs for that so it looks like we should update something.
p

Paulo Correia

09/27/2022, 10:40 AM
I'll update it on my side to Storage V2
Alistair (Infracost)

Alistair (Infracost)

09/27/2022, 10:43 AM
We have this open discussion: https://github.com/infracost/infracost/issues/1796 I'm not sure the existing suggestions would help you're case since you're looping through regions, but if there's any ideas you have for what we could do then let us know on the issue.
p

Paulo Correia

09/27/2022, 10:46 AM
I see, I n my case regions are part of a config variables, a list of regions with properties, and terraform just iterates through them. The reason I'm not using these variables all over the place is to force a correct dependency tree between resources, and hopefully terraform is able to follow that chain, we all know that terraform sometimes does nasty things with dependencies
10:48 AM
well for a quick win, in absence of a better way to solve this, having the regions present in usage-file would work for me! That or... using special comments in terraform code dedicated to infracost
10:48 AM
kind of code annotations
10:55 AM
I've added my suggestions, thanks
Alistair (Infracost)

Alistair (Infracost)

09/27/2022, 11:03 AM
Awesome thanks 🙏. Yeah annotations is a good idea.
p

Paulo Correia

09/27/2022, 11:04 AM
yep java and c# use them and it would not interfere at all with terraform way of working
Ali (Infracost)

Ali (Infracost)

09/27/2022, 4:14 PM
@Paulo Correia I saw your GH comment too, just to be clear the region override would need to be per-resource in the usage-file, right?
p

Paulo Correia

09/27/2022, 4:17 PM
in my case, yep, but we could have kind of a parent region at top level of the config, allowing to be overridden at lower levels per resource
Ali (Infracost)

Ali (Infracost)

09/27/2022, 4:25 PM
Makes sense - thanks! We’ll see when we get time to work on that, we’re open to receiving community contributions on it too in case people have time to help