Skip to content

Plan Modifier UseStateForUnknownIf #1214

@zliang-akamai

Description

@zliang-akamai

Sometimes, the value of an attribute depends on whether another attribute's value is updated. It would be nice to have a UseStateForUnknownIf(...) function, similar to RequiresReplaceIf(...), to mark an attribute as unknown during an update operation if the attribute it depends on has been changed; otherwise, marking it as known.

func (r *MyResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
	resp.Schema = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"a": schema.StringAttribute{
				Required: true,
			},
			"b_depending_on_a": schema.StringAttribute{
				Optional: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknownIf(
						func(ctx context.Context, sr planmodifier.StringRequest, rrifr *stringplanmodifier.UseStateForUnknownIfFuncResponse) {
							// ...
						},
					),,
				},
			},
		},
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions