Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for auto_update in spotinst_ocean_gke_import. #616

Merged
merged 5 commits into from
Jan 10, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 6 additions & 0 deletions docs/resources/ocean_gke_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.


<a id="scheduled-task"></a>
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions spotinst/ocean_gke_import/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
87 changes: 87 additions & 0 deletions spotinst/ocean_gke_import/fields_spotinst_ocean_gke_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions spotinst/resource_spotinst_ocean_gke_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
sharadkesarwani marked this conversation as resolved.
Show resolved Hide resolved
),
},
{
Expand All @@ -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"),
),
},
},
Expand Down Expand Up @@ -230,6 +234,9 @@ strategy {
provisioning_model = "PREEMPTIBLE"
preemptible_percentage = 30
}
auto_update {
is_enabled = true
}
%v
}

Expand All @@ -254,6 +261,9 @@ strategy {
provisioning_model = "SPOT"
preemptible_percentage = 60
}
auto_update {
is_enabled = false
}
%v
}

Expand Down
Loading