Newer
Older
# creates public and private keypair
resource "openstack_compute_keypair_v2" "test-keypair" {
name = "my-keypair"
}
# creates dmznet
resource "openstack_networking_network_v2" "ohpc" {
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" {
name = "dmzsubnet"
network_id = "${openstack_networking_network_v2.ohpc.id}"
cidr = "192.168.100.0/24"
ip_version = 4
dns_nameservers = ["8.8.8.8"]
}
# defines the router borderrouter using floating ip defined in datasources.tf to create the external network id
resource "openstack_networking_router_v2" "ohpc" {
name = "borderrouter"
admin_state_up = "true"
external_network_id = "${data.openstack_networking_network_v2.ohpc.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}"
# 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" {
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" {
name = "clustersubnet"
network_id = "${openstack_networking_network_v2.ohpc2.id}"
cidr = "10.1.1.0/24"
ip_version = 4
}
# creates details for the instance using variables defined in vars.tf and resource for security groups
resource "openstack_compute_instance_v2" "ohpc" {
name = "ohpc"
image_name = "${var.image}"
flavor_name = "${var.flavor}"
key_pair = "${openstack_compute_keypair_v2.test-keypair.name}"
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
security_groups = ["default"]
# defines the networks of the instance
network {
name = "dmznet"
}
network {
name = "clusternet"
}
}
# associates floating ip with the instance
resource "openstack_compute_floatingip_associate_v2" "ohpc" {
floating_ip = "${openstack_networking_floatingip_v2.ohpc.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}"
user = "centos"
private_key = "${file(var.ssh_key_private)}"
}
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'"
]
}
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 = "${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 = "${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"
]
}
}