-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
fix source accessor to allow use in source block #11318
Conversation
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.
LGTM, I would maybe add a test for this one, to avoid regressions :)
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.
👍🏼
hcl2template/types.source.go
Outdated
ectx.Variables[sourcesAccessor] = cty.ObjectVal(map[string]cty.Value{ | ||
"type": cty.StringVal(source.Type), | ||
"name": cty.StringVal(source.Name), | ||
}) |
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.
The following will give the same result and if in the future we add a new attribute we will have to change only in one place.
ectx.Variables[sourcesAccessor] = cty.ObjectVal(map[string]cty.Value{ | |
"type": cty.StringVal(source.Type), | |
"name": cty.StringVal(source.Name), | |
}) | |
ectx.Variables[sourcesAccessor] = cty.ObjectVal(source.ctyValues()) |
The ctyValues
is also used here
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 cool! Thanks for sharing.
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.
Looks good to me. Also nice learning here on
ectx.Variables[sourcesAccessor] = cty.ObjectVal(source.ctyValues())
Added tests -- I'll merge when green |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Makes sure that the source name and type are part of the eval context for builds; this allows you to use source.type and source.
Test func:
Before:
After: