-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcommon.tf
117 lines (95 loc) · 2.41 KB
/
common.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
resource "aws_vpc" "amber" {
cidr_block = "172.17.0.0/16"
tags = {
Name = "${var.prefix}-amber"
}
}
resource "aws_vpc" "green" {
cidr_block = "172.18.0.0/16"
tags = {
Name = "${var.prefix}-green"
}
}
resource "aws_subnet" "amber-lb" {
vpc_id = aws_vpc.amber.id
cidr_block = "172.17.1.0/24"
availability_zone = "${var.region}a"
map_public_ip_on_launch = "true"
tags = {
Name = "${var.prefix}-amber-lb"
}
}
resource "aws_subnet" "amber-vms" {
vpc_id = aws_vpc.amber.id
cidr_block = "172.17.2.0/24"
availability_zone = "${var.region}b"
map_public_ip_on_launch = "true"
tags = {
Name = "${var.prefix}-amber-vms"
}
}
resource "aws_subnet" "green-a" {
vpc_id = aws_vpc.green.id
cidr_block = "172.18.1.0/24"
availability_zone = "${var.region}a"
tags = {
Name = "${var.prefix}-green-a"
}
}
resource "aws_subnet" "green-b" {
vpc_id = aws_vpc.green.id
cidr_block = "172.18.2.0/24"
availability_zone = "${var.region}b"
tags = {
Name = "${var.prefix}-green-b"
}
}
data "aws_caller_identity" "current" {}
resource "aws_vpc_peering_connection" "amber2green" {
vpc_id = "${aws_vpc.amber.id}"
peer_owner_id = "${data.aws_caller_identity.current.account_id}"
peer_vpc_id = "${aws_vpc.green.id}"
auto_accept = true
}
resource "aws_route" "green2amber" {
route_table_id = "${aws_vpc.green.main_route_table_id}"
destination_cidr_block = "${aws_vpc.amber.cidr_block}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.amber2green.id}"
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.amber.id
}
resource "aws_default_route_table" "amber" {
default_route_table_id = aws_vpc.amber.default_route_table_id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
route {
cidr_block = "${aws_vpc.green.cidr_block}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.amber2green.id}"
}
tags = {
Name = "${var.prefix}-amber-internet"
}
}
resource "aws_key_pair" "common-auth" {
key_name = "auth-${var.prefix}"
public_key = "${var.ssh_public_key}"
}
data "aws_ami" "centos" {
owners = ["679593333241"]
most_recent = true
filter {
name = "name"
values = ["AlmaLinux OS 8.7*"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
}