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

Commits on Mar 1, 2019

  1. resource/aws_ecs_service: Ensure placement_strategy removal in versio…

    …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 committed Mar 1, 2019
    Configuration menu
    Copy the full SHA
    b782d72 View commit details
    Browse the repository at this point in the history