diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index e1942508400..22f8eb94550 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -49,6 +49,12 @@ func resourceAwsEcsService() *schema.Resource { Optional: true, }, + "health_check_grace_period_seconds": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validateAwsEcsServiceHealthCheckGracePeriodSeconds, + }, + "launch_type": { Type: schema.TypeString, ForceNew: true, @@ -213,6 +219,10 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error input.Cluster = aws.String(v.(string)) } + if v, ok := d.GetOk("health_check_grace_period_seconds"); ok { + input.HealthCheckGracePeriodSeconds = aws.Int64(int64(v.(int))) + } + if v, ok := d.GetOk("launch_type"); ok { input.LaunchType = aws.String(v.(string)) } @@ -352,7 +362,7 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error { } d.Set("desired_count", service.DesiredCount) - + d.Set("health_check_grace_period_seconds", service.HealthCheckGracePeriodSeconds) d.Set("launch_type", service.LaunchType) // Save cluster in the same format @@ -469,6 +479,10 @@ func resourceAwsEcsServiceUpdate(d *schema.ResourceData, meta interface{}) error _, n := d.GetChange("desired_count") input.DesiredCount = aws.Int64(int64(n.(int))) } + if d.HasChange("health_check_grace_period_seconds") { + _, n := d.GetChange("health_check_grace_period_seconds") + input.HealthCheckGracePeriodSeconds = aws.Int64(int64(n.(int))) + } if d.HasChange("task_definition") { _, n := d.GetChange("task_definition") input.TaskDefinition = aws.String(n.(string)) @@ -646,3 +660,11 @@ func parseTaskDefinition(taskDefinition string) (string, string, error) { return matches[0][1], matches[0][2], nil } + +func validateAwsEcsServiceHealthCheckGracePeriodSeconds(v interface{}, k string) (ws []string, errors []error) { + value := v.(int) + if (value < 0) || (value > 1800) { + errors = append(errors, fmt.Errorf("%q must be between 0 and 1800", k)) + } + return +} diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 2b10eaeaac4..4f754891d29 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -182,6 +182,41 @@ func TestAccAWSEcsServiceWithRenamedCluster(t *testing.T) { }) } +func TestAccAWSEcsService_healthCheckGracePeriodSeconds(t *testing.T) { + rName := acctest.RandomWithPrefix("tf-acc") + resourceName := "aws_ecs_service.with_alb" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEcsServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEcsService_healthCheckGracePeriodSeconds(rName, t.Name(), -1), + ExpectError: regexp.MustCompile(`must be between 0 and 1800`), + }, + { + Config: testAccAWSEcsService_healthCheckGracePeriodSeconds(rName, t.Name(), 1801), + ExpectError: regexp.MustCompile(`must be between 0 and 1800`), + }, + { + Config: testAccAWSEcsService_healthCheckGracePeriodSeconds(rName, t.Name(), 300), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "health_check_grace_period_seconds", "300"), + ), + }, + { + Config: testAccAWSEcsService_healthCheckGracePeriodSeconds(rName, t.Name(), 600), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "health_check_grace_period_seconds", "600"), + ), + }, + }, + }) +} + func TestAccAWSEcsService_withIamRole(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -698,6 +733,138 @@ resource "aws_ecs_service" "main" { `, rInt, rInt, rInt, rInt) } +func testAccAWSEcsService_healthCheckGracePeriodSeconds(rName string, testName string, healthCheckGracePeriodSeconds int) string { + return fmt.Sprintf(` +data "aws_availability_zones" "available" {} + +resource "aws_vpc" "main" { + cidr_block = "10.10.0.0/16" + tags { + Name = "%[2]s" + } +} + +resource "aws_subnet" "main" { + count = 2 + cidr_block = "${cidrsubnet(aws_vpc.main.cidr_block, 8, count.index)}" + availability_zone = "${data.aws_availability_zones.available.names[count.index]}" + vpc_id = "${aws_vpc.main.id}" +} + +resource "aws_ecs_cluster" "main" { + name = "%[1]s" +} + +resource "aws_ecs_task_definition" "with_lb_changes" { + family = "%[1]s" + container_definitions = <