-
Notifications
You must be signed in to change notification settings - Fork 41
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
Do not map resources/datasources specified in IgnoreMappings #1840
Conversation
Fixes #1838 Previously, we applied (in bridge) automatic mapping to resources/datasources that didn't have an associated `Tok` field, even if they were included in `IgnoreMappings`. For providers that vendored resources from multiple prefixes, this caused a panic. The solution is to not provide a mapping for resources that are specified in `IngoreMappings`. This expands the scope of `IngoreMappings`, but does so in a way that I feel is more intuitive then it is now. I have adjusted the comment on `IgnoreMappings` to reflect it's new scope.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1840 +/- ##
==========================================
- Coverage 60.75% 60.28% -0.48%
==========================================
Files 303 310 +7
Lines 42377 42773 +396
==========================================
+ Hits 25747 25785 +38
- Misses 15157 15517 +360
+ Partials 1473 1471 -2 ☔ View full report in Codecov by Sentry. |
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, thanks for the tests.
Is it possible to surprise any provider authors with the new behaviour? Is it not possible now for some resource to go missing silently?
// Fetch a list of all resource types handled by this provider and make a map. | ||
p.resources = make(map[tokens.Type]Resource) | ||
p.tf.ResourcesMap().Range(func(name string, res shim.Resource) bool { | ||
schema, ok := p.info.Resources[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.
We checked for p.info.Resources == nil before - are you allowed to call [name] on a nil map?
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 are allowed to treat a nil map as indexable, if it is an rvalue:
x := mayBeNil[name] // This is ok, x is the zero value
mayBeNil[name] = x // This will panic
It is possible, but highly unlikely. This PR does change the runtime behavior of the provider (removing resources), but it doesn't change the tfgen time behavior. For this to break a provider in use, I believe that the provider's consumers would need to calling RegisterResource directly (instead of using a SDK). |
Fixes #1838
Previously, we applied (in bridge) automatic mapping to resources/datasources that didn't have an associated
Tok
field, even if they were included inIgnoreMappings
. For providers that vendored resources from multiple prefixes, this caused a panic.The solution is to not provide a mapping for resources that are specified in
IngoreMappings
. This expands the scope ofIngoreMappings
, but does so in a way that I feel is more intuitive then it is now. I have adjusted the comment onIgnoreMappings
to reflect it's new scope.