-
Notifications
You must be signed in to change notification settings - Fork 157
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 import resources with provider default tags #4169
Changes from 2 commits
276cafb
e573c99
0063967
18cc1c4
892e985
e24dbfa
7852b77
28ff3a5
9095918
6a9f36c
5f51229
54a9732
25b4b15
d4c01b7
185f434
e84e096
5fe2ef0
8c72e64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,40 @@ func applyTags( | |
} | ||
if allTags.IsNull() { | ||
delete(ret, "tags") | ||
delete(ret, "tagsAll") | ||
corymhall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ret, nil | ||
} | ||
ret["tags"] = allTags | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I was also confused here, I was expecting something like this:
Unfortunately it's more complicated than this as TransformOutputs hook is hiding some differences around the context this code is executing in. Let me add below. |
||
ret["tagsAll"] = allTags | ||
|
||
return ret, nil | ||
} | ||
|
||
// similar to applyTags, but applied to the `TransformOutputs` method that is run | ||
// during Read | ||
func applyTagsOutputs( | ||
ctx context.Context, config resource.PropertyMap, | ||
) (resource.PropertyMap, error) { | ||
ret := config.Copy() | ||
configTags := resource.NewObjectProperty(resource.PropertyMap{}) | ||
if t, ok := config["tags"]; ok { | ||
configTags = t | ||
} | ||
|
||
meta := resource.PropertyMap{} | ||
if at, ok := config["tagsAll"]; ok { | ||
meta["defaultTags"] = resource.NewObjectProperty(resource.PropertyMap{ | ||
"tags": at, | ||
}) | ||
} | ||
|
||
allTags, err := mergeTags(ctx, configTags, meta) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd appreciate a little bit of elaboration here on what we're trying to do, and how does it work, I see this: As written, I think if I recall what TransformOutputs is doing this will be assigning config to the tags and tagsAll coming out of the TF provider. This seems to then ignore the current defaultTags on the provider itself as it were. Why does this work? I thought perhaps we're not trusting the tags_all output from the provider internals, is it useful here? |
||
if err != nil { | ||
return nil, err | ||
} | ||
if allTags.IsNull() { | ||
delete(ret, "tags") | ||
delete(ret, "tagsAll") | ||
return ret, nil | ||
} | ||
ret["tags"] = allTags | ||
|
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.
Note that TransformOutputs affects Create and Update, not just read - is this intended 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.
It's a side effect, but as long as it is true that
tags
anddefaultTags
should always be equal then I think we are fine.