Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions castai/resource_commitments.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ func resourceCommitments() *schema.Resource {
Description: "Scaling strategy of the commitment in CAST AI. One of: Default, CPUBased, RamBased",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"Default", "CPUBased", "RamBased"}, false)),
},
"auto_assignment": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "If enabled, the commitment is automatically assigned to all clusters in the matching region. When disabled, only explicitly listed cluster assignments are used.",
},
}),
},
},
Expand Down
8 changes: 7 additions & 1 deletion castai/resource_commitments_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"strings"
"time"

"github.com/samber/lo"
"slices"

"github.com/samber/lo"

"github.com/castai/terraform-provider-castai/castai/reservations"
"github.com/castai/terraform-provider-castai/castai/sdk"
)
Expand Down Expand Up @@ -76,6 +77,7 @@ type (
AllowedUsage *float64 `mapstructure:"allowed_usage,omitempty"`
Assignments []*commitmentAssignmentResource `mapstructure:"assignments,omitempty"`
ScalingStrategy *string `mapstructure:"scaling_strategy,omitempty"`
AutoAssignment *bool `mapstructure:"auto_assignment,omitempty"`
}
commitmentConfigMatcherResource struct {
Name string `mapstructure:"name"`
Expand Down Expand Up @@ -511,6 +513,7 @@ func mapCommitmentImportWithConfigToUpdateRequest(
Prioritization: c.Commitment.Prioritization,
Status: c.Commitment.Status,
ScalingStrategy: c.Commitment.ScalingStrategy,
AutoAssignment: c.Commitment.AutoAssignment,
}
if c.Config != nil {
if c.Config.AllowedUsage != nil {
Expand All @@ -525,6 +528,9 @@ func mapCommitmentImportWithConfigToUpdateRequest(
if c.Config.ScalingStrategy != nil {
req.ScalingStrategy = (*sdk.CastaiInventoryV1beta1CommitmentScalingStrategy)(c.Config.ScalingStrategy)
}
if c.Config.AutoAssignment != nil {
req.AutoAssignment = c.Config.AutoAssignment
}
}
return req
}
Expand Down
12 changes: 8 additions & 4 deletions castai/resource_commitments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestCommitmentsResourceCreateAndUpdate(t *testing.T) {
commitmentImport: gcpImport,
expectCommitmentUpdate: sdk.CommitmentsAPIUpdateCommitmentJSONRequestBody{
AllowedUsage: lo.ToPtr[float32](0.6),
AutoAssignment: lo.ToPtr(true),
Prioritization: lo.ToPtr(true),
ScalingStrategy: lo.ToPtr(sdk.CPUBased),
Status: lo.ToPtr(sdk.CastaiInventoryV1beta1CommitmentStatusActive),
Expand Down Expand Up @@ -157,6 +158,7 @@ test,3b3de39c-bc44-4d69-be2d-69527dfe9958,630226bb-5170-4b95-90b0-f222757130c1,S
commitmentImport: commitmentImport,
expectCommitmentUpdate: sdk.CommitmentsAPIUpdateCommitmentJSONRequestBody{
AllowedUsage: lo.ToPtr[float32](0.7),
AutoAssignment: lo.ToPtr(true),
Prioritization: lo.ToPtr(true),
ScalingStrategy: lo.ToPtr(sdk.Default),
Status: lo.ToPtr(sdk.CastaiInventoryV1beta1CommitmentStatusActive),
Expand Down Expand Up @@ -363,10 +365,11 @@ test,3b3de39c-bc44-4d69-be2d-69527dfe9958,630226bb-5170-4b95-90b0-f222757130c1,S
"priority": 1,
},
},
"prioritization": true,
"status": "Active",
"allowed_usage": 0.7,
"scaling_strategy": "Default",
"prioritization": true,
"status": "Active",
"allowed_usage": 0.7,
"scaling_strategy": "Default",
"auto_assignment": false,
},
},
})
Expand Down Expand Up @@ -427,6 +430,7 @@ test,3b3de39c-bc44-4d69-be2d-69527dfe9958,630226bb-5170-4b95-90b0-f222757130c1,S
mockClient.EXPECT().CommitmentsAPIUpdateCommitmentWithResponse(
gomock.Any(), commitmentID.String(), sdk.CommitmentsAPIUpdateCommitmentJSONRequestBody{
AllowedUsage: lo.ToPtr[float32](0.7),
AutoAssignment: lo.ToPtr(false),
Prioritization: lo.ToPtr(true),
ScalingStrategy: lo.ToPtr(sdk.Default),
Status: lo.ToPtr(sdk.CastaiInventoryV1beta1CommitmentStatusActive),
Expand Down
1 change: 1 addition & 0 deletions docs/resources/commitments.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading