-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.tf
71 lines (61 loc) · 1.76 KB
/
ec2.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
resource "tls_private_key" "kubernetes" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "aws_key_pair" "kubernetes" {
key_name = "${var.username}-key"
public_key = tls_private_key.kubernetes.public_key_openssh
}
resource "local_file" "instance_private_key_pem" {
content = tls_private_key.kubernetes.private_key_pem
filename = "${local.key_directory}/${aws_key_pair.kubernetes.key_name}.pem"
file_permission = "0400"
}
resource "aws_instance" "controller" {
# kubernetes controllers
count = var.instance_count
ami = data.aws_ami.ubuntu_server_20.id
instance_type = "m5.xlarge"
subnet_id = aws_subnet.main_az_1_public.id
source_dest_check = false
key_name = aws_key_pair.kubernetes.key_name
vpc_security_group_ids = [
aws_security_group.main.id,
aws_security_group.alpha.id,
aws_security_group.internal.id
]
root_block_device {
volume_size = 200
encrypted = true
tags = {
Name = "${var.username}-controller-ubuntu-${count.index}-root-volume"
}
}
tags = {
Name = "${var.username}-controller-ubuntu-${count.index}"
}
}
resource "aws_instance" "worker" {
# kubernetes workers
count = var.instance_count
ami = data.aws_ami.ubuntu_server_20.id
instance_type = "m5.xlarge"
subnet_id = aws_subnet.main_az_1_public.id
source_dest_check = false
key_name = aws_key_pair.kubernetes.key_name
vpc_security_group_ids = [
aws_security_group.main.id,
aws_security_group.alpha.id,
aws_security_group.internal.id
]
root_block_device {
volume_size = 200
encrypted = true
tags = {
Name = "${var.username}-worker-ubuntu-${count.index}-root-volume"
}
}
tags = {
Name = "${var.username}-worker-ubuntu-${count.index}"
}
}