Description
Module version
github.com/hashicorp/terraform-plugin-framework v1.14.1
Use-cases
Support converting tftypes.AttributePath to path.Path
.
Attempted Solutions
Copy the code and modify the schema interface: func AttributePath(ctx context.Context, tfType *tftypes.AttributePath, schema TPFSchema) (path.Path, diag.Diagnostics) {.
Allthough this workaround works, we rather have access directly to the method instead of having to update a THIRD PARTY NOTICES
file and maintain this extra file.
Proposal
Expose the func AttributePath(ctx context.Context, tfType *tftypes.AttributePath, schema fwschema.Schema) (path.Path, diag.Diagnostics) { or a simplified version that converts tftypes.AttributePath
to path.Path
.
References
More Background Context
We are trying to reduce the verbosity users get in the plan diff.
For some attributes we cannot use the UseStateForUnknown
plan modifier directly. We need extra logic to say: Only use state when related attributes are unchanged.
Therefore, in our plan modifier logic we use the Diff
method on tfsdk.State.Raw
to find changes between the state and plan.
func NewPlanModifyDiffer(ctx context.Context, state *tfsdk.State, plan *tfsdk.Plan, diags *diag.Diagnostics, schema conversion.TPFSchema) *PlanModifyDiffer {
diffStatePlan, err := state.Raw.Diff(plan.Raw) // returns []tftypes.ValueDiff, error
The response from this diff is a []tftypes.ValueDiff
:
type ValueDiff struct {
Path *AttributePath // need to convert this to path.Path
Value1 *Value
Value2 *Value
}
We are later using these diffs to find AttributeChanges
which we query to find changed attributes and based on logic we replace the Unknown value with the state value (example).
For any operation on the plan we want to use the tfsdk.Plan
methods that requires a path.Path
(2nd argument):
func (p Plan) GetAttribute(ctx context.Context, path path.Path, target interface{})
func (p *Plan) SetAttribute(ctx context.Context, path path.Path, val interface{}) diag.Diagnostics