From 54f800a541216b95c3dc2d0e174dd7b354b324b3 Mon Sep 17 00:00:00 2001 From: "liron.arad" Date: Wed, 3 Mar 2021 06:59:35 +0200 Subject: [PATCH] fix(elastigroup/aws): AUT-3714, AUT-3713, PROD-4204 --- CHANGELOG.md | 3 +++ docs/resources/elastigroup_aws.md | 2 +- .../fields_spotinst_elastigroup_aws_integrations.go | 8 ++++++-- ..._spotinst_elastigroup_aws_integrations_docker_swarm.go | 2 +- .../fields_spotinst_elastigroup_aws_integrations_ecs.go | 2 +- ...ds_spotinst_elastigroup_aws_integrations_kubernetes.go | 2 +- .../fields_spotinst_elastigroup_aws_integrations_nomad.go | 2 +- ...ields_spotinst_elastigroup_aws_launch_configuration.go | 4 +++- .../fields_spotinst_ocean_aws_strategy.go | 6 +++++- 9 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 553277c2d..735967cca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ BUG FIXES: * resource/spotinst_ocean_gke_import: resolved error with `desired_capacity` not applying 0 as value +* resource/spotinst_elastigroup_aws: resolved errors with `max_scale_down_percentage` +* resource/spotinst_elastigroup_aws: resolved errors with `key_name` +* resource/spotinst_ocean_strategy: resolved errors with `spot_percentage` ## 1.35.0 (March 1, 2021) diff --git a/docs/resources/elastigroup_aws.md b/docs/resources/elastigroup_aws.md index 25be7fc70..c722a88b5 100644 --- a/docs/resources/elastigroup_aws.md +++ b/docs/resources/elastigroup_aws.md @@ -531,7 +531,7 @@ Usage: ## Stateful We support instance persistence via the following configurations. all values are boolean. -For more information on instance persistence please see: [Stateful configuration](https://api.spotinst.com/integration-docs/elastigroup/concepts/stateful-concepts/introduction/) +For more information on instance persistence please see: [Stateful configuration](https://docs.spot.io/elastigroup/features/stateful-instance/stateful-instances) * `persist_root_device` - (Optional) Boolean, should the instance maintain its root device volumes. * `persist_block_devices` - (Optional) Boolean, should the instance maintain its Data volumes. diff --git a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations.go b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations.go index 805ffdf7e..ae510ecee 100644 --- a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations.go +++ b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations.go @@ -50,18 +50,22 @@ func expandAWSGroupAutoScaleHeadroom(data interface{}) (*aws.AutoScaleHeadroom, return nil, nil } -func expandAWSGroupAutoScaleDown(data interface{}) (*aws.AutoScaleDown, error) { +func expandAWSGroupAutoScaleDown(data interface{}, isMaxScaleDownPercentageExist bool) (*aws.AutoScaleDown, error) { if list := data.([]interface{}); len(list) > 0 { autoScaleDown := &aws.AutoScaleDown{} if list != nil && list[0] != nil { m := list[0].(map[string]interface{}) + var maxScaleDownPercentage *float64 = nil if v, ok := m[string(EvaluationPeriods)].(int); ok && v > 0 { autoScaleDown.SetEvaluationPeriods(spotinst.Int(v)) } if v, ok := m[string(MaxScaleDownPercentage)].(float64); ok && v > 0 { - autoScaleDown.SetMaxScaleDownPercentage(spotinst.Float64(v)) + maxScaleDownPercentage = spotinst.Float64(v) + } + if isMaxScaleDownPercentageExist { + autoScaleDown.SetMaxScaleDownPercentage(maxScaleDownPercentage) } } return autoScaleDown, nil diff --git a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_docker_swarm.go b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_docker_swarm.go index 7a8b62a08..883d93856 100644 --- a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_docker_swarm.go +++ b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_docker_swarm.go @@ -172,7 +172,7 @@ func expandAWSGroupDockerSwarmIntegration(data interface{}, nullify bool) (*aws. } if v, ok := m[string(AutoscaleDown)]; ok { - down, err := expandAWSGroupAutoScaleDown(v) + down, err := expandAWSGroupAutoScaleDown(v, true) if err != nil { return nil, err } diff --git a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_ecs.go b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_ecs.go index ab901466f..016212744 100644 --- a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_ecs.go +++ b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_ecs.go @@ -232,7 +232,7 @@ func expandAWSGroupEC2ContainerServiceIntegration(data interface{}) (*aws.EC2Con } if v, ok := m[string(AutoscaleDown)]; ok { - down, err := expandAWSGroupAutoScaleDown(v) + down, err := expandAWSGroupAutoScaleDown(v, true) if err != nil { return nil, err } diff --git a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_kubernetes.go b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_kubernetes.go index 1b78b15c6..4ca4d5038 100644 --- a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_kubernetes.go +++ b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_kubernetes.go @@ -215,7 +215,7 @@ func expandAWSGroupKubernetesIntegration(data interface{}) (*aws.KubernetesInteg } if v, ok := m[string(AutoscaleDown)]; ok { - down, err := expandAWSGroupAutoScaleDown(v) + down, err := expandAWSGroupAutoScaleDown(v, false) if err != nil { return nil, err } diff --git a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_nomad.go b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_nomad.go index 37d2f7ab7..cbf0540b2 100644 --- a/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_nomad.go +++ b/spotinst/elastigroup_aws_integrations/fields_spotinst_elastigroup_aws_integrations_nomad.go @@ -197,7 +197,7 @@ func expandAWSGroupNomadIntegration(data interface{}, nullify bool) (*aws.NomadI } if v, ok := m[string(AutoscaleDown)]; ok { - down, err := expandAWSGroupAutoScaleDown(v) + down, err := expandAWSGroupAutoScaleDown(v, false) if err != nil { return nil, err } diff --git a/spotinst/elastigroup_aws_launch_configuration/fields_spotinst_elastigroup_aws_launch_configuration.go b/spotinst/elastigroup_aws_launch_configuration/fields_spotinst_elastigroup_aws_launch_configuration.go index cd8c2110d..ef5d5c399 100644 --- a/spotinst/elastigroup_aws_launch_configuration/fields_spotinst_elastigroup_aws_launch_configuration.go +++ b/spotinst/elastigroup_aws_launch_configuration/fields_spotinst_elastigroup_aws_launch_configuration.go @@ -145,9 +145,11 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) { func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error { egWrapper := resourceObject.(*commons.ElastigroupWrapper) elastigroup := egWrapper.GetElastigroup() + var value *string = nil if v, ok := resourceData.Get(string(KeyName)).(string); ok && v != "" { - elastigroup.Compute.LaunchSpecification.SetKeyPair(spotinst.String(v)) + value = spotinst.String(v) } + elastigroup.Compute.LaunchSpecification.SetKeyPair(value) return nil }, nil, diff --git a/spotinst/ocean_aws_strategy/fields_spotinst_ocean_aws_strategy.go b/spotinst/ocean_aws_strategy/fields_spotinst_ocean_aws_strategy.go index d744afae4..7138a6193 100644 --- a/spotinst/ocean_aws_strategy/fields_spotinst_ocean_aws_strategy.go +++ b/spotinst/ocean_aws_strategy/fields_spotinst_ocean_aws_strategy.go @@ -148,8 +148,12 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) { func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error { clusterWrapper := resourceObject.(*commons.AWSClusterWrapper) cluster := clusterWrapper.GetCluster() + var spotPercentage *float64 = nil if v := resourceData.Get(string(SpotPercentage)).(int); v > -1 { - cluster.Strategy.SetSpotPercentage(spotinst.Float64(float64(v))) + if v > 0 { + spotPercentage = spotinst.Float64(float64(v)) + } + cluster.Strategy.SetSpotPercentage(spotPercentage) } return nil },