-
Notifications
You must be signed in to change notification settings - Fork 14
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: add new option to template which populates variables from sourc… #393
Conversation
Type: schema.TypeList, | ||
Description: "a list of terraform variables extracted from the source code", | ||
Computed: true, | ||
Elem: &schema.Resource{ |
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 think these 3 will suffice.
Let me know if I should add any additional fields.
ReadContext: dataSourceCodeVariablesRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"template_id": { |
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'm assuming VCS is configured in a template (or environment with an implicit template).
Hopefully this assumption is correct.
return diag.Errorf("failed to extract variables from repository: %v", err) | ||
} | ||
|
||
if err := writeResourceDataSlice(variables, "variables", d); err != nil { |
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.
Some "magic" here.
Basically, this is a version of "writeResourceData" for slices.
env0/utils.go
Outdated
|
||
// Extracts values from a slice of interfaces, and writes it to resourcedata at name. | ||
func writeResourceDataSlice(i interface{}, name string, d *schema.ResourceData) error { | ||
writeResourceDataSliceStruct := func(val reflect.Value, value map[string]interface{}) { |
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 add supports structs within structs. Hopefully, this is enough to cover the vast majority of use cases.
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.
Didn't review all, but left some comments for now
c09311e
to
4646791
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.
Great work! ( like a pro )
Left some questions and I think you missed description
& is_sensitive
@liranfarage89 - Thank you for reviewing so far. let's put on hold the PR, I want to reduce the size so it will be easier to review. Will update you once it's ready for review again. |
89fc8d8
to
956631f
Compare
@@ -19,6 +19,10 @@ type CustomResourceDataField interface { | |||
WriteResourceData(fieldName string, d *schema.ResourceData) error | |||
} | |||
|
|||
type ResourceDataSliceStructValueWriter interface { |
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 interface is for custom writing.
see func (c *ConfigurationVariableSchema) ResourceDataSliceStructValueWrite(values map[string]interface{}) error {
Unit test is below.
107fc84
to
092c2e4
Compare
9d26103
to
9bf84cf
Compare
@liranfarage89 - you may continue reviewing. The PR size was reduced and updated the code based on your comments. |
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.
You rock 🎸 🚀 @TomerHeber 🙇
…e code
Issue & Steps to Reproduce / Feature Request
resolves #359
Solution
Some of the code was split to #410