-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Validate identity in import response #36893
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
Conversation
| } | ||
|
|
||
| // Providers are supposed to return an identity when importing by identity | ||
| if importTarget.Type().IsObjectType() && imported[0].Identity.IsNull() { |
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 dipping my toe into Resource Identity stuff as this PR looked manageable for a newbie.
At this point could the importType still be either "ID" or "Identity"? If Terraform was trying to import by ID, would the identity being null still be a problem 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.
Basically I'm wondering if the condition also needs importType == "Identity" in it
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're doing the same check (importTarget.Type().IsObjectType()) further up to set the value of importType.
So checking importType == "Identity" is equal to checking importTarget.Type().IsObjectType()
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.
Ah yes I understand now, thanks! 😅
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.
Do you think changing importTarget.Type().IsObjectType() to importType == "Identity" would make it more readable in this case?
The sprinkled .IsObjectType() checks trough the codebase feel a bit odd to me
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.
As someone less familiar with the code I think it'd be clearer if there was something more explicit like importType used in conditional logic, versus the implicit meaning of having object-type or string data as the target.
Maybe the strings "ID" and "Identity" could be made into constants to help with any comparison expressions
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 not sure what would be more descriptive if you're unfamiliar with the code. The prior knowledge of knowing the difference in usage of a string vs an object isn't far from knowing the difference between ID and Identity. I'd rather not have multiple fields that need to be updated in concert, since that invites them to end up out of sync, so the other option would probably be a struct containing an enum of the possible types, providing a type declaration with appropriate comments. We already have an ImportTarget type which could be used, though that might have been dropped because it makes some other part of the expansion code simpler.
7d71ed5 to
3427d3c
Compare
|
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 contributions. |
This PR adds a check to ensure that the import RPC returns an identity when Terraform is doing an import by identity.
Target Release
1.12.x
CHANGELOG entry