diff --git a/CHANGELOG.md b/CHANGELOG.md index a3f7ab64..868288cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased +## 1.206.0 (January, 10 2025) +ENHANCEMENTS: +* resource/spotinst_ocean_gke_import: Added support for `auto_update` object. + ## 1.205.1 (January, 07 2025) FIXES: * Upgraded packages go-getter from v1.7.5 to v1.7.6 and go-git/v5 from v5.12.0 to v5.13.0 to solve vulnerabilities. diff --git a/docs/resources/ocean_gke_import.md b/docs/resources/ocean_gke_import.md index d0f8fa71..e9e7c207 100644 --- a/docs/resources/ocean_gke_import.md +++ b/docs/resources/ocean_gke_import.md @@ -41,6 +41,10 @@ resource "spotinst_ocean_gke_import" "example" { max_size = 2 desired_capacity = 0 + auto_update { + is_enabled = true + } + whitelist = ["n1-standard-1", "n1-standard-2"] filters { @@ -110,6 +114,8 @@ The following arguments are supported: * `enable_integrity_monitoring` - (Optional) Boolean. Enable the integrity monitoring parameter on the GCP instances. * `enable_secure_boot` - (Optional) Boolean. Enable the secure boot parameter on the GCP instances. * `use_as_template_only` - (Optional, Default: false) launch specification defined on the Ocean object will function only as a template for virtual node groups. +* `auto_update` - (Optional) The Ocean Kubernetes AutoUpdate object. If set to 'true', Ocean will ensure that your clusters have an up-to-date configuration according to the respective GKE cluster. + * `is_enabled` - (Optional, Default:`true`) Enable the Ocean Kubernetes AutoUpdate. diff --git a/go.mod b/go.mod index 48a918c6..cdb27515 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/hashicorp/terraform-plugin-docs v0.5.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.5.0 github.com/sethvargo/go-password v0.3.1 - github.com/spotinst/spotinst-sdk-go v1.380.0 + github.com/spotinst/spotinst-sdk-go v1.382.0 golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 ) diff --git a/go.sum b/go.sum index 5a294558..b8d8d644 100644 --- a/go.sum +++ b/go.sum @@ -587,8 +587,8 @@ github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0 github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spotinst/spotinst-sdk-go v1.380.0 h1:eGZ12gMDYHazZbR+ZGW1Pq5JnD8uTTrt+sLJX3fd/DY= -github.com/spotinst/spotinst-sdk-go v1.380.0/go.mod h1:Tn4/eb0SFY6IXmxz71CClujvbD/PuT+EO6Ta8v6AML4= +github.com/spotinst/spotinst-sdk-go v1.382.0 h1:EbRLMORlFdN27urjc0QyThjlKUEmpYp+89FvZWZAK80= +github.com/spotinst/spotinst-sdk-go v1.382.0/go.mod h1:Tn4/eb0SFY6IXmxz71CClujvbD/PuT+EO6Ta8v6AML4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= diff --git a/spotinst/ocean_gke_import/consts.go b/spotinst/ocean_gke_import/consts.go index b1f33a38..fd0b8128 100644 --- a/spotinst/ocean_gke_import/consts.go +++ b/spotinst/ocean_gke_import/consts.go @@ -41,4 +41,6 @@ const ( MaxVcpu commons.FieldName = "max_vcpu" MinMemoryGiB commons.FieldName = "min_memory_gib" MinVcpu commons.FieldName = "min_vcpu" + AutoUpdate commons.FieldName = "auto_update" + IsEnabled commons.FieldName = "is_enabled" ) diff --git a/spotinst/ocean_gke_import/fields_spotinst_ocean_gke_import.go b/spotinst/ocean_gke_import/fields_spotinst_ocean_gke_import.go index 9f026977..fea42426 100644 --- a/spotinst/ocean_gke_import/fields_spotinst_ocean_gke_import.go +++ b/spotinst/ocean_gke_import/fields_spotinst_ocean_gke_import.go @@ -552,6 +552,68 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) { }, nil, ) + + fieldsMap[AutoUpdate] = commons.NewGenericField( + commons.OceanGKEImport, + AutoUpdate, + &schema.Schema{ + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + string(IsEnabled): { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + }, + }, + }, + + func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error { + clusterWrapper := resourceObject.(*commons.GKEImportClusterWrapper) + cluster := clusterWrapper.GetCluster() + var result []interface{} = nil + if cluster != nil && cluster.AutoUpdate != nil { + result = flattenAutoUpdate(cluster.AutoUpdate) + } + if len(result) > 0 { + if err := resourceData.Set(string(AutoUpdate), result); err != nil { + return fmt.Errorf(string(commons.FailureFieldReadPattern), string(AutoUpdate), err) + } + } + + return nil + }, + func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error { + clusterWrapper := resourceObject.(*commons.GKEImportClusterWrapper) + cluster := clusterWrapper.GetCluster() + if v, ok := resourceData.GetOk(string(AutoUpdate)); ok { + if autoUpdate, err := expandAutoUpdate(v); err != nil { + return err + } else { + cluster.SetAutoUpdate(autoUpdate) + } + } + return nil + }, + func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error { + clusterWrapper := resourceObject.(*commons.GKEImportClusterWrapper) + cluster := clusterWrapper.GetCluster() + var value *gcp.AutoUpdate = nil + + if v, ok := resourceData.GetOk(string(AutoUpdate)); ok { + if autoUpdate, err := expandAutoUpdate(v); err != nil { + return err + } else { + value = autoUpdate + } + } + cluster.SetAutoUpdate(value) + return nil + }, + nil, + ) } func expandServices(data interface{}) ([]*gcp.BackendService, error) { @@ -739,3 +801,28 @@ func flattenFilters(filters *gcp.Filters) []interface{} { return out } +func flattenAutoUpdate(autoupdate *gcp.AutoUpdate) []interface{} { + var out []interface{} + if autoupdate != nil { + result := make(map[string]interface{}) + result[string(IsEnabled)] = spotinst.BoolValue(autoupdate.IsEnabled) + if len(result) > 0 { + out = append(out, result) + } + } + return out +} + +func expandAutoUpdate(data interface{}) (*gcp.AutoUpdate, error) { + autoUpdate := &gcp.AutoUpdate{} + list := data.([]interface{}) + if list == nil || list[0] == nil { + return autoUpdate, nil + } + m := list[0].(map[string]interface{}) + + if v, ok := m[string(IsEnabled)].(bool); ok { + autoUpdate.SetIsEnabled(spotinst.Bool(v)) + } + return autoUpdate, nil +} diff --git a/spotinst/resource_spotinst_ocean_gke_import_test.go b/spotinst/resource_spotinst_ocean_gke_import_test.go index f11e1e43..c465d88a 100644 --- a/spotinst/resource_spotinst_ocean_gke_import_test.go +++ b/spotinst/resource_spotinst_ocean_gke_import_test.go @@ -182,6 +182,8 @@ func TestAccSpotinstOceanGKEImport_Baseline(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "strategy.0.draining_timeout", "60"), resource.TestCheckResourceAttr(resourceName, "strategy.0.provisioning_model", "PREEMPTIBLE"), resource.TestCheckResourceAttr(resourceName, "strategy.0.preemptible_percentage", "30"), + resource.TestCheckResourceAttr(resourceName, "auto_update.#", "1"), + resource.TestCheckResourceAttr(resourceName, "auto_update.0.is_enabled", "true"), ), }, { @@ -202,6 +204,8 @@ func TestAccSpotinstOceanGKEImport_Baseline(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "strategy.0.draining_timeout", "120"), resource.TestCheckResourceAttr(resourceName, "strategy.0.provisioning_model", "SPOT"), resource.TestCheckResourceAttr(resourceName, "strategy.0.preemptible_percentage", "60"), + resource.TestCheckResourceAttr(resourceName, "auto_update.#", "1"), + resource.TestCheckResourceAttr(resourceName, "auto_update.0.is_enabled", "false"), ), }, }, @@ -230,6 +234,9 @@ strategy { provisioning_model = "PREEMPTIBLE" preemptible_percentage = 30 } +auto_update { + is_enabled = true + } %v } @@ -254,6 +261,9 @@ strategy { provisioning_model = "SPOT" preemptible_percentage = 60 } +auto_update { + is_enabled = false + } %v }