hashicorp / hashicorp/terraform-plugin-framework

Consider UnknownIf Attribute Plan Modifiers

Open
#605 0 comments 1 reaction 0 assignees View on GitHub
enhancement sdkv2-parity
Dominant language
Go
Stars
384
Forks
107
Avg merge
3m
Merged PRs (30d)
1

Description

### Module version

```
v1.0.1
```

### Use-cases

Providers coming from terraform-plugin-sdk may be looking for functionality similar to [`helper/customdiff.ComputedIf`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff#ComputedIf) (which itself was an actual implementation of [`helper/schema.Schema.ComputedWhen`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#Schema.ComputedWhen)). Its purpose was to set the plan value for the attribute as unknown if the given function returned true, which paired well with [`(schema.ResourceDiff).HasChanges()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#ResourceDiff.HasChanges).

In this terraform-plugin-sdk example, the `version` attribute value is set to unknown, if the `value` attribute is ever changed:

```go
customdiff.ComputedIf("version", func(_ context.Context, diff *schema.ResourceDiff, _ interface{}) bool {
return diff.HasChange("value")
}),
```

### Attempted Solutions

Providers would manually need to implement a similar attribute plan modifier or resource-level plan modification.

### Proposal

_To be filled in further_

Potentially introduce the following in each of the typed plan modifiers:

- `func UnknownIf(UnknownIfFunc) planmodifier.XXX`
- `func UnknownIfChanged(...path.Expression) planmodifier.XXX`

### References

- https://github.com/hashicorp/terraform-plugin-framework/issues/526

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.