diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index a5ef84bc0a9f..596d3af0ca90 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -93,10 +93,13 @@ func resourceAwsEcsService() *schema.Resource { "deployment_maximum_percent": { Type: schema.TypeInt, Optional: true, - Default: 200, DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { if d.Get("scheduling_strategy").(string) == ecs.SchedulingStrategyDaemon { return true + } else { // must be SchedulingStrategyReplica + if !d.IsNewResource() && new == "0" { + return true + } } return false }, @@ -105,9 +108,8 @@ func resourceAwsEcsService() *schema.Resource { "deployment_minimum_healthy_percent": { Type: schema.TypeInt, Optional: true, - Default: 100, DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - if d.Get("scheduling_strategy").(string) == ecs.SchedulingStrategyDaemon { + if !d.IsNewResource() && new == "0" { return true } return false @@ -332,12 +334,20 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error TaskDefinition: aws.String(d.Get("task_definition").(string)), DesiredCount: aws.Int64(int64(d.Get("desired_count").(int))), ClientToken: aws.String(resource.UniqueId()), - DeploymentConfiguration: &ecs.DeploymentConfiguration{ - MaximumPercent: aws.Int64(int64(d.Get("deployment_maximum_percent").(int))), - MinimumHealthyPercent: aws.Int64(int64(d.Get("deployment_minimum_healthy_percent").(int))), - }, } + deploymentConfiguration := &ecs.DeploymentConfiguration{} + + if v, ok := d.GetOk("deployment_maximum_percent"); ok { + deploymentConfiguration.MaximumPercent = aws.Int64(int64(v.(int))) + } + + if v, ok := d.GetOk("deployment_minimum_healthy_percent"); ok { + deploymentConfiguration.MinimumHealthyPercent = aws.Int64(int64(v.(int))) + } + + input.DeploymentConfiguration = deploymentConfiguration + if v, ok := d.GetOk("cluster"); ok { input.Cluster = aws.String(v.(string)) } @@ -354,7 +364,7 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error input.SchedulingStrategy = aws.String(schedulingStrategy) if schedulingStrategy == ecs.SchedulingStrategyDaemon { // unset these if DAEMON - input.DeploymentConfiguration = nil + input.DeploymentConfiguration.MaximumPercent = nil input.DesiredCount = nil } @@ -767,13 +777,19 @@ func resourceAwsEcsServiceUpdate(d *schema.ResourceData, meta interface{}) error input.TaskDefinition = aws.String(n.(string)) } - if schedulingStrategy != ecs.SchedulingStrategyDaemon && (d.HasChange("deployment_maximum_percent") || d.HasChange("deployment_minimum_healthy_percent")) { + if schedulingStrategy == ecs.SchedulingStrategyReplica && (d.HasChange("deployment_maximum_percent") || d.HasChange("deployment_minimum_healthy_percent")) { input.DeploymentConfiguration = &ecs.DeploymentConfiguration{ MaximumPercent: aws.Int64(int64(d.Get("deployment_maximum_percent").(int))), MinimumHealthyPercent: aws.Int64(int64(d.Get("deployment_minimum_healthy_percent").(int))), } } + if schedulingStrategy == ecs.SchedulingStrategyDaemon && d.HasChange("deployment_minimum_healthy_percent") { + input.DeploymentConfiguration = &ecs.DeploymentConfiguration{ + MinimumHealthyPercent: aws.Int64(int64(d.Get("deployment_minimum_healthy_percent").(int))), + } + } + if d.HasChange("network_configuration") { input.NetworkConfiguration = expandEcsNetworkConfiguration(d.Get("network_configuration").([]interface{})) } diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index b21839b2f1f2..1cb9489b1472 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -675,6 +675,30 @@ func TestAccAWSEcsService_withDaemonSchedulingStrategy(t *testing.T) { }) } +func TestAccAWSEcsService_withDaemonSchedulingStrategySetDeploymentMinimum(t *testing.T) { + var service ecs.Service + rString := acctest.RandString(8) + + clusterName := fmt.Sprintf("tf-acc-cluster-svc-w-ss-daemon-%s", rString) + tdName := fmt.Sprintf("tf-acc-td-svc-w-ss-daemon-%s", rString) + svcName := fmt.Sprintf("tf-acc-svc-w-ss-daemon-%s", rString) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEcsServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEcsServiceWithDaemonSchedulingStrategySetDeploymentMinimum(clusterName, tdName, svcName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists("aws_ecs_service.ghost", &service), + resource.TestCheckResourceAttr("aws_ecs_service.ghost", "scheduling_strategy", "DAEMON"), + ), + }, + }, + }) +} + func TestAccAWSEcsService_withReplicaSchedulingStrategy(t *testing.T) { var service ecs.Service rString := acctest.RandString(8) @@ -2096,6 +2120,35 @@ resource "aws_ecs_service" "ghost" { `, clusterName, tdName, svcName) } +func testAccAWSEcsServiceWithDaemonSchedulingStrategySetDeploymentMinimum(clusterName, tdName, svcName string) string { + return fmt.Sprintf(` +resource "aws_ecs_cluster" "default" { + name = "%s" +} +resource "aws_ecs_task_definition" "ghost" { + family = "%s" + container_definitions = <