-
Notifications
You must be signed in to change notification settings - Fork 0
/
terraform.tf
154 lines (134 loc) · 3.28 KB
/
terraform.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
provider "aws" {
region = "us-west-2"
}
provider "random" {}
resource "random_id" "hash" {
byte_length = 8
}
resource "aws_vpc" "benchmark_vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "EC2_IO_Benchmark_VPC_${random_id.hash.hex}"
Benchmark = "EC2_IO"
}
}
resource "aws_internet_gateway" "benchmark_internet_gateway" {
vpc_id = aws_vpc.benchmark_vpc.id
tags = {
Benchmark = "EC2_IO"
}
}
resource "aws_route" "internet_access" {
route_table_id = aws_vpc.benchmark_vpc.main_route_table_id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.benchmark_internet_gateway.id
}
resource "aws_subnet" "benchmark_subnet" {
vpc_id = aws_vpc.benchmark_vpc.id
cidr_block = "10.0.0.0/24"
map_public_ip_on_launch = true
availability_zone = "us-west-2a"
tags = {
Benchmark = "EC2_IO"
}
}
resource "aws_security_group" "benchmark_security_group" {
name = "ec2_io_${random_id.hash.hex}"
vpc_id = aws_vpc.benchmark_vpc.id
# SSH access from anywhere
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# All ports open within the VPC
ingress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["10.0.0.0/16"]
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "EC2_IO_Benchmark_SecurityGroup_${random_id.hash.hex}"
Benchmark = "EC2_IO"
}
}
resource "aws_key_pair" "benchmark_key_pair" {
key_name = "aws_ec2_io-${random_id.hash.hex}"
public_key = file("~/.ssh/aws_ec2_io.pub")
tags = {
Benchmark = "EC2_IO"
}
}
variable "instance_types" {
type = list(object({
instance_type = string
arch = string
}))
default = [
{
instance_type = "i3en.large"
arch = "x86_64"
},
{
instance_type = "i3en.xlarge"
arch = "x86_64"
},
{
instance_type = "i4i.large"
arch = "x86_64"
},
{
instance_type = "i4i.xlarge"
arch = "x86_64"
},
{
instance_type = "i4g.large"
arch = "arm64"
},
{
instance_type = "i4g.xlarge"
arch = "arm64"
},
{
instance_type = "is4gen.medium"
arch = "arm64"
},
{
instance_type = "is4gen.large"
arch = "arm64"
},
{
instance_type = "is4gen.xlarge"
arch = "arm64"
},
{
instance_type = "im4gn.large"
arch = "arm64"
},
{
instance_type = "im4gn.xlarge"
arch = "arm64"
},
]
}
resource "aws_instance" "ec2_io" {
count = length(var.instance_types)
instance_type = var.instance_types[count.index].instance_type
ami = var.instance_types[count.index].arch == "x86_64" ? "ami-03f65b8614a860c29" : "ami-0c79a55dda52434da"
key_name = aws_key_pair.benchmark_key_pair.id
subnet_id = aws_subnet.benchmark_subnet.id
vpc_security_group_ids = [aws_security_group.benchmark_security_group.id]
tags = {
Name = "ec2_io_${count.index}"
Benchmark = "EC2_IO"
}
}