I'm having a problem with my terraform configuration for AWS, i hope someone can help me out.
I have a production variable that i utilize to create an RDS cluster:
resource "aws_rds_cluster" "cluster" {
count = "${var.production ? 1 : 0}"
...
}
So obviously, the resource is ctreated if production = true. In another resource i want to reference the endpoint attribute of this cluster, if production was set to true. If not, i want to use another variable:
module "ecs" {
aws_ecs_taskdefinition-environmentVariable-list = <<EOF
[
{ "name" : "SomeName", "value" : "${var.production ? aws_rds_cluster.cluster.endpoint : var.ENV_DATABASE_HOST}:3306" },
]
EOF
}
The issue i'm having, is that when production is false, it is as if terraform tries to resolve the 'aws_rds_cluster.cluster.endpoint', even though that is not the value supposed to be used. And that obviously fails, since in production that resource has count 0:
module.ecs.var.aws_ecs_taskdefinition-environmentVariable-list: Resource 'aws_rds_cluster.cluster' not found for variable 'aws_rds_cluster.cluster.endpoint'
I have the same kind of issue in the relation between a securityGroup and a securityGroupRule for that RDS cluster. Even though the count of the rule is set to 0, it seems like terraform tries to resolve the id of the group it references, which it obviously cant because the group also have a count of 0.
ecsmodule and using a data source to fetch it from there? It would cause you an issue on the first plan if the RDS cluster hadn't yet been created but you could potentially separate the RDS cluster and the ECS stuff into separate parts for Terraform to work on. - ydaetskcoR