Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/ecs_service: add enable_ecs_managed_tags attribute #6544

Merged
merged 1 commit into from
Nov 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func resourceAwsEcsService() *schema.Resource {
},
},

"enable_ecs_managed_tags": {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be setting ForceNew: true? From what I can see, this property is only configurable during the initial creation of a service and not for UpdateService API. If I try to flip it on for an existing service, TF plan repeatedly tries to re-set it back to true because the updates aren't going through.

Type: schema.TypeBool,
Optional: true,
Default: false,
},

"health_check_grace_period_seconds": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -329,11 +335,12 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error
schedulingStrategy := d.Get("scheduling_strategy").(string)

input := ecs.CreateServiceInput{
ClientToken: aws.String(resource.UniqueId()),
SchedulingStrategy: aws.String(schedulingStrategy),
ServiceName: aws.String(d.Get("name").(string)),
Tags: tagsFromMapECS(d.Get("tags").(map[string]interface{})),
TaskDefinition: aws.String(d.Get("task_definition").(string)),
ClientToken: aws.String(resource.UniqueId()),
SchedulingStrategy: aws.String(schedulingStrategy),
ServiceName: aws.String(d.Get("name").(string)),
Tags: tagsFromMapECS(d.Get("tags").(map[string]interface{})),
TaskDefinition: aws.String(d.Get("task_definition").(string)),
EnableECSManagedTags: aws.Bool(d.Get("enable_ecs_managed_tags").(bool)),
}

if schedulingStrategy == ecs.SchedulingStrategyDaemon && deploymentMinimumHealthyPercent != 100 {
Expand Down Expand Up @@ -538,6 +545,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)
d.Set("enable_ecs_managed_tags", service.EnableECSManagedTags)

// Save cluster in the same format
if strings.HasPrefix(d.Get("cluster").(string), "arn:"+meta.(*AWSClient).partition+":ecs:") {
Expand Down
58 changes: 58 additions & 0 deletions aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,28 @@ func TestAccAWSEcsService_Tags(t *testing.T) {
})
}

func TestAccAWSEcsService_ManagedTags(t *testing.T) {
var service ecs.Service
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_ecs_service.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcsServiceConfigManagedTags(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists(resourceName, &service),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "enable_ecs_managed_tags", "true"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Generally its good to verify the default value in one of the "basic" acceptance tests somewhere too 👍

),
},
},
})
}

func testAccCheckAWSEcsServiceDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ecsconn

Expand Down Expand Up @@ -2293,6 +2315,42 @@ resource "aws_ecs_service" "test" {
`, rName, rName, rName, tag1Key, tag1Value, tag2Key, tag2Value)
}

func testAccAWSEcsServiceConfigManagedTags(rName string) string {
return fmt.Sprintf(`
resource "aws_ecs_cluster" "test" {
name = %q
}

resource "aws_ecs_task_definition" "test" {
family = %q

container_definitions = <<DEFINITION
[
{
"cpu": 128,
"essential": true,
"image": "mongo:latest",
"memory": 128,
"name": "mongodb"
}
]
DEFINITION
}

resource "aws_ecs_service" "test" {
cluster = "${aws_ecs_cluster.test.id}"
desired_count = 0
name = %q
task_definition = "${aws_ecs_task_definition.test.arn}"
enable_ecs_managed_tags = true

tags {
tag-key = "tag-value"
}
}
`, rName, rName, rName)
}

func testAccAWSEcsServiceWithReplicaSchedulingStrategy(clusterName, tdName, svcName string) string {
return fmt.Sprintf(`
resource "aws_ecs_cluster" "default" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ecs_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ The following arguments are supported:
* `iam_role` - (Optional) ARN of the IAM role that allows Amazon ECS to make calls to your load balancer on your behalf. This parameter is required if you are using a load balancer with your service, but only if your task definition does not use the `awsvpc` network mode. If using `awsvpc` network mode, do not specify this role. If your account has already created the Amazon ECS service-linked role, that role is used by default for your service unless you specify a role here.
* `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. Not valid when using the `DAEMON` scheduling strategy.
* `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.
* `enable_ecs_managed_tasks` - (Optional) Specifies whether to enable Amazon ECS managed tags for the tasks within the service.
* `placement_strategy` - (Optional) **Deprecated**, use `ordered_placement_strategy` instead.
* `ordered_placement_strategy` - (Optional) Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. The maximum number of `ordered_placement_strategy` blocks is `5`. Defined below.
* `health_check_grace_period_seconds` - (Optional) Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 7200. Only valid for services configured to use load balancers.
Expand Down