-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
63 lines (54 loc) · 1.98 KB
/
main.tf
File metadata and controls
63 lines (54 loc) · 1.98 KB
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
resource "openstack_networking_floatingip_v2" "external" {
count = var.total_servers
pool = "external"
}
resource "openstack_blockstorage_volume_v3" "storage" {
count = var.total_servers
name = "storage-plesk-${count.index}"
volume_type = var.additional_volume_type
size = var.additional_volume_size
}
resource "openstack_compute_instance_v2" "plesk" {
# The amount of instances you want to start
count = var.total_servers
name = "plesk_${count.index}"
flavor_name = var.vm_flavor
key_pair = data.openstack_compute_keypair_v2.keypair.name
security_groups = [
openstack_compute_secgroup_v2.ssh.name,
openstack_compute_secgroup_v2.https.name,
openstack_compute_secgroup_v2.plesk.name
]
block_device {
boot_index = 0
uuid = data.openstack_images_image_v2.ubuntu.id
source_type = "image"
destination_type = "volume"
volume_type = var.boot_volume_type
volume_size = var.boot_volume_size
delete_on_termination = true
}
user_data = templatefile("templates/user_data.yaml.tpl", {
additional_disk_name = "vdb"
})
network {
name = openstack_networking_network_v2.private.name
# Here we get the value of the count and add 10,
# so that each instance gets it's own unique IP
fixed_ip_v4 = cidrhost(var.default_subnet, 10 + count.index)
}
lifecycle {
# Ignore some changes the will trigger a forced replacement
ignore_changes = [user_data]
}
}
resource "openstack_compute_floatingip_associate_v2" "fip" {
count = var.total_servers
floating_ip = openstack_networking_floatingip_v2.external[count.index].address
instance_id = openstack_compute_instance_v2.plesk[count.index].id
}
resource "openstack_compute_volume_attach_v2" "attached" {
count = var.total_servers
instance_id = openstack_compute_instance_v2.plesk[count.index].id
volume_id = openstack_blockstorage_volume_v3.storage[count.index].id
}