Skip to content
Snippets Groups Projects
main.tf 1.81 KiB
Newer Older
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" {}
terraform {
required_version = ">= 0.14.0"
  required_providers {
    openstack = {
      source  = "terraform-provider-openstack/openstack"
      version = "~> 1.42.0"
    }
  }
}

provider "openstack" {
  use_octavia         = true
  endpoint_overrides = {
      "network"  = "https://neutron-api.cloud.rc.uab.edu:9696/v2.0/"
    }
}

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
  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, 'ethernet=$(cat /sys/class/net/eth0/address); nodename=$(hostname -s); sed -e "s/MY_HWADDR/$ethernet/" -e "s/MY_NODENAME/$nodename/" -i /warewulf/config;' ]
     - [ bash, -xc, "echo $(date) ': hello world!'; until WWGETFILES_INTERVAL=0 bash -x /warewulf/bin/wwgetfiles; do echo waiting ; rm -f /tmp/.wwgetfile.lock ; sleep 10; done;" ]
     - [ bash, -xc, "systemctl restart munge" ]
     - [ bash, -xc, "systemctl restart slurmd" ]
    EOF
Ryan Randles Jones's avatar
Ryan Randles Jones committed

# defines the networks of the instance
  network {
    uuid = 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)
}