Skip to content

Commit 5fdd181

Browse files
committed
Rebase.
Rebased on top of paddy_toterraformvalue branch so we can get rid of our helper.
1 parent 6f7a5dd commit 5fdd181

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

attr/value.go

-12
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,3 @@ type Value interface {
2121
// to the Value passed as an argument.
2222
Equal(Value) bool
2323
}
24-
25-
func ValueToTerraform(ctx context.Context, val Value) (tftypes.Value, error) {
26-
raw, err := val.ToTerraformValue(ctx)
27-
if err != nil {
28-
return tftypes.Value{}, err
29-
}
30-
err = tftypes.ValidateValue(val.Type(ctx).TerraformType(ctx), raw)
31-
if err != nil {
32-
return tftypes.Value{}, err
33-
}
34-
return tftypes.NewValue(val.Type(ctx).TerraformType(ctx), raw), nil
35-
}

tfsdk/type_plan_modification.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func runTypePlanModifiers(ctx context.Context, state, plan tftypes.Value, schema
5656
if resp.Diagnostics.HasError() {
5757
return plan, false
5858
}
59-
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
59+
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
6060
if err != nil {
6161
resp.Diagnostics.AddError(
6262
"Error converting value",
@@ -126,7 +126,7 @@ func attributeTypeModifyPlanObject(ctx context.Context, typ attr.Type, state, pl
126126
if diags.HasError() {
127127
return plan, diags
128128
}
129-
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
129+
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
130130
if err != nil {
131131
diags.AddAttributeError(path, "Error generating plan",
132132
fmt.Sprintf("An unexpected error was encountered while trying to generate the plan. Please report the following to the provider developer:\n\nCouldn't convert the attr.Value at %s back to a tftypes.Value: %s", path.WithAttributeName(attrName), err),
@@ -177,7 +177,7 @@ func attributeTypeModifyPlanMap(ctx context.Context, typ attr.Type, state, plan
177177
if diags.HasError() {
178178
return plan, diags
179179
}
180-
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
180+
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
181181
if err != nil {
182182
diags.AddAttributeError(path, "Error generating plan",
183183
fmt.Sprintf("An unexpected error was encountered while trying to generate the plan. Please report the following to the provider developer:\n\nCouldn't convert the attr.Value at %s back to a tftypes.Value: %s", path.WithElementKeyString(key), err),
@@ -228,7 +228,7 @@ func attributeTypeModifyPlanList(ctx context.Context, typ attr.Type, state, plan
228228
if diags.HasError() {
229229
return plan, diags
230230
}
231-
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
231+
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
232232
if err != nil {
233233
diags.AddAttributeError(path, "Error generating plan",
234234
fmt.Sprintf("An unexpected error was encountered while trying to generate the plan. Please report the following to the provider developer:\n\nCouldn't convert the attr.Value at %s back to a tftypes.Value: %s", path.WithElementKeyInt(index), err),
@@ -289,7 +289,7 @@ func attributeTypeModifyPlanTuple(ctx context.Context, typ attr.Type, state, pla
289289
if diags.HasError() {
290290
return plan, diags
291291
}
292-
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
292+
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
293293
if err != nil {
294294
diags.AddAttributeError(path, "Error generating plan",
295295
fmt.Sprintf("An unexpected error was encountered while trying to generate the plan. Please report the following to the provider developer:\n\nCouldn't convert the attr.Value at %s back to a tftypes.Value: %s", path.WithElementKeyInt(index), err),

0 commit comments

Comments
 (0)