Commit b2ce8eda authored by Ryan Randles Jones's avatar Ryan Randles Jones
Browse files

Update main.tf

parent b9a39457
# creates public and private keypair
resource "openstack_compute_keypair_v2" "test-keypair" {
name = "my-keypair"
}
# creates dmznet
resource "openstack_networking_network_v2" "ohpc" {
resource "openstack_networking_network_v2" "dmznet" {
name = "dmznet"
admin_state_up = "true"
}
# creates dmzsubnet using the floating ip defined in datasources.tf to get the network id
# cidr is the subnet range (that subnet range and dns nameservers from the network create file in feat-openstack)
resource "openstack_networking_subnet_v2" "terraform" {
resource "openstack_networking_subnet_v2" "dmzsubnet" {
name = "dmzsubnet"
network_id = "${openstack_networking_network_v2.ohpc.id}"
network_id = "${openstack_networking_network_v2.dmznet.id}"
cidr = "192.168.100.0/24"
ip_version = 4
dns_nameservers = ["8.8.8.8"]
enable_dhcp = true
}
# defines the router borderrouter using floating ip defined in datasources.tf to create the external network id
resource "openstack_networking_router_v2" "ohpc" {
resource "openstack_networking_router_v2" "borderrouter" {
name = "borderrouter"
admin_state_up = "true"
external_network_id = "${data.openstack_networking_network_v2.ohpc.id}"
external_network_id = "${data.openstack_networking_network_v2.borderrouter.id}"
}
# creates the router and subnet id using info defined above
resource "openstack_networking_router_interface_v2" "ohpc" {
router_id = "${openstack_networking_router_v2.ohpc.id}"
subnet_id = "${openstack_networking_subnet_v2.ohpc.id}"
resource "openstack_networking_router_interface_v2" "borderrouter" {
router_id = "${openstack_networking_router_v2.borderrouter.id}"
subnet_id = "${openstack_networking_subnet_v2.dmzsubnet.id}"
}
# defines where floating ip will come from using variable from vars.tf
resource "openstack_networking_floatingip_v2" "ohpc" {
pool = "${var.pool}"
}
# creates clusternet
resource "openstack_networking_network_v2" "ohpc2" {
resource "openstack_networking_network_v2" "clusternet" {
name = "clusternet"
admin_state_up = "true"
}
# 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" "ohpc2" {
# 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.ohpc2.id}"
network_id = "${openstack_networking_network_v2.clusternet.id}"
cidr = "10.1.1.0/24"
ip_version = 4
enable_dhcp = false
}
# creates details for the instance using variables defined in vars.tf and resource for security groups
resource "openstack_compute_instance_v2" "ohpc" {
# defines where floating ip will come from using variable from vars.tf
resource "openstack_networking_floatingip_v2" "ip_pool" {
pool = "${var.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"
image_name = "${var.image}"
flavor_name = "${var.flavor}"
key_pair = "${openstack_compute_keypair_v2.test-keypair.name}"
key_pair = "${var.key_pair}"
security_groups = ["default"]
# defines the networks of the instance
......@@ -71,15 +65,14 @@ resource "openstack_compute_instance_v2" "ohpc" {
}
}
# associates floating ip with the instance
# 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.address}"
floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}"
instance_id = "${openstack_compute_instance_v2.ohpc.id}"
provisioner "remote-exec" {
connection {
host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ohpc.address),3))}"
#host = "${openstack_networking_floatingip_v2.ohpc.address}"
host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}"
user = "centos"
private_key = "${file(var.ssh_key_private)}"
}
......@@ -93,26 +86,27 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" {
"sudo nmcli con mod 'Wired connection 1' connection.id 'eth1'"
]
}
provisioner "file" {
source = "CRI_XCBC/"
destination = "/CRI_XCBC/"
connection {
host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ohpc.address),3))}"
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(var.ssh_key_private)}"
}
}
provisioner "remote-exec" {
connection {
host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ohpc.address),3))}"
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(var.ssh_key_private)}"
}
inline = [
"sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l ohpc /CRI_XCBC/site.yaml -b"
"sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/site.yaml -b"
]
}
}
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