Commit 0687c03b authored by Ryan Randles Jones's avatar Ryan Randles Jones
Browse files

Merge branch 'fix-condense-vars' into 'master'

Fix condense vars

See merge request rrand11/terraform-openstack!19
parents 9a79fb5d c782d797
data "openstack_networking_network_v2" "public-network" {
name = "${var.public-network-name}"
name = var.public-network-name
}
resource "openstack_compute_keypair_v2" "keypair" {
name = "${var.keypair-name}"
public_key = "${file(var.ssh-public-key)}"
name = var.keypair-name
public_key = file(var.ssh-public-key)
}
# creates dmznet
resource "openstack_networking_network_v2" "external_net" {
name = "${var.external-net}"
admin_state_up = "${var.admin-state-up}"
name = var.external-net
admin_state_up = var.admin-state-up
}
resource "openstack_networking_subnet_v2" "external_subnet" {
name = "${var.external-subnet}"
network_id = "${openstack_networking_network_v2.external_net.id}"
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 = "${var.enable-dhcp}"
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" "router" {
name = "${var.router}"
admin_state_up = "${var.admin-state-up}"
external_network_id = "${data.openstack_networking_network_v2.public-network.id}"
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" "router" {
router_id = "${openstack_networking_router_v2.router.id}"
subnet_id = "${openstack_networking_subnet_v2.external_subnet.id}"
router_id = openstack_networking_router_v2.router.id
subnet_id = openstack_networking_subnet_v2.external_subnet.id
}
# creates clusternet
resource "openstack_networking_network_v2" "internal_net" {
name = "${var.internal-net}"
admin_state_up = "${var.admin-state-up}"
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" "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 = "${var.enable-dhcp}"
name = var.internal-subnet
network_id = openstack_networking_network_v2.internal_net.id
cidr = "10.1.1.0/24"
ip_version = 4
enable_dhcp = var.enable-dhcp
}
# defines where floating ip will come from using variable from vars.tf
resource "openstack_networking_floatingip_v2" "ohpc_ip" {
pool = "${var.public-network-name}"
pool = var.public-network-name
}
resource "openstack_networking_floatingip_v2" "ood_ip" {
pool = "${var.public-network-name}"
pool = var.public-network-name
}
# creates details for the OHPC instance using variables defined in vars.tf
resource "openstack_compute_instance_v2" "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}"
depends_on = [openstack_networking_subnet_v2.external_subnet]
name = var.ohpc-instance-name
image_name = var.image_ohpc
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}"
name = var.external-net
}
network {
name = "${var.internal-net}"
name = var.internal-net
}
}
# 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.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.ohpc_ip.address),3))}"
user = "${var.ohpc-user}"
private_key = "${file(var.ssh-private-key)}"
}
# installs programs
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.ohpc_ip.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",
......@@ -103,7 +107,7 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" {
source = "CRI_XCBC/"
destination = "/CRI_XCBC/"
}
# runs ansible playbook
provisioner "remote-exec" {
inline = [
......@@ -114,35 +118,40 @@ 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}"
depends_on = [openstack_networking_subnet_v2.external_subnet]
name = var.ood-instance-name
image_name = var.image_ood
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}"
name = var.external-net
}
network {
name = "${var.internal-net}"
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
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",
......@@ -159,7 +168,7 @@ resource "openstack_compute_floatingip_associate_v2" "ood" {
source = "CRI_XCBC/"
destination = "/CRI_XCBC/"
}
# runs ansible playbook
provisioner "remote-exec" {
inline = [
......
output "ohpc_address" {
value = "${openstack_networking_floatingip_v2.ohpc_ip.address}"
value = openstack_networking_floatingip_v2.ohpc_ip.address
}
output "ood_address" {
value = "${openstack_networking_floatingip_v2.ood_ip.address}"
value = openstack_networking_floatingip_v2.ood_ip.address
}
output "external_network_id" {
value = "${openstack_networking_network_v2.external_net.id}"
value = openstack_networking_network_v2.external_net.id
}
output "internal_network_id" {
value = "${openstack_networking_network_v2.internal_net.id}"
value = openstack_networking_network_v2.internal_net.id
}
variable "admin-state-up" {
description = "whether admin state in enabled. defualt is true"
default = true
default = true
}
variable "enable-dhcp" {
description = "whether dhcp in enabled. defualt is true"
default = true
default = true
}
variable "external-net" {
......@@ -33,14 +33,18 @@ variable "internal-subnet" {
default = "clustersubnet"
}
variable "image" {
variable "image_ohpc" {
default = "CentOS-7-x86_64-GenericCloud-1905"
}
variable "image_ood" {
default = "CentOS-7-x86_64-GenericCloud-1905"
}
variable "keypair-name" {
default = "os-gen-keypair"
}
variable "ohpc-instance-name" {
default = "ohpc"
}
......@@ -67,10 +71,10 @@ variable "router" {
variable "ssh-private-key" {
description = "Path to file containing private key"
default = "~/.ssh/id_rsa"
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
default = "~/.ssh/id_rsa.pub"
}
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