Hi all.
I am trying to build some AWS maintenance windows and in each of them i need to put individual tasks for a list of servers. I have used “chunklist” to split the initial list into multiple pieces but now i am stuck at adding the targets for the tasks. As each list contains 20 instance ids i would like to add each one as a target in a specific task.
The instances are not AWS EC2 but Hybrid activations that i get from a local file. my code is below:
resource "aws_ssm_maintenance_window" "available-patches-scan-***********" {
count = length(local.chunk)
name = "available_patches_***********-scan-${count.index}"
allow_unassociated_targets = "true"
cutoff = "1"
duration = "2"
enabled = "true"
schedule = "rate(30 days)"
start_date = local.date_available_patches
}
resource "aws_ssm_maintenance_window_task" "available-patches-scan-***********-task" {
count = length(local.chunk)
//for_each = local.expanded_names[count.index]
window_id = aws_ssm_maintenance_window.available-patches-scan-***********[count.index].id
name = "available-patches-scan-***********-task-${count.index}"
description = "This is a maintenance window task"
task_type = "RUN_COMMAND"
task_arn = "AWS-RunPatchBaseline"
priority = 1
service_role_arn = "arn:aws:iam::***********:role/***********"
max_concurrency = "7"
max_errors = "10"
dynamic "targets" {
for_each = flatten(local.chunk[count.index])
content {
key = "InstanceIds"
values = targets.value
}
}
task_invocation_parameters {
run_command_parameters {
service_role_arn = "arn:aws:iam::***********:role/***********"
notification_config {
notification_arn = "arn:aws:sns:eu-west-1:***********:patching-scan"
notification_events = ["All"]
notification_type = "Invocation"
}
parameter {
name = "Operation"
values = ["Scan"]
}
}
}
}
and the error is:
Error: Incorrect attribute value type
on available-patches-scan.tf line 29, in resource “aws_ssm_maintenance_window_task” “available-patches-scan-*********-task”:
29: values = targets.value
Inappropriate value for attribute “values”: list of string required.
How can i fix this?