Hi folks
I have a need to create a output variable that returns all the nested values from the replication instance resource I’m creating that uses a map of objects variable in a for_each loop (to create multiple dms replcation instances). I used to do this at my last place so know it’s possible but so far have only gotten it working with a single attribute(see my outputs.tf snip). My googling searches have been fruitless so far. Can anyone give me a syntax example of this please? So to clarify I’m wanting to create a “replication_instance_outputs” output variable that returns all the attributes for each replication instance created e.g. replication_instance_class, engine_version etc
snip of variables .tf
# Replication Instances
variable "replication_instances" {
description = "Map of objects that define the replication instances to be created"
type = any
default = {}
}
snip of main.tf
resource "aws_dms_replication_instance" "this" {
for_each = { for k, v in var.replication_instances : k => v if var.create }
replication_instance_id = each.key
replication_instance_class = lookup(each.value, "repl_instance_class", null)
allocated_storage = lookup(each.value, "repl_instance_allocated_storage", 50)
auto_minor_version_upgrade = lookup(each.value, "repl_instance_auto_minor_version_upgrade", null)
allow_major_version_upgrade = lookup(each.value, "repl_instance_allow_major_version_upgrade", null)
apply_immediately = lookup(each.value, "repl_instance_apply_immediately", null)
availability_zone = lookup(each.value, "repl_availability_zone", null)
engine_version = lookup(each.value, "repl_instance_engine_version", null)
kms_key_arn = lookup(each.value, "repl_kms_key_arn", null)
multi_az = lookup(each.value, "repl_instance_multi_az", false)
preferred_maintenance_window = lookup(each.value, "repl_instance_preferred_maintenance_window", null)
publicly_accessible = lookup(each.value, "repl_instance_publicly_accessible", false)
replication_subnet_group_id = lookup(each.value, "replication_subnet_group_id", null)
vpc_security_group_ids = lookup(each.value, "repl_instance_vpc_security_group_ids", null)
tags = merge(var.tags, var.repl_instance_tags)
timeouts {
create = lookup(var.repl_instance_timeouts, "create", null)
update = lookup(var.repl_instance_timeouts, "update", null)
delete = lookup(var.repl_instance_timeouts, "delete", null)
}
depends_on = [time_sleep.wait_for_dependency_resources]
}
snip of outputs.tf
# Instance
output "replication_instance_arn" {
description = "The Amazon Resource Name (ARN) of the replication instances"
value = values(aws_dms_replication_instance.this)[*].replication_instance_arn
}