Skip to content

Commit 3be65d3

Browse files
author
Ivan De Marino
committed
Remove unnecessary conversion to tftypes in AttributePlanModifiers implementations
1 parent ee2fab0 commit 3be65d3

File tree

1 file changed

+7
-52
lines changed

1 file changed

+7
-52
lines changed

tfsdk/attribute_plan_modification.go

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,7 @@ func (r RequiresReplaceModifier) Modify(ctx context.Context, req ModifyAttribute
140140
return
141141
}
142142

143-
configRaw, err := req.AttributeConfig.ToTerraformValue(ctx)
144-
if err != nil {
145-
resp.Diagnostics.AddAttributeError(req.AttributePath,
146-
"Error converting config value",
147-
fmt.Sprintf("An unexpected error was encountered converting a %s to its equivalent Terraform representation. This is always a bug in the provider.\n\nError: %s", req.AttributeConfig.Type(ctx), err),
148-
)
149-
return
150-
}
151-
if configRaw.IsNull() && attrSchema.Computed {
143+
if req.AttributeConfig.IsNull() && attrSchema.Computed {
152144
// if the config is null and the attribute is computed, this
153145
// could be an out of band change, don't require replace
154146
return
@@ -280,15 +272,7 @@ func (r RequiresReplaceIfModifier) Modify(ctx context.Context, req ModifyAttribu
280272
return
281273
}
282274

283-
configRaw, err := req.AttributeConfig.ToTerraformValue(ctx)
284-
if err != nil {
285-
resp.Diagnostics.AddAttributeError(req.AttributePath,
286-
"Error converting config value",
287-
fmt.Sprintf("An unexpected error was encountered converting a %s to its equivalent Terraform representation. This is always a bug in the provider.\n\nError: %s", req.AttributeConfig.Type(ctx), err),
288-
)
289-
return
290-
}
291-
if configRaw.IsNull() && attrSchema.Computed {
275+
if req.AttributeConfig.IsNull() && attrSchema.Computed {
292276
// if the config is null and the attribute is computed, this
293277
// could be an out of band change, don't require replace
294278
return
@@ -345,47 +329,18 @@ func (r UseStateForUnknownModifier) Modify(ctx context.Context, req ModifyAttrib
345329
return
346330
}
347331

348-
val, err := req.AttributeState.ToTerraformValue(ctx)
349-
if err != nil {
350-
resp.Diagnostics.AddAttributeError(req.AttributePath,
351-
"Error converting state value",
352-
fmt.Sprintf("An unexpected error was encountered converting a %s to its equivalent Terraform representation. This is always a bug in the provider.\n\nError: %s", req.AttributeState.Type(ctx), err),
353-
)
354-
return
355-
}
356-
357332
// if we have no state value, there's nothing to preserve
358-
if val.IsNull() {
359-
return
360-
}
361-
362-
val, err = resp.AttributePlan.ToTerraformValue(ctx)
363-
if err != nil {
364-
resp.Diagnostics.AddAttributeError(req.AttributePath,
365-
"Error converting plan value",
366-
fmt.Sprintf("An unexpected error was encountered converting a %s to its equivalent Terraform representation. This is always a bug in the provider.\n\nError: %s", resp.AttributePlan.Type(ctx), err),
367-
)
333+
if req.AttributeState.IsNull() {
368334
return
369335
}
370336

371-
// if it's not planned to be the unknown value, stick with
372-
// the concrete plan
373-
if val.IsKnown() {
374-
return
375-
}
376-
377-
val, err = req.AttributeConfig.ToTerraformValue(ctx)
378-
if err != nil {
379-
resp.Diagnostics.AddAttributeError(req.AttributePath,
380-
"Error converting config value",
381-
fmt.Sprintf("An unexpected error was encountered converting a %s to its equivalent Terraform representation. This is always a bug in the provider.\n\nError: %s", req.AttributeConfig.Type(ctx), err),
382-
)
337+
// if it's not planned to be the unknown value, stick with the concrete plan
338+
if !resp.AttributePlan.IsUnknown() {
383339
return
384340
}
385341

386-
// if the config is the unknown value, use the unknown value
387-
// otherwise, interpolation gets messed up
388-
if !val.IsKnown() {
342+
// if the config is the unknown value, use the unknown value otherwise, interpolation gets messed up
343+
if req.AttributeConfig.IsUnknown() {
389344
return
390345
}
391346

0 commit comments

Comments
 (0)