diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dbdde4a6..e73840179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ IMPROVEMENTS: * provider/aws: `aws_lambda_function` resources now support VPC configuration [GH-5149] * provider/openstack: Add support for Distributed Routers [GH-4878] * provider/openstack: Add support for optional cacert_file parameter [GH-5106] + * provider/aws: Add support for deployment configuration to `aws_ecs_service` [GH-5220] BUG FIXES: diff --git a/builtin/providers/aws/resource_aws_ecs_service.go b/builtin/providers/aws/resource_aws_ecs_service.go index a066388ee..8d1135f86 100644 --- a/builtin/providers/aws/resource_aws_ecs_service.go +++ b/builtin/providers/aws/resource_aws_ecs_service.go @@ -55,6 +55,18 @@ func resourceAwsEcsService() *schema.Resource { Optional: true, }, + "deployment_maximum_percent": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Default: 200, + }, + + "deployment_minimum_healthy_percent": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Default: 100, + }, + "load_balancer": &schema.Schema{ Type: schema.TypeSet, Optional: true, @@ -94,6 +106,10 @@ 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))), + }, } if v, ok := d.GetOk("cluster"); ok { @@ -208,6 +224,11 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error { } } + if service.DeploymentConfiguration != nil { + d.Set("deployment_maximum_percent", *service.DeploymentConfiguration.MaximumPercent) + d.Set("deployment_minimum_healthy_percent", *service.DeploymentConfiguration.MinimumHealthyPercent) + } + if service.LoadBalancers != nil { d.Set("load_balancers", flattenEcsLoadBalancers(service.LoadBalancers)) } @@ -233,6 +254,13 @@ func resourceAwsEcsServiceUpdate(d *schema.ResourceData, meta interface{}) error input.TaskDefinition = aws.String(n.(string)) } + if 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))), + } + } + out, err := conn.UpdateService(&input) if err != nil { return err diff --git a/builtin/providers/aws/resource_aws_ecs_service_test.go b/builtin/providers/aws/resource_aws_ecs_service_test.go index fcac09ba5..1d1733996 100644 --- a/builtin/providers/aws/resource_aws_ecs_service_test.go +++ b/builtin/providers/aws/resource_aws_ecs_service_test.go @@ -178,6 +178,26 @@ func TestAccAWSEcsService_withIamRole(t *testing.T) { }) } +func TestAccAWSEcsService_withDeploymentValues(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEcsServiceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSEcsServiceWithDeploymentValues, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists("aws_ecs_service.mongo"), + resource.TestCheckResourceAttr( + "aws_ecs_service.mongo", "deployment_maximum_percent", "200"), + resource.TestCheckResourceAttr( + "aws_ecs_service.mongo", "deployment_minimum_healthy_percent", "100"), + ), + }, + }, + }) +} + // Regression for https://github.com/hashicorp/terraform/issues/3444 func TestAccAWSEcsService_withLbChanges(t *testing.T) { resource.Test(t, resource.TestCase{ @@ -418,6 +438,34 @@ resource "aws_ecs_service" "ghost" { } ` +var testAccAWSEcsServiceWithDeploymentValues = ` +resource "aws_ecs_cluster" "default" { + name = "terraformecstest1" +} + +resource "aws_ecs_task_definition" "mongo" { + family = "mongodb" + container_definitions = < **Note:** To prevent race condition during service deletion, make sure to set `depends_on` to related `aws_iam_role_policy`, otherwise policy may be destroyed too soon and ECS service will then stuck in `DRAINING` state. -Provides an ECS service - effectively a task that is expected to run until an error occures or user terminates it (typically a webserver or a database). +Provides an ECS service - effectively a task that is expected to run until an error occures or user terminates it (typically a webserver or a database). See [ECS Services section in AWS developer guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html). @@ -42,6 +42,8 @@ The following arguments are supported: * `desired_count` - (Required) The number of instances of the task definition to place and keep running * `cluster` - (Optional) ARN of an ECS cluster * `iam_role` - (Optional) IAM role that allows your Amazon ECS container agent to make calls to your load balancer on your behalf. This parameter is only required if you are using a load balancer with your service. +* `deployment_maximum_percent` - (Optional) The upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment. +* `deployment_minimum_healthy_percent` - (Optional) The lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. * `load_balancer` - (Optional) A load balancer block. Load balancers documented below. Load balancers support the following: