Skip to content

feat: terraform variables added to input #165

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

Merged
merged 5 commits into from
Jul 14, 2025
Merged

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Jul 9, 2025

Input can override template vars, implementing the equivalent of '-var' in terraform.

To make this work, the *.tfvar files have to be manually parsed. Trivy takes either a set of variable values XOR a set of tfvar files. This code reads the variable values from the files, then overrides with any user supplied values.

Input can override template vars, implementing the equivalent
of '-var' in terraform.
@Emyrk Emyrk force-pushed the stevenmasley/template_vars branch from aa4c103 to b1e7015 Compare July 9, 2025 15:34
@Emyrk Emyrk changed the title feat: template variables added to input feat: terraform variables added to input Jul 9, 2025
@Emyrk Emyrk requested a review from aslilac July 9, 2025 16:05
Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems sensible!

tfvars/load.go Outdated
Comment on lines 49 to 63
// Intentionally commented out to avoid loading from host environment
//
//for _, env := range os.Environ() {
// split := strings.Split(env, "=")
// key := split[0]
// if !strings.HasPrefix(key, "TF_VAR_") {
// continue
// }
// key = strings.TrimPrefix(key, "TF_VAR_")
// var val string
// if len(split) > 1 {
// val = split[1]
// }
// combinedVars[key] = cty.StringVal(val)
//}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. feels a bit weird to leave this code, but it is also nice to have the comment noting that it's explicitly not a desired behavior.

maybe we leave the comment but remove the actual code? it's not a big deal either way tho

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I was a bit unsure. If someone was to reference the original source, they might assume this piece of code was accidentally omitted, or should be added.

I'll remove the code, and just add in a longer comment to describe it better.

@Emyrk Emyrk merged commit ce03bce into main Jul 14, 2025
3 checks passed
@Emyrk Emyrk deleted the stevenmasley/template_vars branch July 14, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants