-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
executable file
·288 lines (247 loc) · 10.3 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
terraform {
required_version = ">=0.12.6"
# required_providers = {
# aws = {
# source = "hashicorp/aws"
# }
# }
}
provider "aws" {
region = "us-east-2"
}
variable "sg_whitelist_cidr_blocks" {
type = list(string)
default = ["192.55.79.160/27",
"198.175.68.32/27",
"192.55.54.32/27",
"192.55.55.32/27",
"134.191.232.64/27",
"134.191.233.192/27",
"192.198.151.32/27",
"134.191.227.32/27",
"134.134.139.64/27",
"134.134.137.64/27",
"134.191.220.64/27",
"134.191.221.64/27",
"192.198.146.160/27",
"192.198.147.160/27",
"192.102.204.32/27",
"192.55.46.32/27",
"134.191.196.160/27",
"134.191.197.160/27"]
}
resource "aws_key_pair" "my-identity-pem" {
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCWL0jMtMdtfnoG8C9szpuz/sgEdzvw1F1f+i9Y+Pf3ajLJEhuyscFDMaNkT6g9KV5w6LPyLqUWGD4p+6MWq2JGV0AE2Jw/YEiscLGN0sCJJcZ8p99lOxzZFtD8B9H32hdoNfdQfvA6Ae0T0WI9nngXfmZBb9r6JiBietdK/nwGEzh1FGA76pCN6FCFYAK6VDpKfdPObLKWkqJW/SBP1bKBmhpcTUPdWu6pNnrgpBL3A6MXpp4Fh+nNrs4+jMRzy+btVA5ZAnCjbjnD7xj8Z8sQiZSO0rVEU8FLwVIJMDQNS2z0CYjZlVCH9MMIOC9NISRr19Uj7S5XWxZ6+8TtZiyGFfxXmLk/8SSvMWVZ+c8d9xlSk3qIxn9vPddZH8CxJQaGK8hNZzNV+MUfk77k6F+NOouzcbtyjdBHuGvke7iaNj08okO7Twdib4zhNIPFkuBgBOUC10XLjPV1ug6DKiTRdA3LO5x5edXqAzh0WITQyvRWP4Q8DfDfVRNLFSi8leiT42ZjZY4fNyAnDt8+ybd1Fst/+DKGVIPYE/4Nh8vzrlwIFYhjA7tWDd94JBo3bwgkZvRCPZ9Zm2EWHMf9d7fvx4N42qzr0SIzqNnuOmVxJ4+3A8ZEJ93R8tY44BV7zDUTIW+9inIbyYBwkgfbCgdcxXGPugUbQGzJQAtz3lHQgQ== amr\rgesteve@rgesteve-dev"
key_name = "MyIdentity.pem"
}
resource "aws_default_security_group" "allow_ssh_from_intel" {
#name = "single_node_secgroup"
#description = "Simple Security Group for a single EC2 instance"
vpc_id = aws_vpc.gabe_vpc.id
ingress {
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = var.sg_whitelist_cidr_blocks
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [ "10.0.0.0/16" ]
}
}
resource "aws_vpc" "gabe_vpc" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "gabe_subnet" {
vpc_id = aws_vpc.gabe_vpc.id
cidr_block = cidrsubnet("10.0.0.0/16", 8, 1)
map_public_ip_on_launch = true
}
resource "aws_internet_gateway" "gabe_igw" {
vpc_id = aws_vpc.gabe_vpc.id
}
resource "aws_default_route_table" "gabe_route_table" {
default_route_table_id = aws_vpc.gabe_vpc.default_route_table_id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gabe_igw.id
}
}
# data "template_file" "user_data" {
# template = file("cloud-init.yml")
# }
# data "cloudinit_config" "testclinit" {
# gzip = false
# base64_encode = false
# part {
# filename = "/home/ubuntu/set-up-crank.sh"
# content_type = "text/x-shellscript"
# content = file("set-up-crank.sh")
# }
# }
resource "aws_instance" "instance_1" {
instance_type = "t2.nano"
#instance_type = "m7i.4xlarge"
ami = "ami-05d251e0fc338590c"
subnet_id = aws_subnet.gabe_subnet.id
associate_public_ip_address = true
key_name = aws_key_pair.my-identity-pem.key_name
#security_groups = [aws_security_group.allow_ssh_from_intel.name]
vpc_security_group_ids = [aws_default_security_group.allow_ssh_from_intel.id]
#user_data = data.template_file.user_data.rendered
#user_data = file("cloud-init.yml")
#user_data = templatefile("cloud-init.yml", { app_ip = aws_instance.app_fake.private_ip })
user_data = templatefile("cloud-init.yml", { app_ip = aws_instance.app.private_ip,
db_ip = aws_instance.db.private_ip,
load_ip = aws_instance.loadgen.private_ip,
ssh_key = aws_key_pair.my-identity-pem.key_name,
machine = aws_instance.app.instance_type })
#user_data = data.cloudinit_config.testclinit.rendered
# Not sure how to pass the Intel proxy spec (scp -o "ProxyCommand=nc -x proxy-us.intel.com:1080 %h %p" -i <private_key> <source> <destination>)
# connection {
# type = "ssh"
# host = self.public_ip
# user = "ubuntu"
# private_key = file(aws_key_pair.my-identity-pem.key_name)
# }
# provisioner "file" {
# source = "MyIdentity.pem"
# destination = "/home/ubuntu/MyIdentity.pem"
# # Apparently terraform allows you to place the connection block nested in the instance or on the provisioner.
# # I have it in the instance because I might want to copy more than one file.
# # connection {
# # type = "ssh"
# # host = self.public_ip
# # user = "ubuntu"
# # private_key = file(aws_key_pair.my-identity-pem.key_name)
# # }
# }
# provisioner "local-exec" {
# command = "scp -i ${aws_key_pair.my-identity-pem.key_name} -o StrictHostKeyChecking=no ${aws_key_pair.my-identity-pem.key_name} ubuntu@${self.public_ip}:/home/ubuntu"
# }
tags = {
Name = "rgesteve-crank-controller"
}
}
# resource "aws_instance" "instance_2" {
# instance_type = "t2.nano"
# #instance_type = "m7i.4xlarge"
# ami = "ami-05d251e0fc338590c"
# subnet_id = aws_subnet.gabe_subnet.id
# associate_public_ip_address = true
# key_name = aws_key_pair.my-identity-pem.key_name
# #security_groups = [aws_security_group.allow_ssh_from_intel.name]
# vpc_security_group_ids = [aws_default_security_group.allow_ssh_from_intel.id]
# tags = {
# Name = "rgesteve-crank-controller"
# }
# }
# resource "aws_instance" "app_fake" {
# instance_type = "t2.nano"
# ami = "ami-05d251e0fc338590c"
# subnet_id = aws_subnet.gabe_subnet.id
# key_name = aws_key_pair.my-identity-pem.key_name
# vpc_security_group_ids = [aws_default_security_group.allow_ssh_from_intel.id]
# tags = {
# Name = "rgesteve-crank-appfake"
# }
# }
resource "aws_instance" "app" {
# SPR
instance_type = "m7i.4xlarge"
ami = "ami-05d251e0fc338590c"
# Graviton3 (ARM)
#instance_type = "m7g.8xlarge"
#ami = "ami-0b5801d081fa3a76c"
subnet_id = aws_subnet.gabe_subnet.id
key_name = aws_key_pair.my-identity-pem.key_name
#security_groups = [aws_security_group.allow_ssh_from_intel.name]
vpc_security_group_ids = [aws_default_security_group.allow_ssh_from_intel.id]
#private_ip = "${cidrhost(aws_vpc.gabe_vpc.cidr_block, 20 + count.index)}"
user_data = file("cloud-init-worker.yml")
tags = {
Name = "rgesteve-crank-app"
}
}
# resource "aws_instance" "worker" {
# count = 2
# # instance_type = "t2.nano"
# instance_type = "m7i.xlarge"
# ami = "ami-05d251e0fc338590c"
# subnet_id = aws_subnet.gabe_subnet.id
# key_name = aws_key_pair.my-identity-pem.key_name
# #security_groups = [aws_security_group.allow_ssh_from_intel.name]
# vpc_security_group_ids = [aws_default_security_group.allow_ssh_from_intel.id]
# #private_ip = "${cidrhost(aws_vpc.gabe_vpc.cidr_block, 20 + count.index)}"
# tags = {
# Name = "rgesteve-crank-worker"
# }
# }
resource "aws_instance" "loadgen" {
instance_type = "m7i.4xlarge"
ami = "ami-05d251e0fc338590c"
subnet_id = aws_subnet.gabe_subnet.id
key_name = aws_key_pair.my-identity-pem.key_name
#security_groups = [aws_security_group.allow_ssh_from_intel.name]
vpc_security_group_ids = [aws_default_security_group.allow_ssh_from_intel.id]
#private_ip = "${cidrhost(aws_vpc.gabe_vpc.cidr_block, 20 + count.index)}"
user_data = file("cloud-init-worker.yml")
tags = {
Name = "rgesteve-crank-loadgen"
}
}
resource "aws_instance" "db" {
instance_type = "m7i.xlarge"
ami = "ami-05d251e0fc338590c"
subnet_id = aws_subnet.gabe_subnet.id
key_name = aws_key_pair.my-identity-pem.key_name
#security_groups = [aws_security_group.allow_ssh_from_intel.name]
vpc_security_group_ids = [aws_default_security_group.allow_ssh_from_intel.id]
#private_ip = "${cidrhost(aws_vpc.gabe_vpc.cidr_block, 20 + count.index)}"
user_data = file("cloud-init-worker.yml")
tags = {
Name = "rgesteve-crank-db"
}
}
output "login" {
# value = "ssh -o \"ProxyCommand=nc -x proxy-us.intel.com:1080 %h %p\" -i ./${aws_key_pair.my-identity-pem.key_name} ubuntu@${aws_instance.instance_1.public_ip}"
value = "ssh -i ./${aws_key_pair.my-identity-pem.key_name} ubuntu@${aws_instance.instance_1.public_ip}"
}
output "controller_ip" {
value = "${aws_instance.instance_1.public_ip}"
}
output "machine_type" {
value = "${aws_instance.app.instance_type}"
}
# output "sndbox_ip" {
# value = "${aws_instance.instance_2.public_ip}"
# }
output "app_ips" {
value = "The application public IP is: ${aws_instance.app.public_ip}, and its private ip is: ${aws_instance.app.private_ip}."
}
# output "worker_pubips" {
# value = "The workers' public IP are 0: ${aws_instance.worker[0].public_ip}, 1: ${aws_instance.worker[1].public_ip}."
# }
# output "worker_privips" {
# value = "The workers' public IP are 0: ${aws_instance.worker[0].private_ip}, 1: ${aws_instance.worker[1].private_ip}."
# }
output "private_ips" {
value = "The worker private IPs are: app: ${aws_instance.app.private_ip}, loadgen: ${aws_instance.loadgen.private_ip}, and db: ${aws_instance.db.private_ip}."
}
resource "local_file" "generated_inventory" {
content = templatefile("inventory_tpl.yaml", {controller_ip = aws_instance.instance_1.public_ip,
app_ip = aws_instance.app.public_ip
loadgen_ip = aws_instance.loadgen.public_ip
db_ip = aws_instance.db.public_ip
})
filename = "generated_inventory.yaml"
}