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_task_definition" still shows as modified each time terraform is applied, "portMappings" is set #6376

Closed
keith-miller opened this issue Nov 6, 2018 · 6 comments
Labels
service/ecs Issues and PRs that pertain to the ecs service.

Comments

@keith-miller
Copy link

Terraform Version

Terraform v0.11.10

  • provider.aws v1.42.0
  • provider.template v1.0.0

Affected Resource(s)

  • aws_ecs_task_definition

Terraform Configuration Files

data "template_file" "service_task_json" {
  template = "${file("../../task_definitions/service.json")}"

  vars {
    role           = "gateway"
    cpu            = "${var.gw_cpu_count}"
    mem            = "${var.gw_memory_size}"
    region         = "${var.region}"
    project        = "${var.project_name}"
    env            = "${var.project_environment}"
    ecr_url        = "${var.ecr_url}"
    port           = 8080
    xms            = "${var.gw_xms}"
    xmx            = "${var.gw_xmx}"
    xmn            = "${var.gw_xmn}"
    survivor_ratio = "${var.gw_survivor_ratio}"
    metaspace_size = "${var.gw_metaspace_size}"
  }
}

resource "aws_ecs_task_definition" "service_task" {
  family = "${var.project_role}-${var.project_environment}-task"
  execution_role_arn = "${var.exec_role}"
  network_mode = "awsvpc"
  container_definitions = "${data.template_file.service_task_json.rendered}"
  requires_compatibilities = ["FARGATE"]
  cpu = "${var.desired_cpu}"
  memory = "${var.desired_memory}"
}

service.json

[
  {
    "cpu": ${cpu},
    "memory": ${mem},
    "name": "${role}",
    "image": "${ecr_url}/${project}_${role}:${env}",
    "portMappings": [{
      "containerPort": ${port},
      "hostPort": ${port},
      "protocol": "tcp"
    }],
    "essential": true,
    "environment" : [
      {
        "name": "XMS",
        "value": "${xms}"
      },
      {
        "name": "XMX",
        "value": "${xmx}"
      },
      {
        "name": "XMN",
        "value": "${xmn}"
      },
      {
        "name": "SURVIVOR_RATIO",
        "value": "${survivor_ratio}"
      },
      {
        "name": "MAX_METASPACE_SIZE",
        "value": "${metaspace_size}"
      },
      {
        "name": "APP_ENV",
        "value": "${env}"
      }
    ],
    "logConfiguration": {
      "logDriver" : "awslogs",
      "options": {
        "awslogs-create-group" : "true",
        "awslogs-region" : "${region}",
        "awslogs-group" : "awslogs-${role}-${env}",
        "awslogs-stream-prefix" : "${role}-${env}"
      }
    },
    "mountPoints": [],
    "volumesFrom": []
  }
]

Debug Output

Expected Behavior

No resources should show as changed

Actual Behavior

aws_ecs_task_definition shows as modified which in turn rebuild that resource

-/+ module.gateway.aws_ecs_task_definition.service_task (new resource required)
  container_definitions:               "[...]" => "${var.container_definitions}" (forces new resource)

Steps to Reproduce

  1. terraform apply

References

@keith-miller
Copy link
Author

#5323 is closed, but I am seeing this still on latest.

@bflad bflad added the service/ecs Issues and PRs that pertain to the ecs service. label Nov 6, 2018
@keith-miller
Copy link
Author

Would guess it has to do with the string to JSON unmarshaling. I will test without environment set to see if that 'fixes' the issue.

@keith-miller
Copy link
Author

It's not environment, it's logConfiguration.options. The order is changing.

@bflad
Copy link
Contributor

bflad commented Nov 14, 2018

We do have a built-in library for ECS Task Definition equivalence: https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/ecs_task_definition_equivalency.go

It likely requires some additional logic to properly handle that situation. e.g. another sort.Slice()

@keith-miller
Copy link
Author

Closing, as this was on me and due to the issue here: hashicorp/terraform#15491

@ghost
Copy link

ghost commented Apr 1, 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 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/ecs Issues and PRs that pertain to the ecs service.
Projects
None yet
Development

No branches or pull requests

2 participants