diff --git a/external-network/main.tf b/external-network/main.tf index 403064c8d8b40ca0fffb1f33a0a6b005ee8f45cc..b5ff37a642b37d4b5618665b54654d2bd2d7ae49 100644 --- a/external-network/main.tf +++ b/external-network/main.tf @@ -1,12 +1,20 @@ +terraform { +required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.42.0" + } + } +} + # is created as a datasource this module and called in root module -variable "public_network_name" {type = "string"} +variable "public_network_name" {type = string} variable "name" {default = "dmz"} variable "admin_state_up" {} variable "enable_dhcp" {} - - data "openstack_networking_network_v2" "public_network" {name = var.public_network_name} # creates dmznet diff --git a/floating-ip/floating-main.tf b/floating-ip/floating-main.tf index a9581cfc9f299dd9ae31fcfe91cc2512f796ca57..0fbd567977d11e9d11c287065e0687ee0477afa6 100644 --- a/floating-ip/floating-main.tf +++ b/floating-ip/floating-main.tf @@ -1,5 +1,22 @@ variable "public_network_name" {} +terraform { +required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.42.0" + } + } +} + +provider "openstack" { + use_octavia = true + endpoint_overrides = { + "network" = "https://neutron-api.cloud.rc.uab.edu:9696/v2.0/" + } +} + # defines where floating ip will come from using variable public_network_name defined in root module resource "openstack_networking_floatingip_v2" "ohpc_ip" { diff --git a/internal-network/main.tf b/internal-network/main.tf index c3ad09bafadfded0e1305f5a0532d5373780e240..947098ea267f10ae92a71301806b861cfcb92ae9 100644 --- a/internal-network/main.tf +++ b/internal-network/main.tf @@ -2,6 +2,23 @@ variable "name" {default = "cluster"} variable "admin_state_up" { } variable "enable_dhcp" {} +terraform { +required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.42.0" + } + } +} + +provider "openstack" { + use_octavia = true + endpoint_overrides = { + "network" = "https://neutron-api.cloud.rc.uab.edu:9696/v2.0/" + } +} + # creates clusternet resource "openstack_networking_network_v2" "internal_network" { name = "${var.name}net" @@ -24,4 +41,4 @@ output "internal_network_id" { output "internal_subnet_id" { value = openstack_networking_subnet_v2.internal_subnet.id -} \ No newline at end of file +} diff --git a/key-pair/main.tf b/key-pair/main.tf index c65cda4ffc656ab1241197ed6d0a15533547bdaf..926ef4b64cf481e5f34f937ac7ac7ce026a9e49f 100644 --- a/key-pair/main.tf +++ b/key-pair/main.tf @@ -1,6 +1,23 @@ variable "keypair_name" {} variable "ssh_public_key" {} +terraform { +required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.42.0" + } + } +} + +provider "openstack" { + use_octavia = true + endpoint_overrides = { + "network" = "https://neutron-api.cloud.rc.uab.edu:9696/v2.0/" + } +} + resource "openstack_compute_keypair_v2" "keypair" { name = var.keypair_name public_key = file(var.ssh_public_key) diff --git a/main.tf b/main.tf index c95d2c2cd8f849093eb79e9e6b66e942429db731..619b8ac857b8f7937b75f2dbd3281ea76e256b51 100644 --- a/main.tf +++ b/main.tf @@ -1,30 +1,48 @@ +terraform { +required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.42.0" + } + } +} + +provider "openstack" { + endpoint_overrides = { + "network" = "https://neutron-api.cloud.rc.uab.edu:9696/v2.0/" + } +} + # runs the external-network module module "dmz-network" { source = "./external-network" # Default name var is in the module main file + name = var.external_network admin_state_up = var.admin_state_up enable_dhcp = var.enable_dhcp public_network_name = var.public_network_name } # calls the outputs defined in the external-network module output "external_network_id" { - value = "${module.dmz-network.external_network_id}" + value = module.dmz-network.external_network_id } output "router_id" { - value = "${module.dmz-network.router_id}" + value = module.dmz-network.router_id } # runs the internal-network module module "cluster-network" { source = "./internal-network" # Default name var is in the module main file + name = var.internal_network admin_state_up = var.admin_state_up enable_dhcp = var.enable_dhcp } # calls the outputs defined in the internal-network module output "internal_network_id" { - value = "${module.cluster-network.internal_network_id}" + value = module.cluster-network.internal_network_id } # runs the floating-ip module - uses public network name defined above @@ -35,11 +53,11 @@ module "floating-ip-address" { # calls the outputs defined in the floating-ip module output "floating_ip_ohpc" { - value = "${module.floating-ip-address.ohpc_address}" + value = module.floating-ip-address.ohpc_address } output "floating_ip_ood" { - value = "${module.floating-ip-address.ood_address}" + value = module.floating-ip-address.ood_address } # runs the key-pair module - imports local public key into openstack and give it the name defined above in the variables @@ -51,23 +69,22 @@ module "import-keypair" { # calls the outputs defined in the key-pair module output "keypair_name" { - value = "${module.import-keypair.keypair_name}" + value = module.import-keypair.keypair_name } # runs the ohpc-instance module - creates ohpc instance using variables defined above # calls functions from dmz-network, import-keypair, and floating-ip-address modules to get values created there for use module "create-ohpc-instance" { - external_subnet_id = "${module.dmz-network.external_subnet_id}" + external_subnet_id = module.dmz-network.external_subnet_id source = "./ohpc-instance" ohpc_instance_name = var.ohpc_instance_name image_ohpc = var.image_ohpc flavor = var.flavor - key_pair = "${module.import-keypair.keypair_name}" + key_pair = module.import-keypair.keypair_name external_network = var.external_network internal_network = var.internal_network internal_ip = var.ohpc_private_ip - floating_ip_ohpc = "${module.floating-ip-address.ohpc_address}" - host_prefix = var.host_prefix + floating_ip_ohpc = module.floating-ip-address.ohpc_address ohpc_user = var.ohpc_user ssh_private_key = var.ssh_private_key } @@ -75,16 +92,15 @@ module "create-ohpc-instance" { # runs the ood-instance module - creates ood instance using variables defined above # calls functions from cluster-network, import-keypair, and floating-ip-address modules to get values created there for use module "create-ood-instance" { - internal_subnet_id = "${module.cluster-network.internal_subnet_id}" + internal_subnet_id = module.cluster-network.internal_subnet_id source = "./ood-instance" ood_instance_name = var.ood_instance_name image_ood = var.image_ood flavor = var.flavor - key_pair = "${module.import-keypair.keypair_name}" + key_pair = module.import-keypair.keypair_name internal_network = var.internal_network - internal_ip = var.ood_private_ip external_network = var.external_network - floating_ip_ood = "${module.floating-ip-address.ood_address}" + floating_ip_ood = module.floating-ip-address.ood_address host_prefix = var.host_prefix ood_user = var.ood_user ssh_private_key = var.ssh_private_key @@ -93,23 +109,23 @@ module "create-ood-instance" { # runs the nodes module - creates nodes using variables defined above # calls functions from cluster-network and import-keypair modules to get values created there for use module "nodes" { - internal_subnet_id = "${module.cluster-network.internal_subnet_id}" + internal_subnet_id = module.cluster-network.internal_subnet_id source = "./nodes" image_compute = var.image_compute flavor = var.flavor - key_pair = "${module.import-keypair.keypair_name}" + key_pair = module.import-keypair.keypair_name compute_node_count = var.compute_node_count internal_network = var.internal_network } # calls the outputs defined in the ohpc-instance module output "ohpc-ssh_host" { - value = "${module.create-ohpc-instance.ssh_host}" + value = module.create-ohpc-instance.ssh_host } # calls the outputs defined in the ood-instance module output "ood-ssh_host" { - value = "${module.create-ood-instance.ssh_host}" + value = module.create-ood-instance.ssh_host } # compute node and ood post provision @@ -123,7 +139,7 @@ resource "null_resource" "ops" { connection { host = module.create-ohpc-instance.ssh_host - user = var.ohpc_user + user = var.ohpc_user private_key = file(var.ssh_private_key) } diff --git a/nodes/main.tf b/nodes/main.tf index dfeeeadd5fa32df3107c5e63258e0833506de556..5f81c5596c2496bdd723589003b093919443da39 100644 --- a/nodes/main.tf +++ b/nodes/main.tf @@ -1,15 +1,32 @@ # is created in internal-network module and called in root module -variable "internal_subnet_id" {type = "string"} +variable "internal_subnet_id" {type = string} variable "image_compute" {} variable "flavor" {} # is created in key-pair module and called in root module -variable "key_pair" {type = "string"} +variable "key_pair" {type = string} variable "compute_node_count" { } variable "internal_network" {} +terraform { +required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.42.0" + } + } +} + +provider "openstack" { + use_octavia = true + endpoint_overrides = { + "network" = "https://neutron-api.cloud.rc.uab.edu:9696/v2.0/" + } +} + data "openstack_images_image_v2" "compute" { name = var.image_compute most_recent = true @@ -35,7 +52,7 @@ resource "openstack_compute_instance_v2" "compute" { # defines the networks of the instance network { - name = var.internal_network + name = "${var.internal_network}net" } } diff --git a/ohpc-instance/main.tf b/ohpc-instance/main.tf index cf39081368c88a4208823ef9ea0af75dcf87ee35..3e135623cb292f91dddd9ca6dca58243c2cb078d 100644 --- a/ohpc-instance/main.tf +++ b/ohpc-instance/main.tf @@ -1,24 +1,39 @@ # is created in external-network module and called in root module -variable "external_subnet_id" {type = "string"} +variable "external_subnet_id" {type = string} variable "ohpc_instance_name" {} variable "image_ohpc" {} variable "flavor" {} # is created in key-pair module and called in root module -variable "key_pair" {type = "string"} +variable "key_pair" {type = string} variable "internal_network" {} variable "internal_ip" {} variable "external_network" {} # is created in floating-ip module and called in root module -variable "floating_ip_ohpc" {type = "string"} +variable "floating_ip_ohpc" {type = string} -variable "host_prefix" {} variable "ohpc_user" {} variable "ssh_private_key" {} +terraform { +required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.42.0" + } + } +} + +provider "openstack" { + use_octavia = true + endpoint_overrides = { + "network" = "https://neutron-api.cloud.rc.uab.edu:9696/v2.0/" + } +} # creates details for the OHPC instance resource "openstack_compute_instance_v2" "ohpc" { @@ -40,10 +55,10 @@ resource "openstack_compute_instance_v2" "ohpc" { # defines the networks of the instance network { - name = var.external_network + name = "${var.external_network}net" } network { - name = var.internal_network + name = "${var.internal_network}net" fixed_ip_v4 = var.internal_ip } } @@ -55,7 +70,7 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { # defines ssh connection connection { - host = format(var.host_prefix,element(split(".", var.floating_ip_ohpc),3,),) + host = var.floating_ip_ohpc user = var.ohpc_user private_key = file(var.ssh_private_key) } @@ -66,5 +81,5 @@ output "id" { } output "ssh_host" { - value = format(var.host_prefix,element(split(".", var.floating_ip_ohpc),3,),) + value = var.floating_ip_ohpc } diff --git a/ood-instance/main.tf b/ood-instance/main.tf index a6a4419dd94634936cb51b31187cb4349bf6656f..cbec17f8f363bafc5b5b995eff9c2ae71a071927 100644 --- a/ood-instance/main.tf +++ b/ood-instance/main.tf @@ -1,24 +1,40 @@ # is created in internal-network module and called in root module -variable "internal_subnet_id" {type = "string"} +variable "internal_subnet_id" {type = string} variable "ood_instance_name" {} variable "image_ood" {} variable "flavor" {} # is created in key-pair module and called in root module -variable "key_pair" {type = "string"} +variable "key_pair" {type = string} variable "internal_network" {} variable "internal_ip" {} variable "external_network" {} # is created in floating-ip module and called in root module -variable "floating_ip_ood" {type = "string"} +variable "floating_ip_ood" {type = string} variable "host_prefix" {} variable "ood_user" {} variable "ssh_private_key" {} +terraform { +required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.42.0" + } + } +} + +provider "openstack" { + use_octavia = true + endpoint_overrides = { + "network" = "https://neutron-api.cloud.rc.uab.edu:9696/v2.0/" + } +} # creates details for the OOD instance resource "openstack_compute_instance_v2" "ood" { diff --git a/vars.tf b/vars.tf index 00bbcd100a31a4f8cee76c2d3e64636e339588e9..ce6fc1b9be9ad2acb254263c771b1d8e7b465c66 100644 --- a/vars.tf +++ b/vars.tf @@ -6,28 +6,27 @@ variable "admin_state_up" {default = true} variable "enable_dhcp" {default = true} # variable for floating-ip - also used in exrernal network creation -variable "public_network_name" {default = "bright-external-flat-externalnet"} +variable "public_network_name" {default = "uab-campus"} # variables for keypair module -variable "keypair_name" {default = "os-gen-keypair"} +variable "keypair_name" {default = "os-gen-keypair-1"} variable "ssh_public_key" {default = "~/.ssh/id_rsa.pub"} # variables for instance modules variable "ohpc_instance_name" {default = "ohpc"} variable "ohpc_private_ip" {default = "10.1.1.10"} variable "ood_instance_name" { default = "ood"} -variable "image_ohpc" {default = "CentOS-7-x86_64-GenericCloud-1905"} -variable "image_ood" {default = "CentOS-7-x86_64-GenericCloud-1905"} +variable "image_ohpc" {default = "ohpc-V1"} +variable "image_ood" {default = ""} variable "ood_private_ip" {default = "10.1.1.11"} -variable "flavor" {default = "m1.medium"} -variable "internal_network" {default = "clusternet"} -variable "external_network" {default = "dmznet"} -variable "host_prefix" {default = "164.111.161.%s"} +variable "flavor" {default = "m1.xlarge"} +variable "internal_network" {default = "xdmod-cluster"} +variable "external_network" {default = "xdmod-dmz"} variable "ohpc_user" {default = "centos"} variable "ood_user" {default = "centos"} variable "ssh_private_key" {default = "~/.ssh/id_rsa"} # variables for node creation module -variable "image_compute" {default = "CentOS-7-x86_64-GenericCloud-1905"} -variable "compute_node_count" {default = 2} +variable "image_compute" {default = "compute-v1"} +variable "compute_node_count" {default = 1}