diff --git a/tf/alb.tf b/tf/alb.tf index 0d125bc..d674f8b 100644 --- a/tf/alb.tf +++ b/tf/alb.tf @@ -71,6 +71,6 @@ resource "aws_lb_listener" "server_https" { resource "aws_autoscaling_attachment" "server" { count = local.ami_available ? 1 : 0 - autoscaling_group_name = aws_autoscaling_group.server[0].name + autoscaling_group_name = aws_autoscaling_group.server[count.index].name alb_target_group_arn = aws_lb_target_group.server.arn } diff --git a/tf/asg.tf b/tf/asg.tf index c245a7b..42e2557 100644 --- a/tf/asg.tf +++ b/tf/asg.tf @@ -38,7 +38,7 @@ resource "aws_launch_template" "server" { count = local.ami_available ? 1 : 0 name = "riju-server" - image_id = data.aws_ami.server[0].id + image_id = data.aws_ami.server[count.index].id instance_type = "t3.small" security_group_names = [aws_security_group.server.name] @@ -81,7 +81,7 @@ resource "aws_autoscaling_group" "server" { max_size = 3 launch_template { - id = aws_launch_template.server[0].id + id = aws_launch_template.server[count.index].id } tags = concat( diff --git a/tf/backup.tf b/tf/backup.tf index 10949b7..ed5e214 100644 --- a/tf/backup.tf +++ b/tf/backup.tf @@ -28,6 +28,6 @@ resource "aws_backup_selection" "riju" { plan_id = aws_backup_plan.riju.id resources = [ - aws_instance.dev_server[0].arn, + aws_instance.dev_server[count.index].arn, ] } diff --git a/tf/ec2.tf b/tf/ec2.tf index f6db8f4..9609330 100644 --- a/tf/ec2.tf +++ b/tf/ec2.tf @@ -31,11 +31,11 @@ resource "aws_security_group" "dev_server" { resource "aws_instance" "dev_server" { count = local.ssh_key_available ? 1 : 0 - ami = data.aws_ami.ubuntu[0].id + ami = data.aws_ami.ubuntu[count.index].id instance_type = "t3.2xlarge" ebs_optimized = true - security_groups = [aws_security_group.dev_server[0].name] + security_groups = [aws_security_group.dev_server[count.index].name] iam_instance_profile = aws_iam_instance_profile.dev_server.name key_name = data.external.env.result.SSH_KEY_NAME @@ -69,6 +69,6 @@ resource "aws_eip" "dev_server" { resource "aws_eip_association" "dev_server" { count = local.ssh_key_available ? 1 : 0 - instance_id = aws_instance.dev_server[0].id - allocation_id = aws_eip.dev_server[0].id + instance_id = aws_instance.dev_server[count.index].id + allocation_id = aws_eip.dev_server[count.index].id }