Skip to content

Commit bd836f3

Browse files
committed
NRL-1385 create vpc module
1 parent 70c2e55 commit bd836f3

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "subnet_id" {
2+
value = aws_subnet.public_subnet.id
3+
}
4+
5+
output "security_group" {
6+
value = [aws_security_group.sg.id]
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "aws_region" {}
2+
variable "aws_azs" {}
3+
variable "enable_dns_hostnames" {}
4+
variable "vpc_cidr_block" {}
5+
variable "vpc_public_subnets_cidr_block" {}
6+
variable "common_tags" {}
7+
variable "name_prefix" {}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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

Comments
 (0)