I am unable to create an ECS task definition due to the following error:
- aws_ecs_task_definition.ee_ecs_spike_task_def: Error decoding JSON: json: cannot unmarshal object into Go value of type []*ecs.ContainerDefinition
I have manually created a task using the exact same JSON via both the web interface and CLI successfully. My JSON is:
{
"containerDefinitions": [
{
"volumesFrom": [],
"memory": 512,
"portMappings": [
{
"hostPort": 80,
"containerPort": 8080,
"protocol": "tcp"
}
],
"essential": true,
"mountPoints": [],
"name": "ee_ecs_spike_repo",
"environment": [],
"image": "897486716820.dkr.ecr.us-east-1.amazonaws.com/ee_ecs_spike_repo:latest",
"cpu": 2
}
],
"volumes": [],
"family": "ee_ecs_spike"
}
My terraform file is:
resource "aws_ecs_task_definition" "ee_ecs_spike_task_def" {
family = "ee_ecs_spike"
container_definitions = "${file("spike-definition.json")}"
}
Trace/Debug output did not display any additional errors:
aws_ecs_task_definition.ee_ecs_spike_task_def: Creating...
arn: "" => "<computed>"
container_definitions: "" => "0ebf6354fd0b8df80d715c3b60f1831018e2f508"
family: "" => "ee_ecs_spike"
revision: "" => "<computed>"
2016/03/04 16:22:32 [DEBUG] root: eval: *terraform.EvalWriteState
2016/03/04 16:22:32 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2016/03/04 16:22:32 [DEBUG] root: eval: *terraform.EvalIf
2016/03/04 16:22:32 [DEBUG] root: eval: *terraform.EvalWriteDiff
2016/03/04 16:22:32 [DEBUG] root: eval: *terraform.EvalIf
2016/03/04 16:22:32 [DEBUG] root: eval: *terraform.EvalWriteState
2016/03/04 16:22:32 [DEBUG] root: eval: *terraform.EvalApplyPost
2016/03/04 16:22:32 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:
* aws_ecs_task_definition.ee_ecs_spike_task_def: Error decoding JSON: json: cannot unmarshal object into Go value of type []*ecs.ContainerDefinition
2016/03/04 16:22:32 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:
* aws_ecs_task_definition.ee_ecs_spike_task_def: Error decoding JSON: json: cannot unmarshal object into Go value of type []*ecs.ContainerDefinition
2016/03/04 16:22:32 [ERROR] root: eval: *terraform.EvalOpFilter, err: 1 error(s) occurred:
* aws_ecs_task_definition.ee_ecs_spike_task_def: Error decoding JSON: json: cannot unmarshal object into Go value of type []*ecs.ContainerDefinition
2016/03/04 16:22:32 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:
* aws_ecs_task_definition.ee_ecs_spike_task_def: Error decoding JSON: json: cannot unmarshal object into Go value of type []*ecs.ContainerDefinition
2016/03/04 16:22:32 [TRACE] [walkApply] Exiting eval tree: aws_ecs_task_definition.ee_ecs_spike_task_def
2016/03/04 16:22:32 [DEBUG] vertex provider.aws (close), got dep: aws_ecs_task_definition.ee_ecs_spike_task_def
2016/03/04 16:22:32 [DEBUG] waiting for all plugin processes to complete...
You are using it wrong. Task definition are only section inside containerDefinitions.
For you it would be:
[
{
"volumesFrom": [],
"memory": 512,
"portMappings": [
{
"hostPort": 80,
"containerPort": 8080,
"protocol": "tcp"
}
],
"essential": true,
"mountPoints": [],
"name": "ee_ecs_spike_repo",
"environment": [],
"image": "897486716820.dkr.ecr.us-east-1.amazonaws.com/ee_ecs_spike_repo:latest",
"cpu": 2
}
]
Hi @TravisHanna,
@aldarund is correct, we expect list of containers in container_definitions
field as per the documentation.
Feel free to reopen this issue if you're still struggling to make your example work.
Thanks much. That solved my problem.
I think it might be worth updating the doc examples. Makes sense after the fact though. :)
Is it possible to improve the error message here?
The above task definition and the Terraform documentation does not work for Fargate.
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
You are using it wrong. Task definition are only section inside containerDefinitions.
For you it would be: