0

I’m trying to put an ELB in from of my ECS service, using this terraform file

But applying it, gives the below error. Any ideas on the setup that I’ve gotten wrong?

$ terraform apply ...
aws_ecs_task_definition.beatthemarket-task: Refreshing state... (ID: beatthemarket)
aws_ecs_cluster.default: Refreshing state... (ID: arn:aws:ecs:us-west-1:186598327969:cluster/beatthemarket)
aws_iam_role.beathemarket-role: Refreshing state... (ID: beathemarket-role)
aws_elb.beathemarket-elb: Refreshing state... (ID: beathemarket-elb)
aws_ecs_service.beatthemarket_service: Creating...
  cluster:                                 "" => "arn:aws:ecs:us-west-1:186598327969:cluster/beatthemarket"
  deployment_maximum_percent:              "" => "200"
  deployment_minimum_healthy_percent:      "" => "100"
  desired_count:                           "" => "1"
  iam_role:                                "" => "arn:aws:iam::186598327969:role/beathemarket-role"
  load_balancer.#:                         "" => "1"
  load_balancer.2282006059.container_name: "" => "beatthemarket_service"
  load_balancer.2282006059.container_port: "" => "8080"
  load_balancer.2282006059.elb_name:       "" => "beathemarket-elb"
  name:                                    "" => "beatthemarket-service"
  task_definition:                         "" => "arn:aws:ecs:us-west-1:186598327969:task-definition/beatthemarket:2"
Error applying plan:

1 error(s) occurred:

* aws_ecs_service.beatthemarket_service: InvalidParameterException: The container beatthemarket_service does not exist in the task definition.
    status code: 400, request id: 67ef4ee6-08e8-11e6-9b7a-95aa41386391
Frye
  • 253
  • 2
  • 3
  • 11

1 Answers1

0

Panagiotis Moustafellos in the #devopsengineers slack channel actually helped me fix this issue. Turns out that the beatthemarket_service container does not exist. (Confusingly) It's the beatthemarkettask definition name.

So I just replaced

resource "aws_ecs_service" "beatthemarket_service" {
  name            = "beatthemarket-service"
  cluster         = "${aws_ecs_cluster.default.id}"
  task_definition = "${aws_ecs_task_definition.beatthemarket-task.arn}"
  desired_count   = 1
  iam_role = "${aws_iam_role.beatthemarket_role.arn}"
  load_balancer {
    elb_name = "${aws_elb.beathemarket-elb.name}"
    container_name = "beatthemarket_service"
    container_port = 8080
  }
}

with

resource "aws_ecs_service" "beatthemarket_service" {
  name            = "beatthemarket-service"
  cluster         = "${aws_ecs_cluster.default.id}"
  task_definition = "${aws_ecs_task_definition.beatthemarket-task.arn}"
  desired_count   = 1
  iam_role = "${aws_iam_role.beatthemarket_role.arn}"
  load_balancer {
    elb_name = "${aws_elb.beathemarket-elb.name}"
    container_name = "beatthemarket"
    container_port = 8080
  }
}
Frye
  • 253
  • 2
  • 3
  • 11