Skip to content

Commit

Permalink
forceNew and validate propagate_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kl4w committed Dec 5, 2018
1 parent d0e2644 commit 343ddaf
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
6 changes: 6 additions & 0 deletions aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,18 @@ 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": {
Expand Down
79 changes: 77 additions & 2 deletions aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,42 @@ func TestAccAWSEcsService_ManagedTags(t *testing.T) {
testAccCheckAWSEcsServiceExists(resourceName, &service),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "enable_ecs_managed_tags", "true"),
resource.TestCheckResourceAttr(resourceName, "propagate_tags", "SERVICE"),
),
},
},
})
}

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"),
),
},
},
Expand Down Expand Up @@ -2512,7 +2547,6 @@ resource "aws_ecs_service" "test" {
name = %q
task_definition = "${aws_ecs_task_definition.test.arn}"
enable_ecs_managed_tags = true
propagate_tags = "SERVICE"
tags {
tag-key = "tag-value"
Expand All @@ -2521,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 = <<DEFINITION
[
{
"cpu": 128,
"essential": true,
"image": "mongo:latest",
"memory": 128,
"name": "mongodb"
}
]
DEFINITION
tags {
tag-key = "task-def"
}
}
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
propagate_tags = "%s"
tags {
tag-key = "service"
}
}
`, rName, rName, rName, propagate)
}

func testAccAWSEcsServiceWithReplicaSchedulingStrategy(clusterName, tdName, svcName string) string {
return fmt.Sprintf(`
resource "aws_ecs_cluster" "default" {
Expand Down

0 comments on commit 343ddaf

Please sign in to comment.