hashicorp / terraform-plugin-framework

A next-generation framework for building Terraform providers.
https://developer.hashicorp.com/terraform/plugin/framework
Mozilla Public License 2.0
304 stars 93 forks source link

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

Open avinashpancham opened 11 months ago

avinashpancham commented 11 months ago

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

TheNilesh commented 7 months ago