terraform-provider-aws: data.aws_ecs_task_definition: Failed getting task definition
Terraform Version
0.9.11.
- aws_ecs_task_definition
Terraform Configuration Files
data "aws_ecs_task_definition" "my-service" {
task_definition = "${aws_ecs_task_definition.my-service.family}"
}
resource "aws_ecs_task_definition" "my-service" {
family = "${var.environment_name}-${var.service_name}-${var.instance_name}"
network_mode = "bridge"
container_definitions = "${data.template_file.my-service.rendered}"
}
resource "aws_ecs_service" "my-service" {
...
#Track the latest ACTIVE revision
task_definition = "${aws_ecs_task_definition.my-services.family}:${max("${aws_ecs_task_definition.my-service.revision}", "${data.aws_ecs_task_definition.my-service.revision}")}"
...
}
Expected Behavior
if resource not exists create new aws_ecs_task_definition else use latest aws_ecs_task_definition version
this code vork fine in Terraform v0.9.2
Actual Behavior
: Failed getting task definition ClientException: Unable to describe task definition. status code: 400, request id: “my-service”
Steps to Reproduce
terraform apply
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 32
- Comments: 28 (9 by maintainers)
Commits related to this issue
- data.aws_ecs_task_definition: Failed getting task definition (#6) Fix in PR. See: https://github.com/terraform-providers/terraform-provider-aws/issues/1274#issuecomment-331332157 — committed to duduribeiro/terraform_ecs_fargate_example by jumbojett 5 years ago
- Provide a working example for ecs-task-definition This is working around the issue of not having a task definition when the resources are initially rolled out. Background: The documetation example ... — committed to skorfmann/terraform-provider-aws by deleted user 5 years ago
I was able to get around this issue by adding a “depends_on” to the data source:
Hope it helps.
This issue isn’t very clear to me. Seems like some folks claim that we should NOT be using a depends_on in the datasource for the task definition but upon the first run it always fails because the resource doesnt exist.
Ya I probably should of tried the fix before replying, it works but it causes continuous change detection to occur. Which is not the expected/desired result
Actually, what I said is a lie, looks like there is a problem when you have an invalid JSON for container definitions and mine is not using the heredoc syntax but a json file with a template and it should be an array of containers and i have only one main object. Here where I found out about it https://github.com/terraform-providers/terraform-provider-aws/issues/2026
FYI for everybody else stumbling over the issue: @skorfmann illustrated in this MR https://github.com/terraform-providers/terraform-provider-aws/pull/10247 a better workaround using
aws_ecs_task_definition.self.revisionand explains why the discusseddepends_onapproach is not what you want!Diving into debugging… I’ve noticed that
func dataSourceAwsEcsTaskDefinitionReaddoes not get called in a vanilla project, but does in an existing one. This appears to be a terraform pattern. I was able to reproduce this by creating a simple resource first (a security group) then trying to perform a lookup. The plan failed when a resource was already present in a statefile (the security group in this case). I verified my hypothesis by also creating a different data source which looked up a non-existent security group. The plan for this also failed.