Skip to content
Snippets Groups Projects

Feat module refactor

Files
23
box/main.tf 0 → 100644
+ 44
0
# always use the latest version of image
data "openstack_images_image_v2" "box" {
name = var.image_name
most_recent = true
}
# to get more hardware details
data "openstack_compute_flavor_v2" "box" {
name = var.box_size
}
# create node
resource "openstack_compute_instance_v2" "box" {
name = var.amount == 1 ? var.box_name : "${var.box_name}${count.index}"
image_id = data.openstack_images_image_v2.box.id
flavor_id = data.openstack_compute_flavor_v2.box.id
key_pair = var.key_pair
security_groups = concat(["default"], var.sec_groups)
count = var.amount
user_data = var.user_data
# define the networks of the instance
dynamic "network" {
for_each = var.box_nets
iterator = net
content {
uuid = net.value.net_id
fixed_ip_v4 = net.value.ip_v4
}
}
}
# allocate floating ip for instance if needed
resource "openstack_networking_floatingip_v2" "box" {
count = var.floating_ip_pool != "" ? var.amount : 0
pool = var.floating_ip_pool
}
# associate floating ip to the instance
resource "openstack_compute_floatingip_associate_v2" "box" {
count = var.floating_ip_pool != "" ? var.amount : 0
floating_ip = openstack_networking_floatingip_v2.box[count.index].address
instance_id = openstack_compute_instance_v2.box[count.index].id
}
Loading