4

We are using terraform to import a ECS solution and for some reason, I can not get pass this error.

aws_ecs_task_definition.clustername: ClientException: Container.name should not be null or empty. 09-Feb-2017 23:35:1 status code: 400

I believe this is coming form this json file, service-prod-server.json

#aws_ecs_task_definition
resource "aws_ecs_task_definition" "cluster-name" {
  family = "cluster-name"
  container_definitions = "${file("task-definitions/service-prod-server.json")}"
}

Here is the top portion of the service-prod-server.json config. I have the name there.

[
  {
    "name": "containername",
    "memory": 7000,
    "image": "imagename",
    "disableNetworking": false,
    "readonlyRootFilesystem": false,

I also have this config defined as well.

#aws_ecs_container_definition
data "aws_ecs_container_definition" "cluster-name" {
  task_definition = "${aws_ecs_task_definition.cluster-name.id}"
  container_name = "containername"
}

Let me know what you guys think

3
  • 1
    It looks like it works, but what about the directory structure? Commented Feb 11, 2017 at 7:53
  • 1
    Would you mind sharing the whole service-prod-server.json config (omitting any secret stuff you may have there)? That might help us reproducing the error. Commented Feb 13, 2017 at 15:39
  • Looks like it did work, I had to delete the existing environment. Once I did that and did a push, it worked. Commented Feb 13, 2017 at 17:29

2 Answers 2

10

For me, I labeled the environment variable key incorrectly:

{ "key": "myvariable", "value": "myvalue" }

instead of

{ "name": "myvariable", "value": "myvalue" }

The difference is that I wrote key instead of name and that broke the whole container definition, which gave me this error.

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't answer the original question which was specifically about Container.name, however I upvote because I had the exact same issue, googling brought me here, and this syntax helped me fix my problem, I was doing something like { "myvariable": "value"} - I hadn't provided the name at all, so thanks!
This answer helped me as I had made the same mistake causing Terraform to ignore my key/value pairs and set environment to {}. Thank You.
8

For what it's worth, I got this same error in Terraform when trying to pass an entire task definition to container_definitions. Note that the container_definitions option should only be set to the containerDefinitions section of the task definition (not the entire thing).

1 Comment

When you put it this way it seems so obvious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.