-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstances.tf
102 lines (85 loc) · 2.88 KB
/
instances.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
### Resolve correct ami id
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["cio-3450-u18"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["565054200205"]
}
### Setup Swarm master
resource "aws_instance" "docker_swarm_master" {
count = var.swarm_master_count
instance_type = "t3.small"
ami = data.aws_ami.ubuntu.id
key_name = aws_key_pair.auth.id
subnet_id = aws_subnet.storidge.id
associate_public_ip_address = "true"
vpc_security_group_ids = [
aws_security_group.storidge.id
]
tags = {
Name = format("var.swarm_name-master-%02d", count.index)
}
}
resource "aws_volume_attachment" "docker_swarm_master_attachment01" {
count = var.swarm_master_count
device_name = "/dev/xvdb"
instance_id = aws_instance.docker_swarm_master.*.id[count.index]
volume_id = aws_ebs_volume.master_storage01.*.id[count.index]
force_detach = "true"
}
resource "aws_volume_attachment" "docker_swarm_master_attachment02" {
count = var.swarm_master_count
device_name = "/dev/xvdc"
instance_id = aws_instance.docker_swarm_master.*.id[count.index]
volume_id = aws_ebs_volume.master_storage02.*.id[count.index]
force_detach = "true"
}
resource "aws_volume_attachment" "docker_swarm_master_attachment03" {
count = var.swarm_master_count
device_name = "/dev/xvdd"
instance_id = aws_instance.docker_swarm_master.*.id[count.index]
volume_id = aws_ebs_volume.master_storage03.*.id[count.index]
force_detach = "true"
}
### Setup Swarm worker
resource "aws_instance" "docker_swarm_worker" {
count = var.swarm_worker_count
instance_type = "t3.small"
ami = data.aws_ami.ubuntu.id
key_name = aws_key_pair.auth.id
subnet_id = aws_subnet.storidge.id
associate_public_ip_address = "true"
vpc_security_group_ids = [
aws_security_group.storidge.id
]
tags = {
Name = format("var.swarm_name-worker-%02d", count.index)
}
}
resource "aws_volume_attachment" "docker_swarm_worker_attachment01" {
count = var.swarm_worker_count
device_name = "/dev/xvdb"
instance_id = aws_instance.docker_swarm_worker.*.id[count.index]
volume_id = aws_ebs_volume.worker_storage01.*.id[count.index]
force_detach = "true"
}
resource "aws_volume_attachment" "docker_swarm_worker_attachment02" {
count = var.swarm_worker_count
device_name = "/dev/xvdc"
instance_id = aws_instance.docker_swarm_worker.*.id[count.index]
volume_id = aws_ebs_volume.worker_storage02.*.id[count.index]
force_detach = "true"
}
resource "aws_volume_attachment" "docker_swarm_worker_attachment03" {
count = var.swarm_worker_count
device_name = "/dev/xvdd"
instance_id = aws_instance.docker_swarm_worker.*.id[count.index]
volume_id = aws_ebs_volume.worker_storage03.*.id[count.index]
force_detach = "true"
}