Skip to content
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

helper/schema: Introduce ResourceData GetResourceId and SetResourceId receiver methods and only passthrough id attribute state if present #542

Closed
wants to merge 1 commit into from

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Aug 20, 2020

Closes #541

Implements proposal 1 from the issue. This goes through the process of deprecating the existing functionality to support potential longer term goals with the SDK (treating the id attribute` like all others), but if that is not warranted happy to change up the implementation here.

This allows resources to decouple from the implicit id attribute by only working with the underlying resource identifier (InstanceState.ID). Any id attribute handling is omitted from these new receiver methods. For reference, the existing Id() receiver method always read the id attribute as a fallback if the resource identifier was missing and SetId() always set the id attribute to match the resource identifier.

Also part of this support, the id attribute is no longer always "promoted" using the resource identifier if the attribute is missing when retrieving the state, however it is always passed through if present in the previous or new state. Existing logic using SetId() and the existing import functionality are unaffected as they continue to set the id attribute.

Current changes:

* helper/schema: Add `ResourceData` `GetResourceId()` and `SetResourceId()` receiver methods
* helper/schema: `ResourceData` `Id()` and `SetId()` receiver methods have been deprecated

Potential major version changes in the future relating to this:

* helper/schema: `ResourceData` `Id()` and `SetId()` receiver methods have been removed
* helper/schema: Importing resources no longer automatically sets the `id` attribute (use `d.Set("id", ...)` to match previous behavior)

… receiver methods and only passthrough id attribute state if present

Reference: hashicorp#541

This allows resources to decouple from the implicit `id` attribute by only working with the underlying resource identifier (`InstanceState.ID`). Any `id` attribute handling is omitted from these new receiver methods. For reference, the existing `Id()` receiver method always read the `id` attribute as a fallback if the resource identifier was missing and `SetId()` always set the `id` attribute to match the resource identifier.

Also part of this support, the `id` attribute is no longer always "promoted" using the resource identifier if the attribute is missing when retrieving the state, however it is always passed through if present in the previous or new state. Existing logic using `SetId()` and the existing import functionality are unaffected as they continue to set the `id` attribute.
@bflad
Copy link
Contributor Author

bflad commented Oct 14, 2021

Going to close this out -- I don't think we'll want to do this in this version of the framework and its not worth keeping it as an open pull request.

@bflad bflad closed this Oct 14, 2021
@bflad bflad deleted the f-ResourceData-SetResourceID branch October 14, 2021 21:27
@github-actions
Copy link

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to Get/Set Only the State Resource Identifier (Without id Attribute Handling)
1 participant