Skip to content
Snippets Groups Projects
Commit 026c5c0a authored by Ryan Jones's avatar Ryan Jones
Browse files

added modules directory

parent 02a89e5e
No related branches found
No related tags found
No related merge requests found
data "openstack_networking_network_v2" "public-network" {
name = var.public-network-name
}
# defines where floating ip will come from using variable from vars.tf
resource "openstack_networking_floatingip_v2" "ohpc_ip" {
pool = var.public-network-name
}
resource "openstack_networking_floatingip_v2" "ood_ip" {
pool = var.public-network-name
}
resource "openstack_compute_keypair_v2" "keypair" {
name = var.keypair-name
public_key = file(var.ssh-public-key)
}
# 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_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
}
network {
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)
}
}
# 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_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
}
network {
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)
}
}
# creates compute node
resource "openstack_compute_instance_v2" "c0" {
depends_on = [openstack_networking_subnet_v2.internal_subnet]
name = "c${count.index}"
image_name = var.image_compute
flavor_name = var.flavor
key_pair = openstack_compute_keypair_v2.keypair.name
security_groups = ["default"]
count = 2
# defines the networks of the instance
network {
name = var.internal-net
}
}
\ No newline at end of file
# creates dmznet
resource "openstack_networking_network_v2" "external_net" {
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
cidr = "192.168.100.0/24"
ip_version = 4
dns_nameservers = ["8.8.8.8"]
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
}
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" "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" "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
}
\ No newline at end of file
output "ohpc_address" {
value = openstack_networking_floatingip_v2.ohpc_ip.address
}
output "ood_address" {
value = openstack_networking_floatingip_v2.ood_ip.address
}
output "external_network_id" {
value = openstack_networking_network_v2.external_net.id
}
output "internal_network_id" {
value = openstack_networking_network_v2.internal_net.id
}
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_ohpc" {
default = "CentOS-7-x86_64-GenericCloud-1905"
}
variable "image_ood" {
default = "CentOS-7-x86_64-GenericCloud-1905"
}
variable "image_compute" {
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 "ood-instance-name" {
default = "ood"
}
variable "ood-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"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment