Skip to content
Snippets Groups Projects
main.tf 1.45 KiB
Newer Older
# is created in external-network module and called in root module
variable "external_subnet_id" {type = "string"}

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
Ryan Randles Jones's avatar
Ryan Randles Jones committed
variable "key_pair" {type = "string"}
Ryan Randles Jones's avatar
Ryan Randles Jones committed
variable "internal_net" {}
variable "external_net" {}
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 "host_prefix" {}
variable "ohpc_user" {}
variable "ssh_private_key" {}

# creates details for the OHPC instance
resource "openstack_compute_instance_v2" "ohpc" {
  depends_on      = [var.external_subnet_id]
  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"]

# defines the networks of the instance
  network {
    name = var.external_net
  }
  network {
    name = var.internal_net
  }
}

# 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

# defines ssh connection
  connection {
    host = format(var.host_prefix,element(split(".", var.floating_ip_ohpc),3,),)
    user        = var.ohpc_user
    private_key = file(var.ssh_private_key)
  }
}

output "ssh_host" {
    value = format(var.host_prefix,element(split(".", var.floating_ip_ohpc),3,),)