diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index 1cb4771d..9e985432 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -1033,8 +1033,8 @@ func toTemplateConstraints(d *schema.ResourceData, obj map[string]any) *sdk.Node } out := &sdk.NodetemplatesV1TemplateConstraints{} - // todo: replace with tri-state enum - if v, exists := d.GetOk(FieldNodeTemplateConstraints + "." + FieldNodeTemplateComputeOptimized); exists { + // todo: replace with tri-state enum as GetOkExists is deprecated + if v, exists := d.GetOkExists(FieldNodeTemplateConstraints + ".0." + FieldNodeTemplateComputeOptimized); exists { out.ComputeOptimized = toPtr(v.(bool)) } if v, ok := obj[FieldNodeTemplateFallbackRestoreRateSeconds].(int); ok { @@ -1074,8 +1074,8 @@ func toTemplateConstraints(d *schema.ResourceData, obj map[string]any) *sdk.Node out.Spot = toPtr(!v) } } - // todo: replace with tri-state enum - if v, exists := d.GetOk(FieldNodeTemplateConstraints + "." + FieldNodeTemplateStorageOptimized); exists { + // todo: replace with tri-state enum as GetOkExists is deprecated + if v, exists := d.GetOkExists(FieldNodeTemplateConstraints + ".0." + FieldNodeTemplateStorageOptimized); exists { out.StorageOptimized = toPtr(v.(bool)) } if v, ok := obj[FieldNodeTemplateUseSpotFallbacks].(bool); ok { diff --git a/castai/resource_node_template_test.go b/castai/resource_node_template_test.go index 98adec82..315cafa4 100644 --- a/castai/resource_node_template_test.go +++ b/castai/resource_node_template_test.go @@ -405,7 +405,7 @@ func TestToTemplateConstraints_HandleTriStateValuesForStorageAndComputeOptimized val cty.Value assertions func(*require.Assertions, *sdk.NodetemplatesV1TemplateConstraints) }{ - "all values empty except one": { + "all values nil": { val: cty.ObjectVal(map[string]cty.Value{ FieldNodeTemplateConstraints: cty.ListVal([]cty.Value{ cty.ObjectVal(map[string]cty.Value{ @@ -419,6 +419,24 @@ func TestToTemplateConstraints_HandleTriStateValuesForStorageAndComputeOptimized r.Nil(constraints.StorageOptimized) }, }, + "values are true/false": { + val: cty.ObjectVal(map[string]cty.Value{ + FieldNodeTemplateConstraints: cty.ListVal([]cty.Value{ + cty.ObjectVal(map[string]cty.Value{ + FieldNodeTemplateMaxCpu: cty.NumberIntVal(100), + FieldNodeTemplateStorageOptimized: cty.True, + FieldNodeTemplateComputeOptimized: cty.False, + }), + }), + }), + assertions: func(r *require.Assertions, constraints *sdk.NodetemplatesV1TemplateConstraints) { + r.NotNil(constraints) + r.NotNil(constraints.ComputeOptimized) + r.NotNil(constraints.StorageOptimized) + r.True(lo.FromPtr(constraints.StorageOptimized)) + r.False(lo.FromPtr(constraints.ComputeOptimized)) + }, + }, } for name, td := range tests {