-
Notifications
You must be signed in to change notification settings - Fork 26
/
vpc-secondary.tf
92 lines (84 loc) · 2.07 KB
/
vpc-secondary.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* VPC.
*
* Virtual network which will be referred to as "secondary" in this example.
*/
resource "aws_vpc" "secondary" {
cidr_block = "10.0.0.0/16"
}
/**
* Internet gateway (IGW).
*
* Gateway which allows traffic to/from the "secondary" VPC to the public
* internet.
*/
resource "aws_internet_gateway" "secondary" {
vpc_id = aws_vpc.secondary.id
}
/**
* Route rule.
*
* Directs all traffic (which doesn't match another route) to the IGW.
*/
resource "aws_route" "secondary-internet_access" {
route_table_id = aws_vpc.secondary.main_route_table_id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.secondary.id
}
/**
* Subnet.
*
* /24 subnet for availability zone "a".
*/
resource "aws_subnet" "secondary-az1" {
vpc_id = aws_vpc.secondary.id
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
availability_zone = "${var.region}a"
}
/**
* Subnet.
*
* /24 subnet for availability zone "b".
*/
resource "aws_subnet" "secondary-az2" {
vpc_id = aws_vpc.secondary.id
cidr_block = "10.0.2.0/24"
map_public_ip_on_launch = true
availability_zone = "${var.region}b"
}
/**
* Security group.
*
* Basic security group with the following rules:
* - Inbound traffic on port 80 restricted to private IPs.
* - Inbound traffic on port 22 unrestricted (enables us to setup instances
* and run tests).
* - Outbound traffic unrestricted.
*/
resource "aws_security_group" "secondary-default" {
name_prefix = "default-"
description = "Default security group for all instances in VPC ${aws_vpc.secondary.id}"
vpc_id = aws_vpc.secondary.id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = [
aws_vpc.primary.cidr_block,
aws_vpc.secondary.cidr_block,
]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}