_This issue was originally opened by @pecigonzalo as hashicorp/terraform#15156. It was migrated here as a result of the provider split. The original body of the issue is below._
0.9.6
[
{
"name": "kafka",
"image": "mydockerrepo/kafka:${kafka_version}",
"memory": 1024,
"cpu": 256,
"essential": true,
"portMappings": [
{
"containerPort": ${kafka_port},
"hostPort": ${kafka_port}
}
],
"environment": [
{"name": "ZK", "value": "${zk_elb_fqdn}:2181"},
{"name": "KAFKA_ADV_PORT", "value": "${kafka_port}"},
{"name": "AUTO_CREATE_TOPICS", "value": true}
]
}
]
data "template_file" "kafka" {
template = "${file("${path.module}/containers/kafka.json.tpl")}"
vars {
kafka_port = "${var.kafkaport}"
kafka_version = "${var.kafkaversion}"
zk_elb_fqdn = "${var.zk_elb_fqdn}"
}
}
resource "aws_ecs_task_definition" "kafka" {
family = "kafka"
container_definitions = "${data.template_file.kafka.rendered}"
}
resource "aws_ecs_service" "kafka" {
name = "kafka"
cluster = "${var.ecs_cluster}"
task_definition = "${aws_ecs_task_definition.kafka.arn}"
desired_count = 1
iam_role = "${var.iam_role}"
deployment_maximum_percent = 100
deployment_minimum_healthy_percent = 50
load_balancer {
elb_name = "${var.kafka_elb_arn}"
container_name = "kafka"
container_port = "${var.kafkaport}"
}
}
md5-0f9da520b680200e22570e8c3b421a75
Error running plan: 1 error(s) occurred:
* aws_ecs_task_definition.kafka: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal bool into Go struct field KeyValuePair.Value of type string
md5-f7eb4b411890796e42da106d1fb8807f
Error running plan: 1 error(s) occurred:
* aws_ecs_service.kafka: 1 error(s) occurred:
* aws_ecs_service.kafka: Resource 'aws_ecs_task_definition.kafka' not found for variable 'aws_ecs_task_definition.kafka.arn'
Using the provided configuration, run terraform plan/apply
Affects 0.10.6
Got bit by this on 0.10.7. It would also be _extremely_ useful if Terraform would start showing the bad data it encounters. Even the debug logs don't show this information, which can make these masked errors downright maddening to track down and fix.
Upstream issue: https://github.com/hashicorp/terraform/issues/14333
Affects 0.11.1
still getting same error..taskdef works from aws console
Error: module.abc.aws_ecs_task_definition.registrar: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal object into Go value of type []*ecs.ContainerDefinition
Terraform v0.11.3
+ provider.aws v1.9.0
+ provider.template v1.0.0
Any update or solution to this error, I'm also getting same eror Error: module.abc.aws_ecs_task_definition.registrar: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal object into Go value of type []*ecs.ContainerDefinition
It seems like the error from JSON parsing is ignored here:
https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_ecs_task_definition.go#L53
This is not trivial to fix, because it's embedded in a function that doesn't return an error itself, so the whole workflow needs to be modified (or just panic).
I am having the a similar problem where I know a valid file is still not being recognized. Here's a valid ECS config file...
[
{
"name": "nginx",
"image": "nginx:alpine",
"memory": 128,
"portMappings": [
{
"containerPort": 80,
"protocol": "tcp"
}
]
}
]
it passes json validation and everything, but it complains with this error.
ECS Task Definition container_definitions is invalid: Error decoding JSON: invalid character '}' after top-level value
Hi folks! 👋 Sorry for the unexpected behavior here.
For the original issue (Resource ... not found for variable
when really it should be a validation error for the task definition JSON), it turns out this is likely an issue upstream in Terraform core, rather than anything to do with the AWS provider specifically. This scenario basically occurs anytime we implement a resource attribute with a ValidateFunc
and then that resource is then referenced by another resource. Terraform core, when the first resource is failing that validation, is preferring to return the invalid resource reference message instead of the resource validation error.
We have a few upstream tracking issues relating to this:
I would suggest commenting on and upvoting those for the latest updates on this. 👍
For the later comments relating to issues where its actually returning a JSON parsing error, please create new issues to consolidate feedback and discussion of those specifically. Thanks!
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!
Most helpful comment
Got bit by this on 0.10.7. It would also be _extremely_ useful if Terraform would start showing the bad data it encounters. Even the debug logs don't show this information, which can make these masked errors downright maddening to track down and fix.