Forked from
Ryan Randles Jones / Terraform Openstack
96 commits ahead of the upstream repository.
-
Eesaan Atluri authoreded504f86
main.tf 2.52 KiB
# is created in internal-network module and called in root module
variable "internal_subnet_id" {type = string}
variable "ood_instance_name" {}
variable "image_ood" {}
variable "flavor" {}
# 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" {}
# is created in floating-ip module and called in root module
variable "floating_ip_ood" {type = string}
variable "host_prefix" {}
variable "ood_user" {}
variable "ssh_private_key" {}
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/"
}
}
# creates details for the OOD instance
resource "openstack_compute_instance_v2" "ood" {
depends_on = [var.internal_subnet_id]
name = var.ood_instance_name
image_name = var.image_ood
flavor_name = var.flavor
key_pair = var.key_pair
security_groups = ["default"]
user_data = <<-EOF
#cloud-config
runcmd:
- [ bash, -xc, 'ethernet=$(cat /sys/class/net/eth1/address); nodename=$(hostname -s); sed -e "s/MY_HWADDR/$ethernet/" -e "s/MY_NODENAME/$nodename/" -i /warewulf/config;' ]
- [ bash, -xc, "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, "cd /CRI_XCBC; ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/ood-ops.yaml -b -v" ]
EOF
# defines the networks of the instance
network {
name = var.external_network
}
network {
name = var.internal_network
fixed_ip_v4 = var.internal_ip
}
}
# associates floating ip with the OOD instance
resource "openstack_compute_floatingip_associate_v2" "ood" {
floating_ip = var.floating_ip_ood
instance_id = openstack_compute_instance_v2.ood.id
# defines ssh connection
connection {
host = format(var.host-prefix,element(split(".", var.floating_ip_ood),3,),)
user = var.ood_user
private_key = file(var.ssh_private_key)
}
}
output "id" {
value = openstack_compute_instance_v2.ood.id
}
output "ssh_host"{
value = format(var.host_prefix,element(split(".", var.floating_ip_ood),3,),)
}
output "network" {
value = openstack_compute_instance_v2.ood.network
}