-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
65 lines (50 loc) · 1.56 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
provider "aws" {
region = var.region
}
resource "aws_vpc" "vpc" {
cidr_block = var.cidr_block
tags = var.tags
}
resource "aws_subnet" "public_subnet" {
availability_zone = join("",[var.region, var.availability_zone])
cidr_block = cidrsubnet(var.cidr_block, 8, 0)
map_public_ip_on_launch = true
vpc_id = aws_vpc.vpc.id
tags = var.tags
}
resource "aws_internet_gateway" "internet_gateway" {
vpc_id = aws_vpc.vpc.id
tags = var.tags
}
resource "aws_route_table" "public_routetable" {
vpc_id = aws_vpc.vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.internet_gateway.id
}
tags = var.tags
}
resource "aws_route_table_association" "public_routetable_association" {
route_table_id = aws_route_table.public_routetable.id
subnet_id = aws_subnet.public_subnet.id
}
resource "aws_security_group" "webserver-sg" {
name = "webserver-sg"
description = "Security Group for HTTP Webserver"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# As Terraform overwrides the AWS default for SGs to be outbound open on every port,
# we need to create a corresponding egress rule in our SG resource
egress {
from_port = 0 # Must be 0 if every protocol ("all") is allowed
to_port = 0 # Must be 0 if every protocol ("all") is allowed
protocol = -1 # Semantically equivalent to "all"
cidr_blocks = ["0.0.0.0/0"]
}
vpc_id = aws_vpc.vpc.id
tags = var.tags
}