|
| 1 | +# Create the VPC |
| 2 | +resource "aws_vpc" "app_vpc" { |
| 3 | + cidr_block = var.vpc_cidr_block |
| 4 | + enable_dns_hostnames = var.enable_dns_hostnames |
| 5 | + |
| 6 | + tags = merge(var.common_tags, { |
| 7 | + Name = "${var.name_prefix}-vpc" |
| 8 | + }) |
| 9 | +} |
| 10 | + |
| 11 | +# Create the internet gateway |
| 12 | +resource "aws_internet_gateway" "igw" { |
| 13 | + vpc_id = aws_vpc.app_vpc.id |
| 14 | + |
| 15 | + tags = merge(var.common_tags, { |
| 16 | + Name = "${var.name_prefix}-igw" |
| 17 | + }) |
| 18 | +} |
| 19 | + |
| 20 | +# Create the public subnet |
| 21 | +resource "aws_subnet" "public_subnet" { |
| 22 | + vpc_id = aws_vpc.app_vpc.id |
| 23 | + cidr_block = var.vpc_public_subnets_cidr_block |
| 24 | + map_public_ip_on_launch = true |
| 25 | + availability_zone = var.aws_azs |
| 26 | + |
| 27 | + tags = merge(var.common_tags, { |
| 28 | + Name = "${var.name_prefix}-pubsubnet" |
| 29 | + }) |
| 30 | + |
| 31 | +} |
| 32 | + |
| 33 | +# Create the route table |
| 34 | +resource "aws_route_table" "public_rt" { |
| 35 | + vpc_id = aws_vpc.app_vpc.id |
| 36 | + |
| 37 | + route { |
| 38 | + cidr_block = "0.0.0.0/0" |
| 39 | + gateway_id = aws_internet_gateway.igw.id |
| 40 | + } |
| 41 | + |
| 42 | +} |
| 43 | + |
| 44 | +# Assign the public route table to the public subnet |
| 45 | +resource "aws_route_table_association" "public_rt_asso" { |
| 46 | + subnet_id = aws_subnet.public_subnet.id |
| 47 | + route_table_id = aws_route_table.public_rt.id |
| 48 | +} |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +# Create the security group |
| 53 | +resource "aws_security_group" "sg" { |
| 54 | + name = "allow_ssh_http" |
| 55 | + description = "Allow ssh http inbound traffic" |
| 56 | + vpc_id = aws_vpc.app_vpc.id |
| 57 | + |
| 58 | + ingress { |
| 59 | + from_port = 3389 |
| 60 | + to_port = 3389 |
| 61 | + protocol = "tcp" |
| 62 | + cidr_blocks = ["0.0.0.0/0"] |
| 63 | + ipv6_cidr_blocks = ["::/0"] |
| 64 | + } |
| 65 | + |
| 66 | + ingress { |
| 67 | + description = "HTTP from VPC" |
| 68 | + from_port = 80 |
| 69 | + to_port = 80 |
| 70 | + protocol = "tcp" |
| 71 | + cidr_blocks = ["0.0.0.0/0"] |
| 72 | + ipv6_cidr_blocks = ["::/0"] |
| 73 | + } |
| 74 | + |
| 75 | + egress { |
| 76 | + from_port = 0 |
| 77 | + to_port = 0 |
| 78 | + protocol = "-1" |
| 79 | + cidr_blocks = ["0.0.0.0/0"] |
| 80 | + ipv6_cidr_blocks = ["::/0"] |
| 81 | + } |
| 82 | + |
| 83 | +} |
0 commit comments