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

resource/aws_ecs_service: Ensure placement_strategy removal in version 2.0.0 does not force recreation #7790

Merged
merged 1 commit into from
Mar 3, 2019

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Mar 1, 2019

Closes #7787

Verified outside the acceptance testing framework as this type of testing is not well supported nor easy to implement for a one-time fix. Theoretically, this can also be prevented with a resource state migration, but that also seems heavy handed for a one-time fix and the extraneous information left in the state should not hurt anything. Lessons learned here will be added to the Terraform Provider development documentation.

Given this version 1.6.0 configuration:

provider "aws" {
  region  = "us-east-2"
  version = "1.6.0"
}

resource "aws_ecs_cluster" "test" {
  name = "bflad-testing"
}

resource "aws_ecs_task_definition" "test" {
  family                = "test"
  container_definitions = <<DEFINITION
[
  {
    "cpu": 128,
    "essential": true,
    "image": "busybox:latest",
    "memory": 128,
    "name": "busybox"
  }
]
DEFINITION
}

resource "aws_ecs_service" "test" {
  cluster = "${aws_ecs_cluster.test.id}"
  desired_count = 0
  name = "bflad-testing"
  task_definition = "${aws_ecs_task_definition.test.arn}"

  placement_strategy {
    field = "memory"
    type = "binpack"
  }

  placement_strategy {
    field = "attribute:ecs.availability-zone"
    type = "spread"
  }
}

And attempting to upgrade the configuration to version 2.0.0 like the below:

provider "aws" {
  region  = "us-east-2"
  version = "2.0.0"
}

resource "aws_ecs_cluster" "test" {
  name = "bflad-testing"
}

resource "aws_ecs_task_definition" "test" {
  family                = "test"
  container_definitions = <<DEFINITION
[
  {
    "cpu": 128,
    "essential": true,
    "image": "busybox:latest",
    "memory": 128,
    "name": "busybox"
  }
]
DEFINITION
}

resource "aws_ecs_service" "test" {
  cluster = "${aws_ecs_cluster.test.id}"
  desired_count = 0
  name = "bflad-testing"
  task_definition = "${aws_ecs_task_definition.test.arn}"

  ordered_placement_strategy {
    field = "memory"
    type = "binpack"
  }

  ordered_placement_strategy {
    field = "attribute:ecs.availability-zone"
    type = "spread"
  }
}

Would yield the following:

$ terraform plan
...
Terraform will perform the following actions:

-/+ aws_ecs_service.test (new resource required)
...
      ordered_placement_strategy.#:        "2" => "2"
      ordered_placement_strategy.0.field:  "memory" => "memory"
      ordered_placement_strategy.0.type:   "binpack" => "binpack"
      ordered_placement_strategy.1.field:  "attribute:ecs.availability-zone" => "attribute:ecs.availability-zone"
      ordered_placement_strategy.1.type:   "spread" => "spread"
      placement_strategy.#:                "2" => "0" (forces new resource)
      placement_strategy.2224589570.field: "memory" => "" (forces new resource)
      placement_strategy.2224589570.type:  "binpack" => "" (forces new resource)
      placement_strategy.3619322362.field: "attribute:ecs.availability-zone" => "" (forces new resource)
      placement_strategy.3619322362.type:  "spread" => "" (forces new resource)
...

Plan: 1 to add, 0 to change, 1 to destroy.

These changes here yield the expected no-operation change:

$ cp ~/go/bin/terraform-provider-aws .terraform/plugins/darwin_amd64/terraform-provider-aws_v2.0.0_x4; terraform init # Overwrite with locally built binary with this change
...
$ terraform plan
...
No changes. Infrastructure is up-to-date.

…n 2.0.0 does not force recreation

References:
* #7787

Verified outside the acceptance testing framework as this type of testing is not well supported nor easy to implement, especially for a one-time fix. Theoretically, this can also be prevented with a resource state migration, but that also seems heavy handed for a one-time fix and the extraneous information left in the state should not hurt anything. Lessons learned here will be added to the Terraform Provider development documentation.

Given this version 1.6.0 configuration:

