Skip to content
Snippets Groups Projects
main.tf 1.99 KiB
Newer Older
# is created in external-network module and called in root module
terraform {
required_version = ">= 0.14.0"
  required_providers {
    openstack = {
      source  = "terraform-provider-openstack/openstack"
      version = "~> 1.42.0"
    }
  }
}

Ryan Randles Jones's avatar
Ryan Randles Jones committed
variable "ohpc_instance_name" {}
variable "image_ohpc" {}
variable "flavor" {}
Ryan Randles Jones's avatar
Ryan Randles Jones committed

# is created in key-pair module and called in root module
variable "key_pair" {type = string}
variable "internal_network" {}
variable "internal_ip" {}
variable "external_network" {}
Ryan Randles Jones's avatar
Ryan Randles Jones committed

# is created in floating-ip module and called in root module
variable "floating_ip_ohpc" {type = string}
Ryan Randles Jones's avatar
Ryan Randles Jones committed
variable "ohpc_user" {}
variable "ssh_private_key" {}
variable "vol_ids" {
  type    = list(string)
  default = []
}

# creates details for the OHPC instance
resource "openstack_compute_instance_v2" "ohpc" {
  name            = var.ohpc_instance_name
  image_name      = var.image_ohpc
  flavor_name     = var.flavor
Ryan Randles Jones's avatar
Ryan Randles Jones committed
  key_pair        = var.key_pair
  security_groups = ["default"]
  user_data = <<-EOF
     #cloud-config
     write_files:
     - content: |
         10.1.1.10 ohpc ohpc.novalocal
       owner: centos:centos
       path: /etc/hosts
       permissions: 0644
     EOF

# defines the networks of the instance
  network {
    uuid = var.external_network
    uuid = var.internal_network
    fixed_ip_v4 = var.internal_ip
  }
}

# associates floating ip with the OHPC instance
resource "openstack_compute_floatingip_associate_v2" "ohpc" {
  floating_ip = var.floating_ip_ohpc
  instance_id = openstack_compute_instance_v2.ohpc.id
# Attach a volume
resource "openstack_compute_volume_attach_v2" "volume_attach" {
  count       = length(var.vol_ids)
  instance_id = openstack_compute_instance_v2.ohpc.id
  volume_id   = var.vol_ids[count.index]
output "xdmod_instance_id" {
Bo-Chun Chen's avatar
Bo-Chun Chen committed
    value = openstack_compute_instance_v2.ohpc.id
}

output "ssh_host" {
    value = var.floating_ip_ohpc
    value = openstack_compute_volume_attach_v2.volume_attach[count.index].device