Skip to content

Commit

Permalink
fix(ocean/ecs): update capcity (AUT-5464) (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lironrad authored Apr 22, 2021
1 parent 5fc23a2 commit fe34ce0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Unreleased

BUG FIXES:
* resource/spotinst_ocean_ecs: resolved error with update `capacity` fields to 0

## 1.39.0 (April 20, 2021)

BUG FIXES:
Expand Down
12 changes: 6 additions & 6 deletions spotinst/ocean_ecs/fields_spotinst_ocean_ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
clusterWrapper := resourceObject.(*commons.ECSClusterWrapper)
cluster := clusterWrapper.GetECSCluster()
if v, ok := resourceData.GetOk(string(MaxSize)); ok {
cluster.Capacity.SetMaximum(spotinst.Int(v.(int)))
if v, ok := resourceData.Get(string(MaxSize)).(int); ok && v >= 0 {
cluster.Capacity.SetMaximum(spotinst.Int(v))
}
return nil
},
Expand Down Expand Up @@ -189,8 +189,8 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
clusterWrapper := resourceObject.(*commons.ECSClusterWrapper)
cluster := clusterWrapper.GetECSCluster()
if v, ok := resourceData.GetOk(string(MinSize)); ok {
cluster.Capacity.SetMinimum(spotinst.Int(v.(int)))
if v, ok := resourceData.Get(string(MinSize)).(int); ok && v >= 0 {
cluster.Capacity.SetMinimum(spotinst.Int(v))
}
return nil
},
Expand Down Expand Up @@ -228,8 +228,8 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
clusterWrapper := resourceObject.(*commons.ECSClusterWrapper)
cluster := clusterWrapper.GetECSCluster()
if v, ok := resourceData.GetOk(string(DesiredCapacity)); ok {
cluster.Capacity.SetTarget(spotinst.Int(v.(int)))
if v, ok := resourceData.Get(string(DesiredCapacity)).(int); ok && v >= 0 {
cluster.Capacity.SetTarget(spotinst.Int(v))
}
return nil
},
Expand Down
6 changes: 3 additions & 3 deletions spotinst/resource_spotinst_elastigroup_gke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ resource "` + string(commons.ElastigroupGKEResourceName) + `" "%v" {
provider = "%v"
name = "%v"
cluster_id = "terraform-tests-do-not-delete"
cluster_id = "terraform-tests-do-not-delete-2"
cluster_zone_name = "us-central1-a"
node_image = "COS"
Expand All @@ -233,7 +233,7 @@ resource "` + string(commons.ElastigroupGKEResourceName) + `" "%v" {
integration_gke {
location = "us-central1-a"
cluster_id = "terraform-tests-do-not-delete"
cluster_id = "terraform-tests-do-not-delete-2"
autoscale_is_enabled = true
autoscale_is_auto_config = false
autoscale_cooldown = 300
Expand All @@ -254,7 +254,7 @@ resource "` + string(commons.ElastigroupGKEResourceName) + `" "%v" {
provider = "%v"
name = "%v"
cluster_id = "terraform-tests-do-not-delete"
cluster_id = "terraform-tests-do-not-delete-2"
cluster_zone_name = "us-central1-a"
node_image = "COS"
Expand Down
9 changes: 6 additions & 3 deletions spotinst/resource_spotinst_ocean_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestAccSpotinstOceanAWS_Baseline(t *testing.T) {
testCheckOceanAWSExists(&cluster, resourceName),
testCheckOceanAWSAttributes(&cluster, clusterName),
resource.TestCheckResourceAttr(resourceName, "max_size", "10"),
resource.TestCheckResourceAttr(resourceName, "min_size", "2"),
resource.TestCheckResourceAttr(resourceName, "min_size", "0"),
resource.TestCheckResourceAttr(resourceName, "desired_capacity", "2"),
),
},
Expand Down Expand Up @@ -239,7 +239,7 @@ resource "` + string(commons.OceanAWSResourceName) + `" "%v" {
region = "us-west-2"
max_size = 10
min_size = 2
min_size = 0
desired_capacity = 2
subnet_ids = ["subnet-bce60ec4"]
Expand Down Expand Up @@ -569,15 +569,17 @@ func TestAccSpotinstOceanAWS_Strategy(t *testing.T) {
},
{
Config: createOceanAWSTerraform(&ClusterConfigMetadata{

clusterName: clusterName,
controllerClusterID: controllerClusterID,
strategy: testStrategyConfig_EmptyFields,
}),
ExpectNonEmptyPlan: true,
Check: resource.ComposeTestCheckFunc(
testCheckOceanAWSExists(&cluster, resourceName),
testCheckOceanAWSAttributes(&cluster, clusterName),
resource.TestCheckResourceAttr(resourceName, "fallback_to_ondemand", "true"),
resource.TestCheckResourceAttr(resourceName, "spot_percentage", "0"),
resource.TestCheckResourceAttr(resourceName, "spot_percentage", "-1"),
resource.TestCheckResourceAttr(resourceName, "utilize_reserved_instances", "true"),
resource.TestCheckResourceAttr(resourceName, "draining_timeout", "0"),
),
Expand Down Expand Up @@ -959,6 +961,7 @@ func TestAccSpotinstOceanAWS_UpdatePolicy(t *testing.T) {
controllerClusterID: controllerClusterID,
fieldsToAppend: testUpdatePolicyAWSClusterConfig_EmptyFields,
}),
ExpectNonEmptyPlan: true,
Check: resource.ComposeTestCheckFunc(
testCheckOceanAWSExists(&cluster, resourceName),
testCheckOceanAWSAttributes(&cluster, clusterName),
Expand Down
14 changes: 7 additions & 7 deletions spotinst/resource_spotinst_ocean_gke_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/spotinst/terraform-provider-spotinst/spotinst/commons"
)

var GcpClusterName = "terraform-tests-do-not-delete"
var GcpClusterName = "terraform-tests-do-not-delete-2"

func init() {
resource.AddTestSweepers("resource_spotinst_ocean_gke_import", &resource.Sweeper{
Expand Down Expand Up @@ -151,7 +151,7 @@ func createOceanGKEImportTerraform(clusterMeta *OceanGKEImportMetadata) string {

// region Ocean GKE Import: Baseline
func TestAccSpotinstOceanGKEImport_Baseline(t *testing.T) {
spotClusterName := "terraform-tests-do-not-delete"
spotClusterName := "terraform-tests-do-not-delete-2"
resourceName := createOceanGKEImportResourceName(spotClusterName)

var cluster gcp.Cluster
Expand Down Expand Up @@ -195,7 +195,7 @@ const testBaselineOceanGKEImportConfig_Create = `
resource "` + string(commons.OceanGKEImportResourceName) + `" "%v" {
provider = "%v"
cluster_name = "terraform-tests-do-not-delete"
cluster_name = "terraform-tests-do-not-delete-2"
location = "us-central1-a"
whitelist = ["n1-standard-1", "n1-standard-2"]
Expand All @@ -211,7 +211,7 @@ const testBaselineOceanGKEImportConfig_Update = `
resource "` + string(commons.OceanGKEImportResourceName) + `" "%v" {
provider = "%v"
cluster_name = "terraform-tests-do-not-delete"
cluster_name = "terraform-tests-do-not-delete-2"
location = "us-central1-a"
whitelist = ["n1-standard-1"]
Expand All @@ -224,7 +224,7 @@ resource "` + string(commons.OceanGKEImportResourceName) + `" "%v" {

//region Ocean GKE Import: BackendServices
func TestAccSpotinstOceanGKEImport_BackendServices(t *testing.T) {
spotClusterName := "terraform-tests-do-not-delete"
spotClusterName := "terraform-tests-do-not-delete-2"
resourceName := createOceanGKEImportResourceName(spotClusterName)

var cluster gcp.Cluster
Expand Down Expand Up @@ -305,7 +305,7 @@ const testBackendServicesOceanGKEImportConfig_Update = `

// region Ocean GKE Import: Scheduling
func TestAccSpotinstOceanGKEImport_Scheduling(t *testing.T) {
spotClusterName := "terraform-tests-do-not-delete"
spotClusterName := "terraform-tests-do-not-delete-2"
resourceName := createOceanGKEImportResourceName(spotClusterName)

var cluster gcp.Cluster
Expand Down Expand Up @@ -396,7 +396,7 @@ const testOceanGKEScheduling_Update = `

// region Ocean GKE Import: autoscaler
func TestAccSpotinstOceanGKEImport_Autoscaler(t *testing.T) {
spotClusterName := "terraform-tests-do-not-delete"
spotClusterName := "terraform-tests-do-not-delete-2"
resourceName := createOceanGKEImportResourceName(spotClusterName)

var cluster gcp.Cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func createOceanGKELaunchSpecImportTerraform(launchSpecMeta *OceanGKELaunchSpecI

// region Ocean GKE Import: Baseline
func TestAccSpotinstOceanGKELaunchSpecImport_Baseline(t *testing.T) {
oceanID := "o-a424eae0"
oceanID := "o-9e2ccd58"
resourceName := createOceanGKELaunchSpecImportResource(oceanID)

var launchSpec gcp.LaunchSpec
Expand Down

0 comments on commit fe34ce0

Please sign in to comment.