#Associate Public Subnets to Public Route Table
resource "aws_route_table" "public_route_table" {
  vpc_id = aws_vpc.vpc.id

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.internet_gateway.id
  }

  tags = {
    Name = "${var.client_name}_public_route_table"
  }
}

resource "aws_route_table_association" "public_subnet_a" {
  subnet_id      = aws_subnet.public_a.id
  route_table_id = aws_route_table.public_route_table.id
}
resource "aws_route_table_association" "public_subnet_b" {
  subnet_id      = aws_subnet.public_b.id
  route_table_id = aws_route_table.public_route_table.id
}

#########################################################
# Associate database Subnets with Database Route Table  #
#########################################################
resource "aws_route_table" "db_private_route_table" {
  vpc_id = aws_vpc.vpc.id

  tags = {
    Name = "${var.client_name}_db_private_route_table"
  }
}

resource "aws_route_table_association" "db_private_subnet_a" {
  subnet_id      = aws_subnet.mysql_db_a.id
  route_table_id = aws_route_table.db_private_route_table.id
}

resource "aws_route_table_association" "db_private_subnet_b" {
  subnet_id      = aws_subnet.mysql_db_b.id
  route_table_id = aws_route_table.db_private_route_table.id
}
