Skip to content

Commit

Permalink
Added a private subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
rishavnandi committed Mar 13, 2023
1 parent 671e78d commit 70651c2
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ resource "aws_vpc" "tf_vpc" {
}
}

resource "aws_subnet" "tf_subnet" {
resource "aws_subnet" "tf_public_subnet" {
vpc_id = aws_vpc.tf_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
map_public_ip_on_launch = true

tags = {
Name = "tf_subnet"
Name = "tf_public_subnet"
}
}

resource "aws_subnet" "tf_private_subnet" {
vpc_id = aws_vpc.tf_vpc.id
cidr_block = "10.0.2.0/24"
availability_zone = "us-east-1a"

tags = {
Name = "tf_private_subnet"
}

}

resource "aws_internet_gateway" "tf_igw" {
vpc_id = aws_vpc.tf_vpc.id

Expand All @@ -43,7 +54,7 @@ resource "aws_route_table" "tf_rt" {
}

resource "aws_route_table_association" "tf_rta" {
subnet_id = aws_subnet.tf_subnet.id
subnet_id = aws_subnet.tf_public_subnet.id
route_table_id = aws_route_table.tf_rt.id
}

Expand All @@ -58,20 +69,6 @@ resource "aws_security_group" "tf_sg" {
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 5000
to_port = 5000
Expand Down Expand Up @@ -107,10 +104,15 @@ data "aws_ami" "tf_ami" {
resource "aws_instance" "tf_instance" {
ami = data.aws_ami.tf_ami.id
instance_type = "t2.micro"
subnet_id = aws_subnet.tf_subnet.id
subnet_id = aws_subnet.tf_public_subnet.id
vpc_security_group_ids = [aws_security_group.tf_sg.id]
private_ip = "10.0.1.100"

tags = {
Name = "tf_instance"
}
}

output "aws_instance_public_ip" {
value = aws_instance.tf_instance.public_ip
}

0 comments on commit 70651c2

Please sign in to comment.