hashicorp / hashicorp/terraform-plugin-framework
Plan Modifier `UseStateForUnknownIf`
- Dominant language
- Go
- Stars
- 384
- Forks
- 107
- Avg merge
- 3m
- Merged PRs (30d)
- 1
Description
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(...)`](https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification#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.
```go
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) {
// ...
},
),,
},
},
},
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.