module "ec2_ssh_key" { source = "terraform-aws-modules/key-pair/aws" key_name = join("-", [var.tags.builder, var.tags.project, var.tags.environment]) public_key = var.ssh_public_key tags = var.tags } module "standalone_ec2" { # Create a new list for each ec2_template object for_each = { for idx, val in var.ec2_template : idx => val } source = "terraform-aws-modules/ec2-instance/aws" name = each.value.hostname ami = each.value.ami instance_type = each.value.family key_name = module.ec2_ssh_key.key_pair_name monitoring = true vpc_security_group_ids = [module.ec2_rdp_sg.security_group_id] subnet_id = each.value.subnet root_block_device = [ { volume_size = each.value.disksize encrypted = true } ] tags = var.tags } module "zones" { source = "terraform-aws-modules/route53/aws//modules/zones" version = "~> 2.0" zones = { "clientapp.com" = { comment = "Public facing ALB name." } } tags = var.tags } module "records" { source = "terraform-aws-modules/route53/aws//modules/records" version = "~> 2.0" zone_name = keys(module.zones.route53_zone_zone_id)[0] records = [ { name = "clientapp.com" type = "A" alias = { name = module.loadbalancer.lb_dns_name zone_id = module.loadbalancer.lb_zone_id evaluate_target_health = true } } ] depends_on = [module.zones, module.loadbalancer] }