-
Notifications
You must be signed in to change notification settings - Fork 5
/
cloud-computing.tf
125 lines (103 loc) · 4.16 KB
/
cloud-computing.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
resource "aws_instance" "aws_ec2_instance_control" {
ami = var.ami_id
instance_type = var.instance_type_control
count = var.number_of_instances_control
vpc_security_group_ids = [aws_security_group.aws_rke2_sg.id]
subnet_id = element([aws_subnet.aws_rke2_private_subnet1.id], count.index % 1)
iam_instance_profile = aws_iam_instance_profile.aws_iam_profile_control.name
key_name = var.key_pair_name
depends_on = [aws_nat_gateway.aws_rke2_ngw]
user_data = templatefile("${path.module}/scripts/control-node.sh", {
DOMAIN = "${var.domain}"
TOKEN = "${var.token}"
vRKE2 = "${var.vRKE2}"
})
tags = {
Name = "${var.prefix}-cp-0${count.index + 1}"
}
root_block_device {
volume_size = var.volume_size_control
volume_type = var.volume_type_control
encrypted = var.encrypted
delete_on_termination = var.delete_on_termination
tags = {
Name = "${var.prefix}-cp-volume-0${count.index + 1}"
}
}
}
resource "aws_instance" "aws_ec2_instance_controls" {
ami = var.ami_id
instance_type = var.instance_type_controls
count = var.number_of_instances_controls
vpc_security_group_ids = [aws_security_group.aws_rke2_sg.id]
subnet_id = element([aws_subnet.aws_rke2_private_subnet2.id, aws_subnet.aws_rke2_private_subnet3.id], count.index % 2)
iam_instance_profile = aws_iam_instance_profile.aws_iam_profile_control.name
key_name = var.key_pair_name
depends_on = [aws_instance.aws_ec2_instance_control]
user_data = templatefile("${path.module}/scripts/control-nodes.sh", {
DOMAIN = "${var.domain}"
TOKEN = "${var.token}"
vRKE2 = "${var.vRKE2}"
})
tags = {
Name = "${var.prefix}-cps-0${count.index + 1}"
}
root_block_device {
volume_size = var.volume_size_controls
volume_type = var.volume_type_controls
encrypted = var.encrypted
delete_on_termination = var.delete_on_termination
tags = {
Name = "${var.prefix}-cps-volume-0${count.index + 1}"
}
}
}
resource "aws_instance" "aws_ec2_instance_worker" {
ami = var.ami_id
instance_type = var.instance_type_worker
count = var.number_of_instances_worker
vpc_security_group_ids = [aws_security_group.aws_rke2_sg.id]
subnet_id = element([aws_subnet.aws_rke2_private_subnet1.id, aws_subnet.aws_rke2_private_subnet2.id, aws_subnet.aws_rke2_private_subnet3.id], count.index % 3)
iam_instance_profile = aws_iam_instance_profile.aws_iam_profile_worker.name
key_name = var.key_pair_name
depends_on = [aws_instance.aws_ec2_instance_controls]
user_data = templatefile("${path.module}/scripts/worker-nodes.sh", {
DOMAIN = "${var.domain}"
TOKEN = "${var.token}"
vRKE2 = "${var.vRKE2}"
})
tags = {
Name = "${var.prefix}-wk-0${count.index + 1}"
}
root_block_device {
volume_size = var.volume_size_worker
volume_type = var.volume_type_worker
encrypted = var.encrypted
delete_on_termination = var.delete_on_termination
tags = {
Name = "${var.prefix}-wk-volume-0${count.index + 1}"
}
}
}
resource "aws_instance" "aws_ec2_instance_bastion" {
ami = var.ami_id
instance_type = var.instance_type_bastion
count = var.number_of_instances_bastion
vpc_security_group_ids = [aws_security_group.aws_rke2_sg.id]
subnet_id = element([aws_subnet.aws_rke2_public_subnet1.id, aws_subnet.aws_rke2_public_subnet2.id, aws_subnet.aws_rke2_public_subnet3.id], count.index % 3)
associate_public_ip_address = true
key_name = var.key_pair_name
depends_on = [aws_nat_gateway.aws_rke2_ngw]
tags = {
Name = "${var.prefix}-bastion-0${count.index + 1}"
}
root_block_device {
volume_size = var.volume_size_bastion
volume_type = var.volume_type_bastion
encrypted = var.encrypted
delete_on_termination = var.delete_on_termination
tags = {
Name = "${var.prefix}-bastion-volume-0${count.index + 1}"
}
}
}