Skip to content

Write only PlanModifier RequiresReplace is never executed #1226

@yottta

Description

@yottta

Module version

github.com/hashicorp/terraform-plugin-framework v1.16.0

Relevant provider source code

    resp.Schema = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"secret_string": schema.StringAttribute{
				Optional:      true,
				WriteOnly:     true,
				PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
			},
		},
	}

Terraform Configuration Files

terraform {
  required_providers {
    provs = {
      source = "edu/provs"
    }
  }
}

provider "provs" {
  path = "/var/tmp/custom_tf_provider"
}

resource "provs_secret" "test" {
  description = "test secret"
  secret_string = "val"
}

Expected Behavior

To satisfy this specification from the docs:
Image

Actual Behavior

When PlanModifiers are specified for write only attributes, even if there is a configuration for the attribute, the replace of the resource does not happen which contradicts with the public docs.

Steps to Reproduce

Provider setup

  1. Clone the testing provider from here.
  2. Run go run ./... -debug=true
  3. Save the returned TF_REATTACH_PROVIDERS to use it later

Configuration setup

With the configuration shared above, do the following:

  1. Run TF_REATTACH_PROVIDERS='...' terraform apply (to create the resource)
  2. Run TF_REATTACH_PROVIDERS='...' terraform apply (to see if the replace is executed which it is not)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions