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

Consider Adding Attribute State Copying Plan Modifiers #180

Closed
bflad opened this issue Sep 24, 2021 · 2 comments · Fixed by #204
Closed

Consider Adding Attribute State Copying Plan Modifiers #180

bflad opened this issue Sep 24, 2021 · 2 comments · Fixed by #204
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@bflad
Copy link
Contributor

bflad commented Sep 24, 2021

Module version

v0.4.0

Use-cases

Due to the proposed behavior changes of #175, it is likely that an upcoming version of the framework will begin marking all Computed-only attributes as unknown in plans. The side effect is that provider developers may explicitly know that the attribute's state value should be copied to the plan as it is expected to not change during update (and therefore be hidden from plan output).

Attempted Solutions

Provider developers are able to manually create plan modifiers which copy the prior state value into the plan.

Proposal

This is likely to be a common use case for providers to improve plan outputs. The framework should likely provide two helper plan modifiers for this case:

  • Always copy known state value to plan for the attribute (attribute is never expected to change after creation)
  • Conditionally copy known state value to plan for the attribute (attribute may change due to other updates)

These likely would live in the tfsdk package, similar to RequiresReplace and RequiresReplaceIf

References

@bflad bflad added the enhancement New feature or request label Sep 24, 2021
@kmoe kmoe modified the milestone: v0.4.1 Sep 27, 2021
@bflad bflad added this to the v0.4.2 milestone Sep 27, 2021
@kmoe kmoe self-assigned this Sep 27, 2021
@bflad bflad modified the milestones: v0.4.2, v0.5.0 Sep 29, 2021
@bflad
Copy link
Contributor Author

bflad commented Oct 1, 2021

I was helping a colleague write one of these for their provider today and here is an example implementation:

type ComputedValueDoesNotChangeModifier struct {}

func (m ComputedValueDoesNotChangeModifier) Description(ctx context.Context) string {
	return "Value does not change after creation."
}

func (m ComputedValueDoesNotChangeModifier) MarkdownDescription(ctx context.Context) string {
	return m.Description()
}

func (m ComputedValueDoesNotChangeModifier) Modify(ctx context.Context, req tfsdk.ModifyAttributePlanRequest, resp *tfsdk.ModifyAttributePlanResponse) {
	// Do nothing for Create. It will automatically be marked as unknown.
	if req.AttributeState == nil || req.AttributeState.IsNull() {
		return
	}

	resp.AttributePlan = req.AttributeState
}

@github-actions
Copy link

github-actions bot commented Dec 4, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, 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 Dec 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants