diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index 27542633fe2..a7a55400b8b 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -127,6 +127,20 @@ func resourceAwsEcsService() *schema.Resource { }, }, }, + Set: func(v interface{}) int { + var buf bytes.Buffer + m := v.(map[string]interface{}) + buf.WriteString(fmt.Sprintf("%s-", m["type"].(string))) + if m["field"] != nil { + field := m["field"].(string) + if field == "host" { + buf.WriteString("instanceId-") + } else { + buf.WriteString(fmt.Sprintf("%s-", field)) + } + } + return hashcode.String(buf.String()) + }, }, "placement_constraints": { diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index c3a60354756..bc79d813ad1 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -108,6 +108,23 @@ func TestAccAWSEcsServiceWithARN(t *testing.T) { }) } +func TestAccAWSEcsServiceWithUnnormalizedPlacementStrategy(t *testing.T) { + rInt := acctest.RandInt() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEcsServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEcsServiceWithInterchangeablePlacementStrategy(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists("aws_ecs_service.mongo"), + ), + }, + }, + }) +} + func TestAccAWSEcsServiceWithFamilyAndRevision(t *testing.T) { rName := acctest.RandomWithPrefix("tf-test") resource.Test(t, resource.TestCase{ @@ -431,6 +448,40 @@ resource "aws_ecs_service" "mongo" { `, rInt, rInt) } +func testAccAWSEcsServiceWithInterchangeablePlacementStrategy(rInt int) string { + return fmt.Sprintf(` +resource "aws_ecs_cluster" "default" { + name = "terraformecstest%d" +} + +resource "aws_ecs_task_definition" "mongo" { + family = "mongodb" + container_definitions = < **Note:** for `spread`, `host` and `instanceId` will be normalized, by AWS, to be `instanceId`. This means the statefile will show `instanceId` but your config will differ if you use `host`. + ## placement_constraints `placement_constraints` support the following: