Skip to content
Snippets Groups Projects
Commit 265d0488 authored by Mitchell Moore's avatar Mitchell Moore Committed by Ryan Randles Jones
Browse files

Feat ood instantiate

parent 46693062
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,11 @@ resource "openstack_networking_subnet_v2" "internal_subnet" { ...@@ -48,7 +48,11 @@ resource "openstack_networking_subnet_v2" "internal_subnet" {
# defines where floating ip will come from using variable from vars.tf # 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}" pool = "${var.public-network-name}"
} }
...@@ -72,12 +76,12 @@ depends_on = ["openstack_networking_subnet_v2.external_subnet"] ...@@ -72,12 +76,12 @@ depends_on = ["openstack_networking_subnet_v2.external_subnet"]
# associates floating ip with the OHPC instance and run the ansible playbook # associates floating ip with the OHPC instance and run the ansible playbook
resource "openstack_compute_floatingip_associate_v2" "ohpc" { 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}" instance_id = "${openstack_compute_instance_v2.ohpc.id}"
# defines ssh connection # defines ssh connection
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}" user = "${var.ohpc-user}"
private_key = "${file(var.ssh-private-key)}" private_key = "${file(var.ssh-private-key)}"
} }
...@@ -107,3 +111,60 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { ...@@ -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"
]
}
}
output "address" { output "ohpc_address" {
value = "${openstack_networking_floatingip_v2.ip_pool.address}" value = "${openstack_networking_floatingip_v2.ohpc_ip.address}"
}
output "ood_address" {
value = "${openstack_networking_floatingip_v2.ood_ip.address}"
} }
output "external_network_id" { output "external_network_id" {
......
...@@ -49,6 +49,14 @@ variable "ohpc-user" { ...@@ -49,6 +49,14 @@ variable "ohpc-user" {
default = "centos" default = "centos"
} }
variable "ood-instance-name" {
default = "ood"
}
variable "ood-user" {
default = "centos"
}
variable "public-network-name" { variable "public-network-name" {
default = "bright-external-flat-externalnet" default = "bright-external-flat-externalnet"
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment