Skip to content

Consider UnknownIf Attribute Plan Modifiers #605

Open
@bflad

Description

@bflad

Module version

v1.0.1

Use-cases

Providers coming from terraform-plugin-sdk may be looking for functionality similar to helper/customdiff.ComputedIf (which itself was an actual implementation of 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().

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsdkv2-parityIssues tracking feature parity with terraform-plugin-sdk v2 and PRs working towards it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions