-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
253 lines (210 loc) · 6.61 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
resource "openstack_images_image_v2" "debiantesting" {
name = "Debian Testing"
image_source_url = "http://cdimage.debian.org/cdimage/openstack/testing/debian-testing-openstack-amd64.qcow2"
container_format = "bare"
disk_format = "qcow2"
}
resource "openstack_compute_keypair_v2" "terraform" {
name = "terraform"
public_key = "${file("${var.ssh_key_file}.pub")}"
}
resource "openstack_networking_network_v2" "terraform" {
name = "terraform"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "terraform" {
name = "terraform"
network_id = "${openstack_networking_network_v2.terraform.id}"
# NOTE: 10.0.0.0/16 is used by Docker for its overlay networks
cidr = "10.1.0.0/16"
ip_version = 4
dns_nameservers = ["8.8.8.8", "8.8.4.4"]
}
resource "openstack_networking_router_v2" "terraform" {
name = "terraform"
admin_state_up = "true"
external_gateway = "${var.external_gateway}"
}
resource "openstack_networking_router_interface_v2" "terraform" {
router_id = "${openstack_networking_router_v2.terraform.id}"
subnet_id = "${openstack_networking_subnet_v2.terraform.id}"
}
resource "openstack_compute_secgroup_v2" "bastion" {
name = "bastion"
description = "Bastion security group limited to SSH"
rule {
from_port = 22
to_port = 22
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
rule {
from_port = -1
to_port = -1
ip_protocol = "icmp"
cidr = "0.0.0.0/0"
}
}
resource "openstack_compute_secgroup_v2" "consul" {
name = "consul"
description = "Consul security group limited to Docker communication and consul"
# ssh access reserved from bastion
rule {
from_port = 22
to_port = 22
ip_protocol = "tcp"
cidr = "${openstack_compute_instance_v2.bastion.access_ip_v4}/32"
}
# internal consul access
rule {
from_port = 8500
to_port = 8500
ip_protocol = "tcp"
cidr = "10.1.0.0/16"
}
rule {
from_port = -1
to_port = -1
ip_protocol = "icmp"
cidr = "0.0.0.0/0"
}
}
resource "openstack_compute_secgroup_v2" "manager" {
name = "manager"
description = "Docker Manager security group limited to Docker communication"
# ssh access reserved from bastion
rule {
from_port = 22
to_port = 22
ip_protocol = "tcp"
cidr = "${openstack_compute_instance_v2.bastion.access_ip_v4}/32"
}
# any possible application exposing on port 80
rule {
from_port = 80
to_port = 80
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
# app-swarm-ui frontend access
rule {
from_port = 88
to_port = 88
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
# internal docker access
rule {
from_port = 2375
to_port = 2375
ip_protocol = "tcp"
cidr = "10.1.0.0/16"
}
rule {
from_port = -1
to_port = -1
ip_protocol = "icmp"
cidr = "0.0.0.0/0"
}
}
resource "openstack_compute_secgroup_v2" "worker" {
name = "worker"
description = "Docker Worker security group limited to Docker communication"
# ssh access reserved from bastion
rule {
from_port = 22
to_port = 22
ip_protocol = "tcp"
cidr = "${openstack_compute_instance_v2.bastion.access_ip_v4}/32"
}
rule {
from_port = 1
to_port = 65535
ip_protocol = "tcp"
self = true
}
rule {
from_port = 1
to_port = 65535
ip_protocol = "udp"
self = true
}
rule {
from_port = -1
to_port = -1
ip_protocol = "icmp"
cidr = "0.0.0.0/0"
}
}
resource "openstack_compute_floatingip_v2" "bastion" {
pool = "${var.pool}"
depends_on = ["openstack_networking_router_interface_v2.terraform"]
}
resource "openstack_compute_floatingip_associate_v2" "bastion" {
floating_ip = "${openstack_compute_floatingip_v2.bastion.address}"
instance_id = "${openstack_compute_instance_v2.bastion.id}"
}
resource "openstack_compute_instance_v2" "bastion" {
name = "bastion"
image_name = "${openstack_images_image_v2.debiantesting.name}"
flavor_name = "${var.bastion_flavor}"
key_pair = "${openstack_compute_keypair_v2.terraform.name}"
security_groups = ["${openstack_compute_secgroup_v2.bastion.name}"]
network {
uuid = "${openstack_networking_network_v2.terraform.id}"
}
}
resource "openstack_compute_instance_v2" "consul" {
name = "consul"
image_name = "${openstack_images_image_v2.debiantesting.name}"
flavor_name = "${var.consul_flavor}"
key_pair = "${openstack_compute_keypair_v2.terraform.name}"
security_groups = ["${openstack_compute_secgroup_v2.consul.name}"]
network {
uuid = "${openstack_networking_network_v2.terraform.id}"
}
user_data = "${file("setup_consul.sh")}"
}
resource "openstack_compute_floatingip_v2" "manager" {
pool = "${var.pool}"
depends_on = ["openstack_networking_router_interface_v2.terraform"]
}
resource "openstack_compute_floatingip_associate_v2" "manager" {
floating_ip = "${openstack_compute_floatingip_v2.manager.address}"
instance_id = "${openstack_compute_instance_v2.manager.id}"
}
data "template_file" "setup_manager" {
template = "${file("setup_manager.sh.tpl")}"
vars {
consul_address = "${openstack_compute_instance_v2.consul.access_ip_v4}"
}
}
resource "openstack_compute_instance_v2" "manager" {
name = "manager"
image_name = "${openstack_images_image_v2.debiantesting.name}"
flavor_name = "${var.docker_flavor}"
key_pair = "${openstack_compute_keypair_v2.terraform.name}"
security_groups = ["${openstack_compute_secgroup_v2.manager.name}", "${openstack_compute_secgroup_v2.worker.name}"]
network {
uuid = "${openstack_networking_network_v2.terraform.id}"
}
user_data = "${data.template_file.setup_manager.rendered}"
}
data "template_file" "setup_worker" {
template = "${file("setup_worker.sh.tpl")}"
vars {
manager_address = "${openstack_compute_instance_v2.manager.access_ip_v4}"
consul_address = "${openstack_compute_instance_v2.consul.access_ip_v4}"
}
}
resource "openstack_compute_instance_v2" "worker" {
name = "worker"
image_name = "${openstack_images_image_v2.debiantesting.name}"
flavor_name = "${var.docker_flavor}"
key_pair = "${openstack_compute_keypair_v2.terraform.name}"
security_groups = ["${openstack_compute_secgroup_v2.worker.name}"]
network {
uuid = "${openstack_networking_network_v2.terraform.id}"
}
user_data = "${data.template_file.setup_worker.rendered}"
}