Skip to content
Snippets Groups Projects
main.tf 1.28 KiB
Newer Older
# is created in internal-network module and called in root module
variable "internal_subnet_id" {type = "string"}
Ryan Randles Jones's avatar
Ryan Randles Jones committed
variable "image_compute" {}
variable "flavor" {}

# is created in key-pair module and called in root module
variable "key_pair" {type = "string"}

Ryan Randles Jones's avatar
Ryan Randles Jones committed
variable "compute_node_count" { }
variable "internal_network" {}
data "openstack_images_image_v2" "compute" {
  name = var.image_compute
  most_recent = true
}

Ryan Randles Jones's avatar
Ryan Randles Jones committed
# creates compute node
resource "openstack_compute_instance_v2" "compute" {
Ryan Randles Jones's avatar
Ryan Randles Jones committed
  depends_on      = [var.internal_subnet_id]
  name            = "c${count.index}"
  image_id        = data.openstack_images_image_v2.compute.id
Ryan Randles Jones's avatar
Ryan Randles Jones committed
  flavor_name     = var.flavor
Ryan Randles Jones's avatar
Ryan Randles Jones committed
  key_pair        = var.key_pair
Ryan Randles Jones's avatar
Ryan Randles Jones committed
  security_groups = ["default"]
  count           = var.compute_node_count
  user_data =  <<-EOF
    #cloud-config
    runcmd:
     - [ bash, -xc, 'echo DEBUG: empty user_data var: add post instantiation steps here' ]
Ryan Randles Jones's avatar
Ryan Randles Jones committed

# defines the networks of the instance
  network {
    name = var.internal_network
Bo-Chun Chen's avatar
Bo-Chun Chen committed
}

# output
output "id" {
  value = openstack_compute_instance_v2.compute.*.id
}
output "image_id" {
  value = data.openstack_images_image_v2.compute.id
}

output "network" {
  value = zipmap(openstack_compute_instance_v2.compute.*.name, openstack_compute_instance_v2.compute.*.network)
}