Terraform - Resource not found for variable despite having it declared in the same file
For those experiencing an issue with aws_ecs_task_definition
not finding a variable for the aws_ecs_task_definition.XXX.arn
, there's a good chance your JSON came out malformed. Here's what I did to remedy my issue
- Replace your line with
task_definition = "[]"
- Run
terraform plan
At this point you should get an error. For example, I got
module.tf.aws_ecs_task_definition.sandbox: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal string into Go struct field ContainerDefinition.MemoryReservation of type int64
In this case, I had quoted memSize
in my template_file
and it didn't implicitly convert to int64, hence an error.
I changed "memoryReservation": "${mem_size}"
to "memoryReservation": ${mem_size}
, removed the task_definition placeholder, and everything went smoothly.
I believe your role declaration could be slightly wrong. And terraform was not able to generate an arn for that, therefore not found.
It looks like you also need to create resource "aws_iam_role_policy"
. See https://www.terraform.io/docs/providers/aws/r/codepipeline.html
It's a bit unclear why you'd need to split.
If this is not the case, let me know and I'll try to run the code myself to test.
To help out with investigating such issues, you can run targeted terraform plan
.
In my case (misconfigured reference to CIDR block from custom AWS VPC module), after running
terraform plan --target aws_security_group.something-or-other
Terraform actually provided clear error message on what exactly i did wrong this time. Hope it helps :)