@@ -32,11 +32,12 @@ func resourceAllocationGroup() *schema.Resource {
3232 Description : "Allocation group name" ,
3333 },
3434 "cluster_ids" : {
35- Type : schema .TypeList ,
35+ Type : schema .TypeSet ,
3636 Required : true ,
3737 Description : "List of CAST AI cluster ids" ,
3838 Elem : & schema.Schema {
39- Type : schema .TypeString ,
39+ Type : schema .TypeString ,
40+ ValidateDiagFunc : validation .ToDiagFunc (validation .IsUUID ),
4041 },
4142 },
4243 "namespaces" : {
@@ -62,6 +63,7 @@ func resourceAllocationGroup() *schema.Resource {
6263 OR (default) - workload needs to have at least one label to be included
6364 AND - workload needs to have all the labels to be included` ,
6465 Optional : true ,
66+ Default : sdk .OR ,
6567 Elem : & schema.Schema {
6668 Type : schema .TypeString ,
6769 },
@@ -113,7 +115,7 @@ func resourceAllocationGroupRead(ctx context.Context, d *schema.ResourceData, me
113115 if err := d .Set ("name" , ag .Name ); err != nil {
114116 return diag .FromErr (fmt .Errorf ("setting name: %w" , err ))
115117 }
116- if err := d .Set ("cluster_ids" , ag .Filter .ClusterIds ); err != nil {
118+ if err := d .Set ("cluster_ids" , * ag .Filter .ClusterIds ); err != nil {
117119 return diag .FromErr (fmt .Errorf ("setting cluster_ids: %w" , err ))
118120 }
119121 if err := d .Set ("namespaces" , ag .Filter .Namespaces ); err != nil {
@@ -156,7 +158,7 @@ func resourceAllocationGroupCreate(ctx context.Context, d *schema.ResourceData,
156158 }
157159 create , err := client .AllocationGroupAPICreateAllocationGroupWithResponse (ctx , body )
158160 if err != nil {
159- return nil
161+ return diag . FromErr ( fmt . Errorf ( "error calling create allocation group: %w" , err ))
160162 }
161163 switch create .StatusCode () {
162164 case http .StatusOK :
@@ -210,19 +212,6 @@ func resourceAllocationGroupUpdate(ctx context.Context, d *schema.ResourceData,
210212func resourceAllocationGroupDelete (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
211213 client := meta .(* ProviderConfig ).api
212214
213- resp , err := client .AllocationGroupAPIGetAllocationGroupWithResponse (ctx , d .Id ())
214- if err != nil {
215- return diag .FromErr (err )
216- }
217-
218- if resp .StatusCode () == http .StatusNotFound {
219- tflog .Debug (ctx , "Allocation group not found, skipping delete" , map [string ]any {"id" : d .Id ()})
220- return nil
221- }
222- if err := sdk .StatusOk (resp ); err != nil {
223- return diag .FromErr (err )
224- }
225-
226215 response , err := client .AllocationGroupAPIDeleteAllocationGroupWithResponse (ctx , d .Id ())
227216 if err != nil {
228217 return diag .FromErr (err )
@@ -247,7 +236,7 @@ func toLabelsOperator(d *schema.ResourceData) *sdk.CostreportV1beta1FilterOperat
247236
248237func toClusterIds (d * schema.ResourceData ) []string {
249238 if v , ok := d .GetOk ("cluster_ids" ); ok {
250- if lv := v .([] interface {} ); len (lv ) > 0 {
239+ if lv := v .(* schema. Set ). List ( ); len (lv ) > 0 {
251240 return toStringList (lv )
252241 }
253242 }
0 commit comments