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

Delete old_main

parent 61b1317d
# creates public and private keypair
resource "openstack_compute_keypair_v2" "test-keypair" {
name = "my-keypair"
}
# creates dmznet
resource "openstack_networking_network_v2" "terraform" {
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.terraform.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" "terraform" {
name = "borderrouter"
admin_state_up = "true"
external_network_id = "${data.openstack_networking_network_v2.terraform.id}"
}
# creates the router and subnet id using info defined above
resource "openstack_networking_router_interface_v2" "terraform" {
router_id = "${openstack_networking_router_v2.terraform.id}"
subnet_id = "${openstack_networking_subnet_v2.terraform.id}"
}
# creates a security group
resource "openstack_networking_secgroup_v2" "terraform" {
name = "terraform"
description = "Security group for the Terraform example instances"
}
# creates details of security group fir port 22 and creates security group id
resource "openstack_networking_secgroup_rule_v2" "terraform_22" {
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 22
port_range_max = 22
remote_ip_prefix = "0.0.0.0/0"
security_group_id = "${openstack_networking_secgroup_v2.terraform.id}"
}
# creates details of security group fir port 80 and creates security group id
resource "openstack_networking_secgroup_rule_v2" "terraform_80" {
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 80
port_range_max = 80
remote_ip_prefix = "0.0.0.0/0"
security_group_id = "${openstack_networking_secgroup_v2.terraform.id}"
}
# creates details of security group fir protocol icmp and creates security group id
resource "openstack_networking_secgroup_rule_v2" "terraform" {
direction = "ingress"
ethertype = "IPv4"
protocol = "icmp"
remote_ip_prefix = "0.0.0.0/0"
security_group_id = "${openstack_networking_secgroup_v2.terraform.id}"
}
# defines where floating ip will come from using variable from vars.tf
resource "openstack_networking_floatingip_v2" "terraform" {
pool = "${var.pool}"
}
# creates details for the instance using variables defined in vars.tf and resource for security groups
resource "openstack_compute_instance_v2" "terraform" {
name = "ohpc"
image_name = "${var.image}"
flavor_name = "${var.flavor}"
key_pair = "${openstack_compute_keypair_v2.test-keypair.name}"
security_groups = ["${openstack_networking_secgroup_v2.terraform.name}"]
# defines the instance id using info from datasources.tf
network {
uuid = "${openstack_networking_network_v2.terraform.id}"
}
}
# associates floating ip with the instance
resource "openstack_compute_floatingip_associate_v2" "terraform" {
floating_ip = "${openstack_networking_floatingip_v2.terraform.address}"
instance_id = "${openstack_compute_instance_v2.terraform.id}"
}
# creates clusternet
resource "openstack_networking_network_v2" "terraform2" {
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" "terraform2" {
name = "clustersubnet"
network_id = "${openstack_networking_network_v2.terraform2.id}"
cidr = "10.1.1.0/24"
ip_version = 4
}
# defines the instance and network id using info defined above
resource "openstack_compute_interface_attach_v2" "terraform2" {
instance_id = "${openstack_compute_instance_v2.terraform.id}"
network_id = "${openstack_networking_network_v2.terraform2.id}"
}
provisioner "remote-exec" {
inline = [
"hostnamectl set-hostname ohpc",
"yum install -y epel-release",
"yum install -y ansible git vim bash-completion",
"yum install -y NetworkManager",
"systemctl restart NetworkManager",
"nmcli con mod 'Wired connection 1' connection.id 'eth1'",
]
connection {
host = "${self.ipv4_address}" # The `self` variable is like `this` in many programming languages
type = "ssh" # in this case, `self` is the resource (the server).
user = "root"
private_key = "${file("~/.ssh/id_rsa")}"
}
}
provisioner "local-exec" {
environment {
PUBLIC_IP = "${self.ipv4_address}"
PRIVATE_IP = "${self.ipv4_address_private}"
}
working_dir = "$HOME/terraform-first-instance/terraform-openstack/CRI_XCBC/"
command = "ansible-playbook -c local -i hosts -l `hostname` 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