diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index 08333814..e00b430b 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -123,8 +123,8 @@ func resourceNodeTemplate() *schema.Resource { }, FieldNodeTemplateOnDemand: { Type: schema.TypeBool, - Default: false, Optional: true, + Computed: true, Description: "Should include on-demand instances in the considered pool.", }, FieldNodeTemplateUseSpotFallbacks: { @@ -147,7 +147,6 @@ func resourceNodeTemplate() *schema.Resource { }, FieldNodeTemplateSpotDiversityPriceIncreaseLimitPercent: { Type: schema.TypeInt, - Default: 20, Optional: true, Description: "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.", }, @@ -159,7 +158,6 @@ func resourceNodeTemplate() *schema.Resource { }, FieldNodeTemplateSpotInterruptionPredictionsType: { Type: schema.TypeString, - Default: "aws-rebalance-recommendations", Optional: true, Description: "Spot interruption predictions type. Can be either \"aws-rebalance-recommendations\" or \"interruption-predictions\".", ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"aws-rebalance-recommendations", "interruption-predictions"}, false)), @@ -882,6 +880,10 @@ func toTemplateConstraints(obj map[string]any) *sdk.NodetemplatesV1TemplateConst } if v, ok := obj[FieldNodeTemplateOnDemand].(bool); ok { out.OnDemand = toPtr(v) + } else { + if v, ok := obj[FieldNodeTemplateSpot].(bool); ok { + out.Spot = toPtr(!v) + } } if v, ok := obj[FieldNodeTemplateStorageOptimized].(bool); ok { out.StorageOptimized = toPtr(v) diff --git a/castai/resource_node_template_test.go b/castai/resource_node_template_test.go index 70cd2985..7b0dc8ec 100644 --- a/castai/resource_node_template_test.go +++ b/castai/resource_node_template_test.go @@ -244,10 +244,10 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "constraints.0.max_cpu", "100"), resource.TestCheckResourceAttr(resourceName, "constraints.0.use_spot_fallbacks", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.spot", "true"), + 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, "is_default", "false"), - resource.TestCheckResourceAttr(resourceName, "constraints.0.on_demand", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.enable_spot_diversity", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_diversity_price_increase_limit_percent", "21"), resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_interruption_predictions_enabled", "true"), @@ -278,6 +278,7 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "custom_taints.0.value", "custom-taint-value-1"), resource.TestCheckResourceAttr(resourceName, "constraints.0.use_spot_fallbacks", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.spot", "true"), + resource.TestCheckResourceAttr(resourceName, "constraints.0.on_demand", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.instance_families.#", "0"), resource.TestCheckResourceAttr(resourceName, "constraints.0.gpu.0.manufacturers.#", "0"), resource.TestCheckResourceAttr(resourceName, "constraints.0.gpu.0.include_names.#", "0"), @@ -285,11 +286,9 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "constraints.0.min_cpu", "0"), resource.TestCheckResourceAttr(resourceName, "constraints.0.max_cpu", "0"), resource.TestCheckResourceAttr(resourceName, "constraints.0.use_spot_fallbacks", "true"), - resource.TestCheckResourceAttr(resourceName, "constraints.0.spot", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.architectures.#", "1"), resource.TestCheckResourceAttr(resourceName, "constraints.0.architectures.0", "arm64"), resource.TestCheckResourceAttr(resourceName, "is_default", "false"), - resource.TestCheckResourceAttr(resourceName, "constraints.0.on_demand", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.enable_spot_diversity", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_diversity_price_increase_limit_percent", "22"), resource.TestCheckResourceAttr(resourceName, "constraints.0.spot_interruption_predictions_enabled", "true"), @@ -334,7 +333,6 @@ func testAccNodeTemplateConfig(rName, clusterName string) string { constraints { fallback_restore_rate_seconds = 1800 spot = true - on_demand = true enable_spot_diversity = true spot_diversity_price_increase_limit_percent = 21 spot_interruption_predictions_enabled = true