Skip to content

Commit 79d46a1

Browse files
authored
Merge pull request #297 from hashicorp/bendbennett/issues-296
Remove unneeded code from plan modifier
2 parents 86d2361 + a869987 commit 79d46a1

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

internal/planmodifiers/attribute.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ type numberNumericAttributePlanModifier struct {
9595
}
9696

9797
func (d *numberNumericAttributePlanModifier) Description(ctx context.Context) string {
98-
return ""
98+
return "Ensures that number and numeric attributes are kept synchronised."
9999
}
100100

101101
func (d *numberNumericAttributePlanModifier) MarkdownDescription(ctx context.Context) string {
102-
return ""
102+
return d.Description(ctx)
103103
}
104104

105105
func (d *numberNumericAttributePlanModifier) Modify(ctx context.Context, req tfsdk.ModifyAttributePlanRequest, resp *tfsdk.ModifyAttributePlanResponse) {
@@ -111,7 +111,7 @@ func (d *numberNumericAttributePlanModifier) Modify(ctx context.Context, req tfs
111111
}
112112

113113
numericConfig := types.Bool{}
114-
req.Config.GetAttribute(ctx, path.Root("numeric"), &numericConfig)
114+
diags = req.Config.GetAttribute(ctx, path.Root("numeric"), &numericConfig)
115115
resp.Diagnostics.Append(diags...)
116116
if resp.Diagnostics.HasError() {
117117
return
@@ -125,35 +125,21 @@ func (d *numberNumericAttributePlanModifier) Modify(ctx context.Context, req tfs
125125
return
126126
}
127127

128-
numberPlan := types.Bool{}
129-
diags = req.Config.GetAttribute(ctx, path.Root("number"), &numberPlan)
130-
resp.Diagnostics.Append(diags...)
131-
if resp.Diagnostics.HasError() {
132-
return
133-
}
134-
135-
numericPlan := types.Bool{}
136-
req.Config.GetAttribute(ctx, path.Root("numeric"), &numericPlan)
137-
resp.Diagnostics.Append(diags...)
138-
if resp.Diagnostics.HasError() {
139-
return
140-
}
141-
142128
// Default to true for both number and numeric when both are null.
143-
if numberPlan.Null && numericPlan.Null {
129+
if numberConfig.Null && numericConfig.Null {
144130
resp.AttributePlan = types.Bool{Value: true}
145131
return
146132
}
147133

148134
// Default to using value for numeric if number is null
149-
if numberPlan.Null && !numericPlan.Null {
150-
resp.AttributePlan = numericPlan
135+
if numberConfig.Null && !numericConfig.Null {
136+
resp.AttributePlan = numericConfig
151137
return
152138
}
153139

154140
// Default to using value for number if numeric is null
155-
if !numberPlan.Null && numericPlan.Null {
156-
resp.AttributePlan = numberPlan
141+
if !numberConfig.Null && numericConfig.Null {
142+
resp.AttributePlan = numberConfig
157143
return
158144
}
159145
}

0 commit comments

Comments
 (0)