Skip to content

Commit

Permalink
Rebase.
Browse files Browse the repository at this point in the history
Rebased on top of paddy_toterraformvalue branch so we can get rid of our
helper.
  • Loading branch information
paddycarver committed Dec 3, 2021
1 parent 6f7a5dd commit 5fdd181
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
12 changes: 0 additions & 12 deletions attr/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,3 @@ type Value interface {
// to the Value passed as an argument.
Equal(Value) bool
}

func ValueToTerraform(ctx context.Context, val Value) (tftypes.Value, error) {
raw, err := val.ToTerraformValue(ctx)
if err != nil {
return tftypes.Value{}, err
}
err = tftypes.ValidateValue(val.Type(ctx).TerraformType(ctx), raw)
if err != nil {
return tftypes.Value{}, err
}
return tftypes.NewValue(val.Type(ctx).TerraformType(ctx), raw), nil
}
10 changes: 5 additions & 5 deletions tfsdk/type_plan_modification.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func runTypePlanModifiers(ctx context.Context, state, plan tftypes.Value, schema
if resp.Diagnostics.HasError() {
return plan, false
}
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
if err != nil {
resp.Diagnostics.AddError(
"Error converting value",
Expand Down Expand Up @@ -126,7 +126,7 @@ func attributeTypeModifyPlanObject(ctx context.Context, typ attr.Type, state, pl
if diags.HasError() {
return plan, diags
}
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
if err != nil {
diags.AddAttributeError(path, "Error generating plan",
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),
Expand Down Expand Up @@ -177,7 +177,7 @@ func attributeTypeModifyPlanMap(ctx context.Context, typ attr.Type, state, plan
if diags.HasError() {
return plan, diags
}
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
if err != nil {
diags.AddAttributeError(path, "Error generating plan",
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),
Expand Down Expand Up @@ -228,7 +228,7 @@ func attributeTypeModifyPlanList(ctx context.Context, typ attr.Type, state, plan
if diags.HasError() {
return plan, diags
}
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
if err != nil {
diags.AddAttributeError(path, "Error generating plan",
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),
Expand Down Expand Up @@ -289,7 +289,7 @@ func attributeTypeModifyPlanTuple(ctx context.Context, typ attr.Type, state, pla
if diags.HasError() {
return plan, diags
}
rawNewPlan, err := attr.ValueToTerraform(ctx, newPlan)
rawNewPlan, err := newPlan.ToTerraformValue(ctx)
if err != nil {
diags.AddAttributeError(path, "Error generating plan",
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),
Expand Down

0 comments on commit 5fdd181

Please sign in to comment.