Skip to content

Commit dedb4c4

Browse files
committed
hopefully fix most perma-diff cases
1 parent 04bda77 commit dedb4c4

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

internal/provider/allocation_group.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func (plan *allocationGroupResourceModel) toRequest(ctx context.Context) (groupA
5757
Description: planRules[i].Description.ValueStringPointer(),
5858
Formula: planRules[i].Formula.ValueStringPointer(),
5959
}
60-
if !planRules[i].Components.IsNull() {
60+
// Don't send components if selecting existing allocation
61+
if !planRules[i].Components.IsNull() && planRules[i].Action.ValueString() != "select" {
6162
ruleComponents := []resource_allocation_group.ComponentsValue{}
6263
diags = planRules[i].Components.ElementsAs(ctx, &ruleComponents, true)
6364
d.Append(diags...)
@@ -73,10 +74,10 @@ func (plan *allocationGroupResourceModel) toRequest(ctx context.Context) (groupA
7374
Mode: models.AllocationComponentMode(ruleComponents[j].Mode.ValueString()),
7475
Type: models.DimensionsTypes(ruleComponents[j].ComponentsType.ValueString()),
7576
}
76-
values := make([]attr.Value, len(ruleComponents[j].Values.Elements()))
77-
for k := range ruleComponents[j].Values.Elements() {
78-
values[k] = ruleComponents[j].Values.Elements()[k]
79-
createComponents[j].Values[k] = values[k].String()
77+
diags := ruleComponents[j].Values.ElementsAs(ctx, &createComponents[j].Values, true)
78+
d.Append(diags...)
79+
if d.HasError() {
80+
return
8081
}
8182
}
8283
groupAllocationRequest.Rules[i].Components = &createComponents
@@ -108,15 +109,18 @@ func (state *allocationGroupResourceModel) populate(groupAllocation *models.Grou
108109
Owner: types.StringPointerValue(rule.Owner),
109110
RulesType: types.StringPointerValue(rule.Type),
110111
UpdateTime: types.Int64PointerValue(rule.UpdateTime),
111-
// Doesn't exist on the AllocationListItem data model
112-
// AllocationType: types.StringPointerValue(string(rule.AllocationType)),
113-
// Description: types.StringPointerValue(rule.Description),
114-
// UrlUi: types.StringPointerValue(rule.UrlUi),
112+
UrlUi: types.StringPointerValue(rule.UrlUI),
115113
}
114+
if rule.AllocationType != nil {
115+
stateRule.AllocationType = types.StringValue(string(*rule.AllocationType))
116+
}
117+
// if the ruleId is not in the map of actions, it has to be a new rule
116118
if rule.Id != nil {
117-
stateRule.Action = types.StringValue(actions[*rule.Id])
118-
} else {
119-
stateRule.Action = types.StringValue("create")
119+
action, ok := actions[*rule.Id]
120+
if !ok {
121+
action = "create"
122+
}
123+
stateRule.Action = types.StringValue(action)
120124
}
121125

122126
var singleAllocation *models.SingleAllocation
@@ -137,6 +141,11 @@ func (state *allocationGroupResourceModel) populate(groupAllocation *models.Grou
137141
if d.HasError() {
138142
return
139143
}
144+
stateRule.Description, diags = singleAllocationState.Description.ToStringValue(ctx)
145+
d.Append(diags...)
146+
if d.HasError() {
147+
return
148+
}
140149
stateRule.Formula, diags = singleAllocationState.Rule.Formula.ToStringValue(ctx)
141150
d.Append(diags...)
142151
if d.HasError() {
@@ -248,6 +257,9 @@ func (c *ClientTest) UpdateAllocationGroup(allocationID string, allocation model
248257
log.Println(req.URL)
249258
body, err := c.doRequest(req)
250259
if err != nil {
260+
fmt.Println("ERROR REQUEST----------------")
261+
fmt.Println(err)
262+
fmt.Println(string(rb))
251263
return nil, err
252264
}
253265

0 commit comments

Comments
 (0)