-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing: add handling of unknown providers and empty terraform #55
Conversation
d456e9d
to
aea48c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the HCL case is not handled and that this is maybe not the best way to handle the case that we do not have 0.0.
There are 2 ways to do it:
- On the functions of the
cost.Plan
- Initialization of the Plan if the
prior
andplanned
are totally empty.
Or following what you did you could also add the if
onto the terraform.ExtractQueriesFromHCL
terraform/error.go
Outdated
ErrNoQueries = fmt.Errorf("no terraform entities found, looks empty") | ||
ErrNoKnownProvider = fmt.Errorf("terraform providers are not yet supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same but I would use error.New
as fmt.Errorf
is mainly used to create interpolation messages with %s
and so on.
terraform/hcl.go
Outdated
} | ||
|
||
// extractHCLModule returns the resources found in the provided module. | ||
func extractHCLModule(providers map[string]Provider, parser *configs.Parser, modPath string, modName string, mod *configs.Module, evalCtx *hcl.EvalContext) ([]query.Resource, error) { | ||
queries := make([]query.Resource, 0, len(mod.ManagedResources)) | ||
|
||
// knownProvider will remain false, until one resource from a | ||
// known provider is encountered. This allows to know if through | ||
// all the given resources some could be estimated or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's GH but I see a weird space on could be estimated or not
terraform/error.go
Outdated
|
||
// Errors that might be returned from procesing the HCL | ||
var ( | ||
ErrNoQueries = fmt.Errorf("no terraform entities found, looks empty") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Means empty or that we do not support any of the resources on the Plan/HCL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Means no queries were found - eg something generates a diff where there is nothing to process or contains no files.
Why? Both cases are tested on the PR though?
HCL doesn't contain prior and plan costs. Plus as we are speaking of plan, you could have some prior queries, but no new ones.
I'm not sure to follow your point there. |
I'm currently having issues with the pipeline to properly test it, so I'll remove the |
IDK why I did only see the
What I don't like about your solution is that it's the same logic in 2 places, and the Also as the query returns s |
Done, pipeline has been fixed too to work with the dump. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rs
2775c12
to
db5159d
Compare
Done |
estimation.go
Outdated
@@ -27,7 +27,7 @@ func EstimateTerraformPlan(ctx context.Context, backend Backend, plan io.Reader, | |||
} | |||
|
|||
priorQueries, err := tfplan.ExtractPriorQueries() | |||
if err != nil { | |||
if err != nil && err != terraform.ErrNoQueries { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, AFAIK this is needed in case there are no prior queries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the ExtractPriorQueries
doeds not return this error anymore, this was useful before but now it's not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, done
I've updated the Makefile/docker-compose file to ease the testing locally/in the CI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RS + merge
The testdata has been re-arranged to better reflect which providers where being tested; this allows to deal more easily with tests and the providers which are not yet supported. Some SQL dump of a previous ingestion has also been added to be able to test things locally more easily, it will be injected into the database whenever this one is started. The database can now be access via `make db-cli`
Instead of returning 0 as a cost estimated, Terracost will now return an error depending on the condition: no known providers were found, so it had no data to estimate it, or when a terraform module/files is empty and nothing could be extracted.
The known providers are now put into a separated files, which helps with adding new supported one to the default list.
a9b1203
to
dcca7a5
Compare
This PR adds the handling of unknown provider (eg. vmware) and also cases of empty terraform plan/module. That allows to give better output when the cost estimated is '0.0'. Now instead of having '0.0' an error will be returned.
In order to improve the testing, some pricing dump got also injected as part of it.
Related to: #21