Hi, I was trying infracost breakdown on a pipeline...
# help
l
Hi, I was trying infracost breakdown on a pipeline. What I see is that, the total value gets changing randomly. I mean for the same set of files, once is is $770 and at another time it $1350 So since in Gitlab CI pipeline, if I run the runner multiple times, I get multiple results fluctuating between these. Has anyone else faced a similar situation. And I hitting a known pothole?
b
Hello! Are you able to share your TF code so we could reproduce it?
l
Will not be able to share the TF code. Posted the cost JSON files for the same resources across two runs with different cost estimates as private message
m
@lively-helicopter-12644 hey, I’m not sure if the is has been discussed by Vadim in you private chat, but could this be to do with un rebased changes in from your main to target branch? We’ve seen fluctuations like this before because of this. The other option is that internal bug with Infracost because of a case in your Terraform that we’re not handling correctly. In order to resolve issues like this it’s super helpful to have the underlying terraform code for the problematic resource (you can of course sanitize any sensitive values e.t.c). Otherwise it’s really very tricky for us to assist you.
b
From the provided files I found one price discrepancy for one resource, but the count of resources differs too. Looking into why
l
Thanks @mysterious-teacher-68276. re: Rebase: The fluctuation that I reported is not just on the working branch, but also on the fresh clone of master. re: TF code - I understand, however as you’d know there are quite a lot of controls over code. I will try my best, but highly unlikely.
m
If there is
count
logic and involved it’s probably likely that there’s a bug in the Terraform parsing our side, which again is incredibly tricky to resolve without the actual code. It could be as simple as doing the following for the problem resource:
Copy code
variable "change_my_name" {}

resource "aws_instance" "replace_the_name" {
    count = var.change_my_name
    
    # remove any attributes that we're not interested in 
    ...
}
this should be pretty safe from a sec ops point of view
b
Okay, I was incorrect, the prices are fine. But the counts are off for many resources
l
Seems for sure there is a bug with NAT Gateway count. Tried in another repo as well. Same issue
m
are you fetching this count from a data block?
l
Yes -
data.aws_availability_zones.available.names
For the previously discussed subnet, now NAT gateways etc., we are using the count of availability zones.
m
ok so this is an issue with how we mock the list that’s returned from that data block then. Infracost doesn’t use credentials to talk to AWS so it has no way to fetch the information from a data block. We thus mock the data, which in your case seems to be fluctuating with each run.
l
Ah makes sense. However for this specific case, isn’t it worth to keep a count of AZs per region instead of a blunt mock? Static values will return better than random values in this case.
m
for sure, but our mocking at this point in time is quite naive - so we don’t have many specific mock overrides defined for data blocks
l
Oh ok… FWIW, I looked through multiple large repos. The
data.aws_availability_zones
is the only one that required an accurate mock, as far as I see now. I am sure many use these for ensure all AZs in a given AWS region is covered.
Can you please point me to your code repo - I understand its opensource would love to have a look. Also, I know there is a pricing API server which can run locally, may be I would then try that and fiddle with it. Don’t know. But for now, this is a blocker to even add infracost to our CI system as a preview feature, since the costs go inconsistent.
Would trigger false alarm, especially if in case of a diff usecase.
cc: @busy-agent-35515 seems we can got to the root of it. It is the problem with the mock returning random values for ‘data.aws_availability_zones.available.names’
m
yep understood - the other option you have is to parse the Terraform plan JSON directly
this would sidestep the mock problem
as to the actual code change @lively-helicopter-12644 , I’d prefer that this is something we handle internally as the mocking logic and implementation is in flux
I’ll raise and issue and post here for you to track progress on it
l
Just thinking about using the plan json. However, that would mean, it would show only what is in the plan, meaning only resources that will be created. Not the entire project. So ya, one will get an estimate of cost of resources to be created as part of MR. But will not be able to see the overall cost or master and how much this MR is increasing.
Still a decent option
m
No I believe we will show you the entire project costs, just the diff on the resources changed as part of the plan
l
Cool, let me try