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

Describe how to use resource plan modification for a resource that cannot be updated #880

Open
avinashpancham opened this issue Nov 27, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@avinashpancham
Copy link

Module version

1.4.2

Use-cases

For resources that have no update functionality rather than adding the resource.RequiresReplace() attribute plan modifier in the schema, you would like to use resource plan modification. Based on the documentation it is, however, not clear for first-time Terraform plugin developers how to achieve this.

Attempted Solutions

func (r * ThingResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {

	var state ThingResourceceModel
	readDiags := req.State.Get(ctx, &state)
	resp.Diagnostics.Append(readDiags...)

	if resp.Diagnostics.HasError() {
		return
	}
        resp.RequiresReplace(path.Paths{path.Root("field?")})

Proposal

Would it be possible to explain how to achieve this? If I know this then I dont mind extending the docs on for example the update resource page

References

@avinashpancham avinashpancham added the enhancement New feature or request label Nov 27, 2023
@TheNilesh
Copy link

TheNilesh commented Mar 28, 2024

  • Use data sources if you wish to restrict the practitioner from modifying any attributes.
  • For attributes that cannot be set or updated, mark them as read-only with Computed=true and Optional=false.
  • If modifying an attribute requires resource recreation, use RequiresReplace().
  • To fail the apply operation when someone attempts to modify a specific attribute's value, you must write your own plan modifier. Refer to Creating Attribute Plan Modifiers for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants