-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: dereference variables from terraform.tfvars and *.auto.tfvars [CFG-1502] #12
Conversation
terraform/utils.go
Outdated
return false | ||
} | ||
|
||
func orderFilesByPriority(fileNames []string) []string { |
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.
Nothing wrong with the current function but I do want to share another idea about how to implement it and discuss it.
It looks like we are going to end up with a bunch of loops and each loop will contain its own unique logic for the specific file type that we are looking for, what if instead of that we will do something like the following:
1. Separately create a new enum that will contain the file type and its priority (e.g. .tf = 1)
2. Sort the files in lexical order
3. Iterate through the files and attach to each one of them its priority based on the file name
4. Sort the files by the priority while keeping the lexical order
5. Return the sorted list
This way when we would like to add support for a new file type we will only need to add its priority to the enum.
WDYT?
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'll give it a go and see how readable it is, thanks! 👍
c9d0686
to
8070daa
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.
Other than the feedback I left below you did excellent job! 🎉
Thank you for working it, it's very exciting to see the progress we are making with this 😃
8070daa
to
1b94b9c
Compare
This PR enables support for dereferencing variables defined in
terraform.tfvars
and*.auto.tfvars
. It does not aim to supportterraform.tfvars.json
and*.auto.tfvars.json
files, or files provided via the-var
and-var-file
flags. Tfvars files are explained hereIt keeps in mind variable definition precedences, as per this doc. So default variables can be overridden by
terraform.tfvars
variables, then by*.auto.tfvars
variables with the last file in alphabetical order overriding everything (if already defined).The
ParseModule
was modified so that files ending in.tf
and.tfvars
have variables extracted from them, then the precedence is dealt with when merging variables inmergeVariables
by ordering the file names based on priority. Then, we only parse.tf
files.Jira ticket: https://snyksec.atlassian.net/browse/CFG-1502