Hi,
I’m trying to create a module for ECS to use scheduled tasks. I can get an ecs cluster, service and task definition created but running into an issue when including the cloudwacth_events module.
Error: Invalid value for module argument
main.tf line 89, in module "events":
ecs_target = [
{
task_count = 1
task_definition_arn = module.ecs.ecs_task_arn
}
]
The given value is not suitable for child module variable "ecs_target" defined
at ..\terraform_aws_modules\monitoring\cloudwatch\events\variable.tf:47,1-22:
element 0: element "task_definition_arn": string required.
The plan looks like the below:
module “ecs” {
source = "../terraform_aws_modules/compute/ecs/"
create_cluster = true
create_service = true
cluster_name = "test_cluster"
capacity_providers = ["FARGATE"]
service_name = ["test-service"]
launch_type = "FARGATE"
scheduling_strategy = "REPLICA"
platform_version = "LATEST"
desired_count = 0
enable_ecs_managed_tags = true
propagate_tags = "TASK_DEFINITION"
assign_public_ips = false
ecs_subnet_ids = []
security_groups = []
family = ["test"]
container_definitions = file("service.json")
requires_compatibilities = toset(["FARGATE"])
network_mode = "awsvpc"
memory = 512
cpu = 256
execution_role_arn = module.iam.iam_role_arn
task_role_arn = module.iam.iam_role_arn
}
module "events" {
source = "../terraform_aws_modules/monitoring/cloudwatch/events"
name = "test"
target_id = "test"
schedule_expression = ["cron(0 6 * * ? *)"]
role_arn = module.iam.iam_role_arn
arn = module.ecs.ecs_cluster_arn
ecs_target = [
{
task_count = 1
task_definition_arn = module.ecs.ecs_task_arn
}
]
}
The cloudwatch_event_target resource block is below:
resource "aws_cloudwatch_event_target" "this" {
count = var.enable_event && length(var.name) > 0 ? length(var.name) : 0
rule = aws_cloudwatch_event_rule.this[count.index].name
arn = element(var.arn, count.index)
target_id = var.target_id
role_arn = var.role_arn
dynamic "ecs_target" {
for_each = var.ecs_target
content {
group = lookup(ecs_target.value, "group", null)
launch_type = lookup(ecs_target.value, "launch_type", null)
platform_version = lookup(ecs_target.value, "platform_version", null)
task_count = lookup(ecs_target.value, "task_count", null)
task_definition_arn = lookup(ecs_target.value, "task_definition_arn", null)
And the ecs task output is:
output "ecs_task_arn" {
description = "ARN of task definition"
value = aws_ecs_task_definition.this.*.arn
}
Where am i going wrong?