Skip to content

Commit

Permalink
Update AWS VPC Terraform templates to include additional subnets for ASG
Browse files Browse the repository at this point in the history
  • Loading branch information
nilgaar committed Jul 16, 2024
1 parent d53860e commit e88be5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions IaC/aws/tofu/asg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource "aws_lb" "lb" {
name = "asg-example-lb"
load_balancer_type = "application"
security_groups = [aws_security_group.sec_group.id]
subnets = [aws_subnet.asg_subnet.id]
subnets = [aws_subnet.asg_subnet_1.id, aws_subnet.asg_subnet_2.id]
}

resource "aws_lb_listener" "lb_listener" {
Expand All @@ -36,7 +36,7 @@ resource "aws_autoscaling_group" "asg_example" {
min_size = 1
health_check_grace_period = 300
launch_configuration = aws_launch_configuration.launch_configuration.name
vpc_zone_identifier = [aws_subnet.asg_subnet.id]
vpc_zone_identifier = [aws_subnet.asg_subnet_1.id]
target_group_arns = [aws_lb_target_group.lb_target_group.arn]
health_check_type = "ELB"

Expand Down
10 changes: 8 additions & 2 deletions IaC/aws/tofu/vpc_network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ resource "aws_subnet" "ec2_subnet" {
map_public_ip_on_launch = true
}

resource "aws_subnet" "asg_subnet" {
resource "aws_subnet" "asg_subnet_1" {
vpc_id = aws_vpc.vpc.id
availability_zone = var.availability_zone
cidr_block = "10.0.1.0/24"
}

resource "aws_subnet" "asg_subnet_2" {
vpc_id = aws_vpc.vpc.id
availability_zone = var.availability_zone
cidr_block = "10.0.2.0/24"
}

resource "aws_route_table" "route_table" {
vpc_id = aws_vpc.vpc.id

Expand All @@ -35,7 +41,7 @@ resource "aws_route_table_association" "route_table_association_ec2" {
}

resource "aws_route_table_association" "route_table_association_asg" {
subnet_id = aws_subnet.asg_subnet.id
subnet_id = aws_subnet.asg_subnet_1.id
route_table_id = aws_route_table.route_table.id
}

Expand Down

0 comments on commit e88be5e

Please sign in to comment.