Skip to content

Commit 391e050

Browse files
committed
REP-1293: corrects PR comments
1 parent e8af974 commit 391e050

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

castai/resource_allocation_group.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
210212
func 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

248237
func 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
}

castai/sdk/api.gen.go

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/resources/allocation_group.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)