-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path010-computes.tf
More file actions
executable file
·63 lines (51 loc) · 1.67 KB
/
010-computes.tf
File metadata and controls
executable file
·63 lines (51 loc) · 1.67 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
#
# Create instance
#
resource "openstack_compute_instance_v2" "instance" {
name = var.name
flavor_name = var.flavor_name
block_device {
uuid = var.image_id
source_type = "image"
volume_size = var.block_device_volume_size
boot_index = 0
destination_type = "volume"
delete_on_termination = var.block_device_delete_on_termination
}
key_pair = var.key_pair_name
dynamic "scheduler_hints" {
for_each = var.server_groups
content {
group = scheduler_hints.value
}
}
dynamic "network" {
for_each = openstack_networking_port_v2.port
content {
port = network.value["id"]
}
}
}
# Create network port
resource "openstack_networking_port_v2" "port" {
count = length(var.ports)
name = var.ports[count.index].name
network_id = var.ports[count.index].network_id
admin_state_up = var.ports[count.index].admin_state_up == null ? true : var.ports[count.index].admin_state_up
security_group_ids = var.ports[count.index].security_group_ids == null ? [] : var.ports[count.index].security_group_ids
fixed_ip {
subnet_id = var.ports[count.index].subnet_id
ip_address = var.ports[count.index].ip_address == null ? null : var.ports[count.index].ip_address
}
}
# Create floating ip
resource "openstack_networking_floatingip_v2" "ip" {
count = var.is_public ? 1 : 0
pool = var.public_ip_network
}
# Attach floating ip to instance
resource "openstack_compute_floatingip_associate_v2" "ipa" {
count = var.is_public ? 1: 0
floating_ip = openstack_networking_floatingip_v2.ip[count.index].address
instance_id = openstack_compute_instance_v2.instance.id
}