Commit 58dc1a39 authored by Ryan Randles Jones's avatar Ryan Randles Jones
Browse files

Merge branch 'variable-update-branch' into 'master'

Variable update branch

See merge request rrand11/terraform-openstack!18
parents ec215bdb 928452c3
resource "openstack_compute_keypair_v2" "keypair" {
name = "my-keypair"
public_key = "${file("~/.ssh/id_rsa.pub")}"
}
#local variable for ssh connect to ohpc
locals {
connection = {
host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
user = "centos"
private_key = "${file("~/.ssh/id_rsa")}"
}
name = "${var.keypair-name}"
public_key = "${file(var.ssh-public-key)}"
}
# creates dmznet
resource "openstack_networking_network_v2" "dmznet" {
name = "dmznet"
admin_state_up = "true"
resource "openstack_networking_network_v2" "external_net" {
name = "${var.external-net}"
admin_state_up = "${var.admin-state-up}"
}
resource "openstack_networking_subnet_v2" "dmzsubnet" {
name = "dmzsubnet"
network_id = "${openstack_networking_network_v2.dmznet.id}"
resource "openstack_networking_subnet_v2" "external_subnet" {
name = "${var.external-subnet}"
network_id = "${openstack_networking_network_v2.external_net.id}"
cidr = "192.168.100.0/24"
ip_version = 4
dns_nameservers = ["8.8.8.8"]
enable_dhcp = true
enable_dhcp = "${var.enable-dhcp}"
}
# defines the router borderrouter using floating ip defined in datasources.tf to create the external network id
resource "openstack_networking_router_v2" "borderrouter" {
name = "borderrouter"
admin_state_up = "true"
resource "openstack_networking_router_v2" "router" {
name = "${var.router}"
admin_state_up = "${var.admin-state-up}"
external_network_id = "${data.openstack_networking_network_v2.public-network.id}"
}
resource "openstack_networking_router_interface_v2" "borderrouter" {
router_id = "${openstack_networking_router_v2.borderrouter.id}"
subnet_id = "${openstack_networking_subnet_v2.dmzsubnet.id}"
resource "openstack_networking_router_interface_v2" "router" {
router_id = "${openstack_networking_router_v2.router.id}"
subnet_id = "${openstack_networking_subnet_v2.external_subnet.id}"
}
# creates clusternet
resource "openstack_networking_network_v2" "clusternet" {
name = "clusternet"
admin_state_up = "true"
resource "openstack_networking_network_v2" "internal_net" {
name = "${var.internal-net}"
admin_state_up = "${var.admin-state-up}"
}
# creates clustersubnet
# cidr is the subnet range (that subnet range and dns nameservers from the network create file in feat-openstack)
resource "openstack_networking_subnet_v2" "clustersubnet" {
name = "clustersubnet"
network_id = "${openstack_networking_network_v2.clusternet.id}"
resource "openstack_networking_subnet_v2" "internal_subnet" {
name = "${var.internal-subnet}"
network_id = "${openstack_networking_network_v2.internal_net.id}"
cidr = "10.1.1.0/24"
ip_version = 4
enable_dhcp = true
enable_dhcp = "${var.enable-dhcp}"
}
......@@ -63,8 +54,8 @@ resource "openstack_networking_floatingip_v2" "ip_pool" {
# creates details for the OHPC instance using variables defined in vars.tf
resource "openstack_compute_instance_v2" "ohpc" {
depends_on = ["openstack_networking_subnet_v2.dmzsubnet"]
name = "ohpc"
depends_on = ["openstack_networking_subnet_v2.external_subnet"]
name = "${var.ohpc-instance-name}"
image_name = "${var.image}"
flavor_name = "${var.flavor}"
key_pair = "${openstack_compute_keypair_v2.keypair.name}"
......@@ -72,10 +63,10 @@ depends_on = ["openstack_networking_subnet_v2.dmzsubnet"]
# defines the networks of the instance
network {
name = "dmznet"
name = "${var.external-net}"
}
network {
name = "clusternet"
name = "${var.internal-net}"
}
}
......@@ -83,14 +74,16 @@ depends_on = ["openstack_networking_subnet_v2.dmzsubnet"]
resource "openstack_compute_floatingip_associate_v2" "ohpc" {
floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}"
instance_id = "${openstack_compute_instance_v2.ohpc.id}"
provisioner "remote-exec" {
# defines ssh connection
connection {
host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
user = "centos"
private_key = "${file("~/.ssh/id_rsa")}"
host = "${format("${var.host-prefix}", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
user = "${var.ohpc-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",
......@@ -101,24 +94,14 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" {
]
}
# moves CRI_XCBC file into directory made above
provisioner "file" {
source = "CRI_XCBC/"
destination = "/CRI_XCBC/"
connection {
host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
#host = "${openstack_networking_floatingip_v2.terraform.address}"
user = "centos"
private_key = "${file("~/.ssh/id_rsa")}"
}
}
# runs ansible playbook
provisioner "remote-exec" {
connection {
host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
#host = "${openstack_networking_floatingip_v2.ohpc.address}"
user = "centos"
private_key = "${file("~/.ssh/id_rsa")}"
}
inline = [
"sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/site.yaml -b"
]
......
......@@ -2,10 +2,10 @@ output "address" {
value = "${openstack_networking_floatingip_v2.ip_pool.address}"
}
output "dmznet_network_id" {
value = "${openstack_networking_network_v2.dmznet.id}"
output "external_network_id" {
value = "${openstack_networking_network_v2.external_net.id}"
}
output "clusternet_network_id" {
value = "${openstack_networking_network_v2.clusternet.id}"
output "internal_network_id" {
value = "${openstack_networking_network_v2.internal_net.id}"
}
variable "image" {
default = "CentOS-7-x86_64-GenericCloud-1905"
variable "admin-state-up" {
description = "whether admin state in enabled. defualt is true"
default = true
}
variable "enable-dhcp" {
description = "whether dhcp in enabled. defualt is true"
default = true
}
variable "external-net" {
default = "dmznet"
}
variable "external-subnet" {
default = "dmzsubnet"
}
variable "flavor" {
default = "m1.medium"
}
variable "host-prefix" {
description = "prefix of host id."
default = "164.111.161.%s"
}
variable "internal-net" {
default = "clusternet"
}
variable "internal-subnet" {
default = "clustersubnet"
}
variable "image" {
default = "CentOS-7-x86_64-GenericCloud-1905"
}
variable "keypair-name" {
default = "os-gen-keypair"
}
variable "ohpc-instance-name" {
default = "ohpc"
}
variable "ohpc-user" {
default = "centos"
}
variable "public-network-name" {
default = "bright-external-flat-externalnet"
}
variable "router" {
default = "borderrouter"
}
variable "ssh-private-key" {
description = "Path to file containing private key"
default = "~/.ssh/id_rsa"
}
variable "ssh-public-key" {
description = "Path to file containing public key"
default = "~/.ssh/id_rsa.pub"
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment