@@ -16,6 +16,25 @@ import (
1616 "github.com/hashicorp/terraform-plugin-framework/types"
1717)
1818
19+ func (plan * allocationGroupResourceModel ) getActions (ctx context.Context ) (actions map [string ]string , d diag.Diagnostics ) {
20+ actions = make (map [string ]string )
21+ var diags diag.Diagnostics
22+ if ! plan .Rules .IsNull () {
23+ planRules := []resource_allocation_group.RulesValue {}
24+ diags = plan .Rules .ElementsAs (ctx , & planRules , false )
25+ d .Append (diags ... )
26+ if d .HasError () {
27+ return
28+ }
29+ for i := range planRules {
30+ if ! planRules [i ].Id .IsNull () {
31+ actions [planRules [i ].Id .ValueString ()] = planRules [i ].Action .ValueString ()
32+ }
33+ }
34+ }
35+ return
36+ }
37+
1938func (plan * allocationGroupResourceModel ) toRequest (ctx context.Context ) (groupAllocationRequest models.GroupAllocationRequest , d diag.Diagnostics ) {
2039 var diags diag.Diagnostics
2140 groupAllocationRequest .UnallocatedCosts = plan .UnallocatedCosts .ValueStringPointer ()
@@ -67,7 +86,7 @@ func (plan *allocationGroupResourceModel) toRequest(ctx context.Context) (groupA
6786 return groupAllocationRequest , d
6887}
6988
70- func (state * allocationGroupResourceModel ) populate (groupAllocation * models.GroupAllocation , client * ClientTest , ctx context.Context ) (d diag.Diagnostics ) {
89+ func (state * allocationGroupResourceModel ) populate (groupAllocation * models.GroupAllocation , client * ClientTest , actions map [ string ] string , ctx context.Context ) (d diag.Diagnostics ) {
7190 var diags diag.Diagnostics
7291 state .Description = types .StringPointerValue (groupAllocation .Description )
7392 state .Id = types .StringPointerValue (groupAllocation .Id )
@@ -89,7 +108,17 @@ func (state *allocationGroupResourceModel) populate(groupAllocation *models.Grou
89108 Owner : types .StringPointerValue (rule .Owner ),
90109 RulesType : types .StringPointerValue (rule .Type ),
91110 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),
92115 }
116+ if rule .Id != nil {
117+ stateRule .Action = types .StringValue (actions [* rule .Id ])
118+ } else {
119+ stateRule .Action = types .StringValue ("create" )
120+ }
121+
93122 var singleAllocation * models.SingleAllocation
94123 singleAllocation , err := client .GetAllocation (stateRule .Id .ValueString ())
95124 if err != nil {
@@ -99,6 +128,9 @@ func (state *allocationGroupResourceModel) populate(groupAllocation *models.Grou
99128 )
100129 return
101130 }
131+ // This is an ugly hack because we have two different version of the ComponentsValue / ComponentsType and we need to convert between them
132+ // This would not be necessary if we could unify resource_allocation and resource_allocation_group but the generator cannot be used with the
133+ // "full" OpenAPI spec, so we have to split it
102134 singleAllocationState := allocationResourceModel {}
103135 diags = singleAllocationState .populate (singleAllocation , ctx )
104136 d .Append (diags ... )
@@ -138,7 +170,7 @@ func (state *allocationGroupResourceModel) populate(groupAllocation *models.Grou
138170 }
139171
140172 stateRules [i ], diags = resource_allocation_group .NewRulesValue (stateRule .AttributeTypes (ctx ), map [string ]attr.Value {
141- "action" : types . StringValue ( "select" ) ,
173+ "action" : stateRule . Action ,
142174 "allocation_type" : stateRule .AllocationType ,
143175 "components" : stateRule .Components ,
144176 "create_time" : stateRule .CreateTime ,
0 commit comments