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

ECS Service 'Host' Placement Strategy Forcing Service Rebuild #938

Closed
woodyza opened this issue Jun 22, 2017 · 2 comments · Fixed by #1025
Closed

ECS Service 'Host' Placement Strategy Forcing Service Rebuild #938

woodyza opened this issue Jun 22, 2017 · 2 comments · Fixed by #1025

Comments

@woodyza
Copy link

woodyza commented Jun 22, 2017

Small thing: if you use the field host in a placement strategy of type spread within an ECS Service definition a service rebuild will occur on every apply. This looks to be a similar issue to #13216 over in the main repo, except instead of case differences it's an interchangeable term.

host and instanceId are interchangeable and mean the same thing (docs) but it seems the AWS CLI will always return instanceId irrespective of which is originally specified when creating the resource, which I'm picking is the cause of the issue.

Terraform Version

terraform -v
Terraform v0.9.8

Affected Resource(s)

Please list the resources as a list, for example:

  • aws_ecs_service

Terraform Configuration Files

resource "aws_ecs_service" "dd_agent_service" {
  name            = "dd-agent"
  cluster         = "${aws_ecs_cluster.api_cluster.id}"
  task_definition = "${aws_ecs_task_definition.dd_agent_task.arn}"
  desired_count   = "1"

  placement_strategy {
    type  = "spread"
    field = "host"
  }
}

Debug Output

Sorry not a debug but the plan output shows enough detail to spot the issue I think:

-/+ aws_ecs_service.dd_agent_service
    cluster:                             "arn:aws:ecs:us-east-1:__REDACTED__:cluster/__REDACTED__" => "arn:aws:ecs:us-east-1:__REDACTED__:cluster/__REDACTED__"
    deployment_maximum_percent:          "200" => "200"
    deployment_minimum_healthy_percent:  "100" => "100"
    desired_count:                       "1" => "1"
    name:                                "dd-agent" => "dd-agent"
    placement_strategy.#:                "1" => "1"
    placement_strategy.1427850681.field: "" => "host" (forces new resource)
    placement_strategy.1427850681.type:  "" => "spread" (forces new resource)
    placement_strategy.3946258308.field: "instanceId" => "" (forces new resource)
    placement_strategy.3946258308.type:  "spread" => "" (forces new resource)
    task_definition:                     "arn:aws:ecs:us-east-1:__REDACTED__:task-definition/dd-agent-task:3" => "arn:aws:ecs:us-east-1:__REDACTED__:task-definition/dd-agent-task:3"

Expected Behavior

No change to the service resource, since there is no change to the placement strategy

Actual Behavior

The service resource will be destroyed and recreated on every terraform apply.

Steps to Reproduce

  1. Create an ECS service using a placement strategy spread with field host
  2. terraform apply to create
  3. terraform apply without changing any tf config will force a new resource

Important Factoids

Perfectly acceptable workaround is to just use instanceId, but I figured it was worth reporting this anyway

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

  • #13216 in the main repository
stack72 added a commit that referenced this issue Jun 30, 2017
Fixes: #938

When aws_ecs_service has a placement_strategy of type `spread`, you can
use a field of `instanceId` or `host` interchangable. BUT AWS will normalize the
field value to return `instanceId`.

We have introduced a custom Set func to manage this work so that we
understand when someone uses `host`, we won't get a diff when AWS return
`instanceId` -> if there is a diff, a ForceNew is applied

