diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index 9405d526..fe7e997e 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -44,6 +44,7 @@ const ( FieldNodeTemplateMinMemory = "min_memory" FieldNodeTemplateName = "name" FieldNodeTemplateOnDemand = "on_demand" + FieldNodeTemplateOs = "os" FieldNodeTemplateRebalancingConfigMinNodes = "rebalancing_config_min_nodes" FieldNodeTemplateShouldTaint = "should_taint" FieldNodeTemplateSpot = "spot" @@ -62,10 +63,13 @@ const ( const ( ArchAMD64 = "amd64" ArchARM64 = "arm64" + OsLinux = "linux" + OsWindows = "windows" ) func resourceNodeTemplate() *schema.Resource { supportedArchitectures := []string{ArchAMD64, ArchARM64} + supportedOs := []string{OsLinux, OsWindows} return &schema.Resource{ CreateContext: resourceNodeTemplateCreate, @@ -295,6 +299,21 @@ func resourceNodeTemplate() *schema.Resource { }, Description: fmt.Sprintf("List of acceptable instance CPU architectures, the default is %s. Allowed values: %s.", ArchAMD64, strings.Join(supportedArchitectures, ", ")), }, + FieldNodeTemplateOs: { + Type: schema.TypeList, + MaxItems: 2, + MinItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(supportedOs, false)), + }, + DefaultFunc: func() (interface{}, error) { + return []string{OsLinux}, nil + }, + Description: fmt.Sprintf("List of acceptable instance Operating Systems, the default is %s. Allowed values: %s.", OsLinux, strings.Join(supportedOs, ", ")), + }, }, }, }, @@ -505,6 +524,9 @@ func flattenConstraints(c *sdk.NodetemplatesV1TemplateConstraints) ([]map[string if c.Architectures != nil { out[FieldNodeTemplateArchitectures] = lo.FromPtr(c.Architectures) } + if c.Os != nil { + out[FieldNodeTemplateOs] = lo.FromPtr(c.Os) + } return []map[string]any{out}, nil } @@ -966,6 +988,9 @@ func toTemplateConstraints(obj map[string]any) *sdk.NodetemplatesV1TemplateConst if v, ok := obj[FieldNodeTemplateArchitectures].([]any); ok { out.Architectures = toPtr(toStringList(v)) } + if v, ok := obj[FieldNodeTemplateOs].([]any); ok { + out.Os = toPtr(toStringList(v)) + } if v, ok := obj[FieldNodeTemplateIsGpuOnly].(bool); ok { out.IsGpuOnly = toPtr(v) } diff --git a/castai/resource_node_template_test.go b/castai/resource_node_template_test.go index 85bacc9e..8695ec5d 100644 --- a/castai/resource_node_template_test.go +++ b/castai/resource_node_template_test.go @@ -70,6 +70,7 @@ func TestNodeTemplateResourceReadContext(t *testing.T) { ] }, "architectures": ["amd64", "arm64"], + "os": ["linux"], "gpu": { "manufacturers": [ "NVIDIA" @@ -154,6 +155,8 @@ constraints.0.max_memory = 0 constraints.0.min_cpu = 10 constraints.0.min_memory = 0 constraints.0.on_demand = true +constraints.0.os.# = 1 +constraints.0.os.0 = linux constraints.0.spot = false constraints.0.spot_diversity_price_increase_limit_percent = 20 constraints.0.spot_interruption_predictions_enabled = true @@ -394,6 +397,8 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "constraints.0.on_demand", "false"), resource.TestCheckResourceAttr(resourceName, "constraints.0.architectures.#", "1"), resource.TestCheckResourceAttr(resourceName, "constraints.0.architectures.0", "amd64"), + resource.TestCheckResourceAttr(resourceName, "constraints.0.os.#", "1"), + resource.TestCheckResourceAttr(resourceName, "constraints.0.os.0", "linux"), resource.TestCheckResourceAttr(resourceName, "is_default", "false"), resource.TestCheckResourceAttr(resourceName, "constraints.0.enable_spot_diversity", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_diversity_price_increase_limit_percent", "21"), @@ -436,6 +441,8 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "constraints.0.use_spot_fallbacks", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.architectures.#", "1"), resource.TestCheckResourceAttr(resourceName, "constraints.0.architectures.0", "arm64"), + resource.TestCheckResourceAttr(resourceName, "constraints.0.os.#", "1"), + resource.TestCheckResourceAttr(resourceName, "constraints.0.os.0", "linux"), resource.TestCheckResourceAttr(resourceName, "is_default", "false"), resource.TestCheckResourceAttr(resourceName, "constraints.0.enable_spot_diversity", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_diversity_price_increase_limit_percent", "22"), diff --git a/castai/sdk/api.gen.go b/castai/sdk/api.gen.go index eddba1f3..9a2856cc 100644 --- a/castai/sdk/api.gen.go +++ b/castai/sdk/api.gen.go @@ -1564,7 +1564,8 @@ type NodetemplatesV1TemplateConstraints struct { MinMemory *int32 `json:"minMemory"` // Should include on-demand instances in the considered pool. - OnDemand *bool `json:"onDemand"` + OnDemand *bool `json:"onDemand"` + Os *[]string `json:"os,omitempty"` // Should include spot instances in the considered pool. // Note 1: if both spot and on-demand are false, then on-demand is assumed. diff --git a/docs/resources/node_template.md b/docs/resources/node_template.md index eab90d46..b1c0f997 100644 --- a/docs/resources/node_template.md +++ b/docs/resources/node_template.md @@ -55,6 +55,7 @@ Optional: - `min_cpu` (Number) Min CPU cores per node. - `min_memory` (Number) Min Memory (Mib) per node. - `on_demand` (Boolean) Should include on-demand instances in the considered pool. +- `os` (List of String) List of acceptable instance Operating Systems, the default is linux. Allowed values: linux, windows. - `spot` (Boolean) Should include spot instances in the considered pool. - `spot_diversity_price_increase_limit_percent` (Number) Allowed node configuration price increase when diversifying instance types. E.g. if the value is 10%, then the overall price of diversified instance types can be 10% higher than the price of the optimal configuration. - `spot_interruption_predictions_enabled` (Boolean) Enable/disable spot interruption predictions.