```hcl
provider "aws" {
  region  = "us-east-2"
  version = "1.6.0"
}

resource "aws_ecs_cluster" "test" {
  name = "bflad-testing"
}

resource "aws_ecs_task_definition" "test" {
  family                = "test"
  container_definitions = <<DEFINITION
[
  {
    "cpu": 128,
    "essential": true,
    "image": "busybox:latest",
    "memory": 128,
    "name": "busybox"
  }
]
DEFINITION
}

resource "aws_ecs_service" "test" {
  cluster = "${aws_ecs_cluster.test.id}"
  desired_count = 0
  name = "bflad-testing"
  task_definition = "${aws_ecs_task_definition.test.arn}"

  placement_strategy {
    field = "memory"
    type = "binpack"
  }

  placement_strategy {
    field = "attribute:ecs.availability-zone"
    type = "spread"
  }
}
```

And attempting to upgrade the configuration to version 2.0.0 like the below:

```hcl
provider "aws" {
  region  = "us-east-2"
  version = "2.0.0"
}

resource "aws_ecs_cluster" "test" {
  name = "bflad-testing"
}

resource "aws_ecs_task_definition" "test" {
  family                = "test"
  container_definitions = <<DEFINITION
[
  {
    "cpu": 128,
    "essential": true,
    "image": "busybox:latest",
    "memory": 128,
    "name": "busybox"
  }
]
DEFINITION
}

resource "aws_ecs_service" "test" {
  cluster = "${aws_ecs_cluster.test.id}"
  desired_count = 0
  name = "bflad-testing"
  task_definition = "${aws_ecs_task_definition.test.arn}"

  ordered_placement_strategy {
    field = "memory"
    type = "binpack"
  }

  ordered_placement_strategy {
    field = "attribute:ecs.availability-zone"
    type = "spread"
  }
}
```

Would yield the following:

```console
$ terraform plan
...
Terraform will perform the following actions:

-/+ aws_ecs_service.test (new resource required)
...
      ordered_placement_strategy.#:        "2" => "2"
      ordered_placement_strategy.0.field:  "memory" => "memory"
      ordered_placement_strategy.0.type:   "binpack" => "binpack"
      ordered_placement_strategy.1.field:  "attribute:ecs.availability-zone" => "attribute:ecs.availability-zone"
      ordered_placement_strategy.1.type:   "spread" => "spread"
      placement_strategy.#:                "2" => "0" (forces new resource)
      placement_strategy.2224589570.field: "memory" => "" (forces new resource)
      placement_strategy.2224589570.type:  "binpack" => "" (forces new resource)
      placement_strategy.3619322362.field: "attribute:ecs.availability-zone" => "" (forces new resource)
      placement_strategy.3619322362.type:  "spread" => "" (forces new resource)
...

Plan: 1 to add, 0 to change, 1 to destroy.
```

These changes here yield the expected no-operation change:

```console
$ cp ~/go/bin/terraform-provider-aws .terraform/plugins/darwin_amd64/terraform-provider-aws_v2.0.0_x4; terraform init # Overwrite with locally built binary with this change
...
$ terraform plan
...
No changes. Infrastructure is up-to-date.
```
@bflad bflad added bug Addresses a defect in current functionality. service/ecs Issues and PRs that pertain to the ecs service. labels Mar 1, 2019
@bflad bflad added this to the v2.1.0 milestone Mar 1, 2019
@bflad bflad requested a review from a team March 1, 2019 20:42
@ghost ghost added the size/XS Managed by automation to categorize the size of a PR. label Mar 1, 2019
Copy link
Contributor

@tracypholmes tracypholmes left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@bflad bflad merged commit c7e9331 into master Mar 3, 2019
@bflad bflad deleted the b-aws_ecs_service-placement_strategy-computed branch March 3, 2019 15:30
bflad added a commit that referenced this pull request Mar 3, 2019
bflad added a commit to hashicorp/terraform-website that referenced this pull request Mar 5, 2019
…te removal with Computed/ForceNew and resource soft removal with friendly error messages

References:
* hashicorp/terraform-provider-aws#7815
* hashicorp/terraform-provider-aws#7790
@bflad
Copy link
Contributor Author

bflad commented Mar 8, 2019

This has been released in version 2.1.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Mar 31, 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 Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ecs Issues and PRs that pertain to the ecs service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
2 participants