Skip to content
Snippets Groups Projects
Commit 5b8af06b authored by Ravi Tripathi's avatar Ravi Tripathi
Browse files

Merge branch 'feat_use_fixed_router_and_networks' into 'feat-test-keypair'

Use already existing networks to build terraform

See merge request rc/terraform-openstack!5
parents b4bc023f 3d1a6c5c
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,8 @@ variables: ...@@ -9,7 +9,8 @@ variables:
OS_AUTH_URL: "https://keystone.cloud.rc.uab.edu:5000/v3" OS_AUTH_URL: "https://keystone.cloud.rc.uab.edu:5000/v3"
TF_ROOT: ${CI_PROJECT_DIR}/ TF_ROOT: ${CI_PROJECT_DIR}/
TF_VAR_internal_network: "xdmod-packer-clusternet" TF_VAR_internal_network: "xdmod-packer-clusternet"
TF_VAR_external_network: "xdmod-packer-dmz" TF_VAR_external_network: "xdmod-packer-dmznet"
TF_VAR_flavor: "m1.medium"
GIT_SUBMODULE_STRATEGY: "recursive" GIT_SUBMODULE_STRATEGY: "recursive"
GIT_SUBMODULE_UPDATE_FLAGS: "--force" GIT_SUBMODULE_UPDATE_FLAGS: "--force"
...@@ -45,13 +46,11 @@ tf-apply: ...@@ -45,13 +46,11 @@ tf-apply:
tags: [build] tags: [build]
script: script:
- export BUILD_DATE=$(TZ=America/Chicago date +%Y%m%d%H%M%S) - export BUILD_DATE=$(TZ=America/Chicago date +%Y%m%d%H%M%S)
- export TF_VAR_internal_network="tf-clusternet-$BUILD_DATE"
- export TF_VAR_external_network="tf-dmznet-$BUILD_DATE"
- export TF_VAR_keypair_name="os-gen-keypair-$BUILD_DATE"
- XDMOD_IMAGES=($(openstack image list --sort-column Name --sort-descending -f value -c Name -c ID | grep -P ' xdmod-\d{14}$' | awk '{print $2}')) - XDMOD_IMAGES=($(openstack image list --sort-column Name --sort-descending -f value -c Name -c ID | grep -P ' xdmod-\d{14}$' | awk '{print $2}'))
- export TF_VAR_image_ohpc="${XDMOD_IMAGES[0]}" - export TF_VAR_image_ohpc="${XDMOD_IMAGES[0]}"
# - export TF_VAR_image_ohpc="xdmod-20230629191611" # - export TF_VAR_image_ohpc="xdmod-20230629191611"
- echo $TF_VAR_image_ohpc - echo $TF_VAR_image_ohpc
- export TF_VAR_keypair_name="os-gen-keypair-$BUILD_DATE"
- terraform apply -auto-approve || terraform destroy -auto-approve - terraform apply -auto-approve || terraform destroy -auto-approve
clean-up: clean-up:
......
...@@ -14,37 +14,6 @@ provider "openstack" { ...@@ -14,37 +14,6 @@ provider "openstack" {
} }
} }
# 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.id
}
output "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.id
}
# runs the floating-ip module - uses public network name defined above # runs the floating-ip module - uses public network name defined above
module "floating-ip-address" { module "floating-ip-address" {
source = "./floating-ip" source = "./floating-ip"
...@@ -72,17 +41,19 @@ output "keypair_name" { ...@@ -72,17 +41,19 @@ output "keypair_name" {
value = module.import-keypair.keypair_name value = module.import-keypair.keypair_name
} }
data "openstack_networking_network_v2" "external_net" {name = var.external_network}
data "openstack_networking_network_v2" "internal_net" {name = var.internal_network}
# runs the ohpc-instance module - creates ohpc instance using variables defined above # 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 # calls functions from dmz-network, import-keypair, and floating-ip-address modules to get values created there for use
module "create-ohpc-instance" { module "create-ohpc-instance" {
external_subnet_id = module.dmz-network.external_subnet_id
source = "./ohpc-instance" source = "./ohpc-instance"
ohpc_instance_name = var.ohpc_instance_name ohpc_instance_name = var.ohpc_instance_name
image_ohpc = var.image_ohpc image_ohpc = var.image_ohpc
flavor = var.flavor flavor = var.flavor
key_pair = module.import-keypair.keypair_name key_pair = module.import-keypair.keypair_name
external_network = module.dmz-network.id external_network = data.openstack_networking_network_v2.external_net.id
internal_network = module.cluster-network.id internal_network = data.openstack_networking_network_v2.internal_net.id
internal_ip = var.ohpc_private_ip internal_ip = var.ohpc_private_ip
floating_ip_ohpc = module.floating-ip-address.ohpc_address floating_ip_ohpc = module.floating-ip-address.ohpc_address
ohpc_user = var.ohpc_user ohpc_user = var.ohpc_user
...@@ -109,13 +80,12 @@ module "create-ohpc-instance" { ...@@ -109,13 +80,12 @@ module "create-ohpc-instance" {
# runs the nodes module - creates nodes using variables defined above # 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 # calls functions from cluster-network and import-keypair modules to get values created there for use
module "nodes" { module "nodes" {
internal_subnet_id = module.cluster-network.internal_subnet_id
source = "./nodes" source = "./nodes"
image_compute = var.image_compute image_compute = var.image_compute
flavor = var.flavor flavor = var.flavor
key_pair = module.import-keypair.keypair_name key_pair = module.import-keypair.keypair_name
compute_node_count = var.compute_node_count compute_node_count = var.compute_node_count
internal_network = module.cluster-network.id internal_network = data.openstack_networking_network_v2.internal_net.id
} }
# calls the outputs defined in the ohpc-instance module # calls the outputs defined in the ohpc-instance module
......
# is created in internal-network module and called in root module
variable "internal_subnet_id" {type = string}
variable "image_compute" {} variable "image_compute" {}
variable "flavor" {} variable "flavor" {}
...@@ -34,7 +31,6 @@ data "openstack_images_image_v2" "compute" { ...@@ -34,7 +31,6 @@ data "openstack_images_image_v2" "compute" {
# creates compute node # creates compute node
resource "openstack_compute_instance_v2" "compute" { resource "openstack_compute_instance_v2" "compute" {
depends_on = [var.internal_subnet_id]
name = "c${count.index}" name = "c${count.index}"
image_id = data.openstack_images_image_v2.compute.id image_id = data.openstack_images_image_v2.compute.id
flavor_name = var.flavor flavor_name = var.flavor
......
...@@ -9,7 +9,6 @@ required_version = ">= 0.14.0" ...@@ -9,7 +9,6 @@ required_version = ">= 0.14.0"
} }
} }
variable "external_subnet_id" {type = string}
variable "ohpc_instance_name" {} variable "ohpc_instance_name" {}
variable "image_ohpc" {} variable "image_ohpc" {}
...@@ -31,7 +30,6 @@ variable "ssh_private_key" {} ...@@ -31,7 +30,6 @@ variable "ssh_private_key" {}
# creates details for the OHPC instance # creates details for the OHPC instance
resource "openstack_compute_instance_v2" "ohpc" { resource "openstack_compute_instance_v2" "ohpc" {
depends_on = [var.external_subnet_id]
name = var.ohpc_instance_name name = var.ohpc_instance_name
image_name = var.image_ohpc image_name = var.image_ohpc
flavor_name = var.flavor flavor_name = var.flavor
......
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