diff --git a/CHANGELOG.md b/CHANGELOG.md index ea5039bd1..2c20ac579 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/spotinst/ocean_ecs/fields_spotinst_ocean_ecs.go b/spotinst/ocean_ecs/fields_spotinst_ocean_ecs.go index e1c094ff3..7e924e14f 100644 --- a/spotinst/ocean_ecs/fields_spotinst_ocean_ecs.go +++ b/spotinst/ocean_ecs/fields_spotinst_ocean_ecs.go @@ -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 }, @@ -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 }, @@ -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 }, diff --git a/spotinst/resource_spotinst_elastigroup_gke_test.go b/spotinst/resource_spotinst_elastigroup_gke_test.go index 85a874de0..4a536e58e 100644 --- a/spotinst/resource_spotinst_elastigroup_gke_test.go +++ b/spotinst/resource_spotinst_elastigroup_gke_test.go @@ -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" @@ -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 @@ -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" diff --git a/spotinst/resource_spotinst_ocean_aws_test.go b/spotinst/resource_spotinst_ocean_aws_test.go index 904425734..276cfe55b 100644 --- a/spotinst/resource_spotinst_ocean_aws_test.go +++ b/spotinst/resource_spotinst_ocean_aws_test.go @@ -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"), ), }, @@ -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"] @@ -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"), ), @@ -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), diff --git a/spotinst/resource_spotinst_ocean_gke_import_test.go b/spotinst/resource_spotinst_ocean_gke_import_test.go index 69e2e4ccd..3ea6727da 100644 --- a/spotinst/resource_spotinst_ocean_gke_import_test.go +++ b/spotinst/resource_spotinst_ocean_gke_import_test.go @@ -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{ @@ -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 @@ -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"] @@ -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"] @@ -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 @@ -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 @@ -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 diff --git a/spotinst/resource_spotinst_ocean_gke_launch_spec_import_test.go b/spotinst/resource_spotinst_ocean_gke_launch_spec_import_test.go index 87937e0d3..cd88f8b47 100644 --- a/spotinst/resource_spotinst_ocean_gke_launch_spec_import_test.go +++ b/spotinst/resource_spotinst_ocean_gke_launch_spec_import_test.go @@ -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