diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index 8382de552f2..bbe88552b9e 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -301,6 +301,23 @@ func resourceAwsEcsService() *schema.Resource { }, }, + "propagate_tags": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + if old == "NONE" && new == "" { + return true + } + return false + }, + ValidateFunc: validation.StringInSlice([]string{ + ecs.PropagateTagsService, + ecs.PropagateTagsTaskDefinition, + "", + }, false), + }, + "service_registries": { Type: schema.TypeSet, Optional: true, @@ -395,6 +412,10 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error input.LaunchType = aws.String(v.(string)) } + if v, ok := d.GetOk("propagate_tags"); ok { + input.PropagateTags = aws.String(v.(string)) + } + loadBalancers := expandEcsLoadBalancers(d.Get("load_balancer").(*schema.Set).List()) if len(loadBalancers) > 0 { log.Printf("[DEBUG] Adding ECS load balancers: %s", loadBalancers) @@ -574,6 +595,7 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error { d.Set("health_check_grace_period_seconds", service.HealthCheckGracePeriodSeconds) d.Set("launch_type", service.LaunchType) d.Set("enable_ecs_managed_tags", service.EnableECSManagedTags) + d.Set("propagate_tags", service.PropagateTags) // Save cluster in the same format if strings.HasPrefix(d.Get("cluster").(string), "arn:"+meta.(*AWSClient).partition+":ecs:") { diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 0afaba3f7e3..f38e77bdf50 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -830,6 +830,42 @@ func TestAccAWSEcsService_ManagedTags(t *testing.T) { }) } +func TestAccAWSEcsService_PropagateTags(t *testing.T) { + var first, second, third 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: testAccAWSEcsServiceConfigPropagateTags(rName, "SERVICE"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists(resourceName, &first), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "propagate_tags", ecs.PropagateTagsService), + ), + }, + { + Config: testAccAWSEcsServiceConfigPropagateTags(rName, "TASK_DEFINITION"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists(resourceName, &second), + resource.TestCheckResourceAttr(resourceName, "propagate_tags", ecs.PropagateTagsTaskDefinition), + ), + }, + { + Config: testAccAWSEcsServiceConfigManagedTags(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists(resourceName, &third), + resource.TestCheckResourceAttr(resourceName, "propagate_tags", "NONE"), + ), + }, + }, + }) +} + func testAccCheckAWSEcsServiceDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).ecsconn @@ -2519,6 +2555,47 @@ resource "aws_ecs_service" "test" { `, rName, rName, rName) } +func testAccAWSEcsServiceConfigPropagateTags(rName, propagate string) string { + return fmt.Sprintf(` +resource "aws_ecs_cluster" "test" { + name = %q +} + +resource "aws_ecs_task_definition" "test" { + family = %q + + container_definitions = <