diff --git a/main.tf b/main.tf index 351eff57d915454691defd964968f83cb4b32448..15a2f2aa949624afb7ec45b06c139497d7035633 100644 --- a/main.tf +++ b/main.tf @@ -48,7 +48,11 @@ resource "openstack_networking_subnet_v2" "internal_subnet" { # defines where floating ip will come from using variable from vars.tf -resource "openstack_networking_floatingip_v2" "ip_pool" { +resource "openstack_networking_floatingip_v2" "ohpc_ip" { + pool = "${var.public-network-name}" +} + +resource "openstack_networking_floatingip_v2" "ood_ip" { pool = "${var.public-network-name}" } @@ -72,12 +76,12 @@ depends_on = ["openstack_networking_subnet_v2.external_subnet"] # associates floating ip with the OHPC instance and run the ansible playbook resource "openstack_compute_floatingip_associate_v2" "ohpc" { - floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}" + floating_ip = "${openstack_networking_floatingip_v2.ohpc_ip.address}" instance_id = "${openstack_compute_instance_v2.ohpc.id}" # defines ssh connection connection { - host = "${format("${var.host-prefix}", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("${var.host-prefix}", element(split(".", openstack_networking_floatingip_v2.ohpc_ip.address),3))}" user = "${var.ohpc-user}" private_key = "${file(var.ssh-private-key)}" } @@ -107,3 +111,60 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { ] } } + +# creates details for the OOD instance using variables defined in vars.tf +resource "openstack_compute_instance_v2" "ood" { +depends_on = ["openstack_networking_subnet_v2.external_subnet"] + name = "${var.ood-instance-name}" + image_name = "${var.image}" + flavor_name = "${var.flavor}" + key_pair = "${openstack_compute_keypair_v2.keypair.name}" + security_groups = ["default"] + +# defines the networks of the instance + network { + name = "${var.external-net}" + } + network { + name = "${var.internal-net}" + } +} + +# associates floating ip with the OOD instance and run the ansible playbook +resource "openstack_compute_floatingip_associate_v2" "ood" { + floating_ip = "${openstack_networking_floatingip_v2.ood_ip.address}" + instance_id = "${openstack_compute_instance_v2.ood.id}" + + # defines ssh connection + connection { + host = "${format("${var.host-prefix}", element(split(".", openstack_networking_floatingip_v2.ood_ip.address),3))}" + user = "${var.ood-user}" + private_key = "${file(var.ssh-private-key)}" + } + + # installs programs + provisioner "remote-exec" { + inline = [ + "sudo mkdir -p /CRI_XCBC && sudo chown centos: /CRI_XCBC", + "sudo yum install -y epel-release", + "sudo yum install -y ansible git vim bash-completion", + "sudo yum install -y NetworkManager", + "sudo systemctl restart NetworkManager", + "sudo nmcli con mod 'Wired connection 1' connection.id 'eth1'" + ] + } + + # moves CRI_XCBC file into directory made above + provisioner "file" { + source = "CRI_XCBC/" + destination = "/CRI_XCBC/" + } + + # runs ansible playbook + provisioner "remote-exec" { + inline = [ + "sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/site.yaml -b" + ] + } +} + diff --git a/output.tf b/output.tf index fcec64226cf46d0548f9fbef266dec066d5b77a0..0cb4c08b0ce625d3da72e1784d8adfed81df9a99 100644 --- a/output.tf +++ b/output.tf @@ -1,5 +1,9 @@ -output "address" { - value = "${openstack_networking_floatingip_v2.ip_pool.address}" +output "ohpc_address" { + value = "${openstack_networking_floatingip_v2.ohpc_ip.address}" +} + +output "ood_address" { + value = "${openstack_networking_floatingip_v2.ood_ip.address}" } output "external_network_id" { diff --git a/vars.tf b/vars.tf index c30b0083e6c0c96a1e67589d84efd7673814fd08..376a93078d88567f9e39bfb5266d6932f6eaf6f2 100644 --- a/vars.tf +++ b/vars.tf @@ -49,6 +49,14 @@ variable "ohpc-user" { default = "centos" } +variable "ood-instance-name" { + default = "ood" +} + +variable "ood-user" { + default = "centos" +} + variable "public-network-name" { default = "bright-external-flat-externalnet" }