```
% make testacc TEST=./aws TESTARGS='-run=TestAccAWSEcsService'                                                                  ✹
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSEcsService -timeout 120m
=== RUN   TestAccAWSEcsServiceWithARN
--- PASS: TestAccAWSEcsServiceWithARN (147.06s)
=== RUN   TestAccAWSEcsServiceWithUnnormalizedPlacementStrategy
--- PASS: TestAccAWSEcsServiceWithUnnormalizedPlacementStrategy (116.97s)
=== RUN   TestAccAWSEcsServiceWithFamilyAndRevision
--- PASS: TestAccAWSEcsServiceWithFamilyAndRevision (125.69s)
=== RUN   TestAccAWSEcsServiceWithRenamedCluster
--- PASS: TestAccAWSEcsServiceWithRenamedCluster (268.02s)
=== RUN   TestAccAWSEcsService_withIamRole
--- PASS: TestAccAWSEcsService_withIamRole (155.57s)
=== RUN   TestAccAWSEcsService_withDeploymentValues
--- PASS: TestAccAWSEcsService_withDeploymentValues (128.80s)
=== RUN   TestAccAWSEcsService_withLbChanges
--- PASS: TestAccAWSEcsService_withLbChanges (242.82s)
=== RUN   TestAccAWSEcsService_withEcsClusterName
--- PASS: TestAccAWSEcsService_withEcsClusterName (113.21s)
=== RUN   TestAccAWSEcsService_withAlb
--- PASS: TestAccAWSEcsService_withAlb (349.69s)
=== RUN   TestAccAWSEcsServiceWithPlacementStrategy
--- PASS: TestAccAWSEcsServiceWithPlacementStrategy (238.08s)
=== RUN   TestAccAWSEcsServiceWithPlacementConstraints
--- PASS: TestAccAWSEcsServiceWithPlacementConstraints (123.41s)
=== RUN   TestAccAWSEcsServiceWithPlacementConstraints_emptyExpression
--- PASS: TestAccAWSEcsServiceWithPlacementConstraints_emptyExpression (126.25s)
PASS
ok	github.com/terraform-providers/terraform-provider-aws/aws	2138.968s
```
stack72 added a commit that referenced this issue Jun 30, 2017
#1025)

Fixes: #938

When aws_ecs_service has a placement_strategy of type `spread`, you can
use a field of `instanceId` or `host` interchangable. BUT AWS will normalize the
field value to return `instanceId`.

We have introduced a custom Set func to manage this work so that we
understand when someone uses `host`, we won't get a diff when AWS return
`instanceId` -> if there is a diff, a ForceNew is applied

```
% make testacc TEST=./aws TESTARGS='-run=TestAccAWSEcsService'                                                                  ✹
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSEcsService -timeout 120m
=== RUN   TestAccAWSEcsServiceWithARN
--- PASS: TestAccAWSEcsServiceWithARN (147.06s)
=== RUN   TestAccAWSEcsServiceWithUnnormalizedPlacementStrategy
--- PASS: TestAccAWSEcsServiceWithUnnormalizedPlacementStrategy (116.97s)
=== RUN   TestAccAWSEcsServiceWithFamilyAndRevision
--- PASS: TestAccAWSEcsServiceWithFamilyAndRevision (125.69s)
=== RUN   TestAccAWSEcsServiceWithRenamedCluster
--- PASS: TestAccAWSEcsServiceWithRenamedCluster (268.02s)
=== RUN   TestAccAWSEcsService_withIamRole
--- PASS: TestAccAWSEcsService_withIamRole (155.57s)
=== RUN   TestAccAWSEcsService_withDeploymentValues
--- PASS: TestAccAWSEcsService_withDeploymentValues (128.80s)
=== RUN   TestAccAWSEcsService_withLbChanges
--- PASS: TestAccAWSEcsService_withLbChanges (242.82s)
=== RUN   TestAccAWSEcsService_withEcsClusterName
--- PASS: TestAccAWSEcsService_withEcsClusterName (113.21s)
=== RUN   TestAccAWSEcsService_withAlb
--- PASS: TestAccAWSEcsService_withAlb (349.69s)
=== RUN   TestAccAWSEcsServiceWithPlacementStrategy
--- PASS: TestAccAWSEcsServiceWithPlacementStrategy (238.08s)
=== RUN   TestAccAWSEcsServiceWithPlacementConstraints
--- PASS: TestAccAWSEcsServiceWithPlacementConstraints (123.41s)
=== RUN   TestAccAWSEcsServiceWithPlacementConstraints_emptyExpression
--- PASS: TestAccAWSEcsServiceWithPlacementConstraints_emptyExpression (126.25s)
PASS
ok	github.com/terraform-providers/terraform-provider-aws/aws	2138.968s
```
@woodyza
Copy link
Author

woodyza commented Jun 30, 2017

Thanks! 👍

@ghost
Copy link

ghost commented Apr 11, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant