Added and used map of objects instead of a local variable

This commit is contained in:
Francesco Mangiacrapa 2023-11-28 16:40:10 +01:00
parent a528af9b70
commit 944b280c42
3 changed files with 62 additions and 18 deletions

View File

@ -1 +0,0 @@
../../modules/geoserver/variables-geoserver.tf

View File

@ -0,0 +1,30 @@
#Default geoserver vol_data_device
variable "geoserver_basic_data" {
type = map(string)
default = {
vol_data_device = "/dev/vdb"
}
}
#Geoserver instances Map
variable "geoserver_instances_map" {
type = map(object({
name = string
description = string
flavor = string
vol_data_name = string
vol_data_size = string
}))
default = {
geona = { name = "geoserver-geona", description = "Geoserver geona instance", flavor = "m1.xlarge", vol_data_name = "geoserver-geona_data_volume", vol_data_size = "50" }
esquiline = { name = "geoserver-esquiline", description = "Geoserver esquiline instance", flavor = "m2.small", vol_data_name = "geoserver-esquiline_data_volume", vol_data_size = "20" }
ariadne = { name = "geoserver-ariadne", description = "Geoserver ariadne instance", flavor = "m2.small", vol_data_name = "geoserver-ariadne_data_volume", vol_data_size = "20" }
grsf = { name = "geoserver-grsf", description = "Geoserver grsf instance", flavor = "m1.large", vol_data_name = "geoserver-grsf_data_volume", vol_data_size = "40" }
protectedareaimpactmaps = { name = "geoserver-protectedareaimpactmaps", description = "Geoserver protectedareaimpactmaps instance", flavor = "c1.large", vol_data_name = "geoserver-protectedareaimpactmaps_data_volume", vol_data_size = "70" }
sdi-lab = { name = "geoserver-sdi-lab", description = "Geoserver sdi-lab instance", flavor = "m1.large", vol_data_name = "geoserver-sdi-lab_data_volume", vol_data_size = "100" }
tunaatlas = { name = "geoserver-tunaatlas", description = "Geoserver tunaatlas instance", flavor = "m1.large", vol_data_name = "geoserver-tunaatlas_data_volume", vol_data_size = "60" }
wecafc-firms = { name = "geoserver-wecafc-firms", description = "Geoserver wecafc-firms instance", flavor = "m1.large", vol_data_name = "geoserver-wecafc-firms_data_volume", vol_data_size = "40" }
aquacultureatlas = { name = "geoserver-aquacultureatlas", description = "Geoserver aquacultureatlas instance", flavor = "m1.large", vol_data_name = "geoserver-aquacultureatlas_data_volume", vol_data_size = "50" }
}
}

View File

@ -40,18 +40,32 @@
# } # }
# Creates all the geoserver instances with volumes declared in the locals.geoserver_instances # Creates all the geoserver instances with volumes declared in the var.geoserver_instances_map
# variable "geoserver_instances" {
# type = map(object({
# name = string
# description = string
# flavor = string
# vol_data_name = string
# vol_data_size = string
# }))
# default = {
# geoserver = { name = "", description = "", flavor = "", vol_data_name = "", vol_data_size = "" }
# }
# }
# Geoserver attached volume - used for 'geoserver_data' # Geoserver attached volume - used for 'geoserver_data'
resource "openstack_blockstorage_volume_v3" "geoserver_data_volume" { resource "openstack_blockstorage_volume_v3" "geoserver_data_volume" {
for_each = local.geoserver_instances for_each = var.geoserver_instances_map
name = each.value.vol_data_name name = each.value.vol_data_name
size = each.value.vol_data_size size = each.value.vol_data_size
} }
# Geoserver instance # Geoserver instance
resource "openstack_compute_instance_v2" "geoserver" { resource "openstack_compute_instance_v2" "geoserver" {
for_each = local.geoserver_instances for_each = var.geoserver_instances_map
name = each.value.name name = each.value.name
availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu
flavor_name = each.value.flavor flavor_name = each.value.flavor
@ -77,7 +91,7 @@ resource "openstack_compute_instance_v2" "geoserver" {
# Attach the additional volume # Attach the additional volume
resource "openstack_compute_volume_attach_v2" "geoserver_data_attach_vol" { resource "openstack_compute_volume_attach_v2" "geoserver_data_attach_vol" {
for_each = local.geoserver_instances for_each = var.geoserver_instances_map
instance_id = openstack_compute_instance_v2.geoserver[each.key].id instance_id = openstack_compute_instance_v2.geoserver[each.key].id
volume_id = openstack_blockstorage_volume_v3.geoserver_data_volume[each.key].id volume_id = openstack_blockstorage_volume_v3.geoserver_data_volume[each.key].id
device = var.geoserver_basic_data.vol_data_device device = var.geoserver_basic_data.vol_data_device

View File

@ -1,3 +1,4 @@
#Not used
variable "geoserver_basic" { variable "geoserver_basic" {
type = map(string) type = map(string)
default = { default = {
@ -7,25 +8,25 @@ variable "geoserver_basic" {
} }
} }
#Default geoserver vol_data_device
variable "geoserver_basic_data" { variable "geoserver_basic_data" {
type = map(string) type = map(string)
default = { default = {
vol_data_name = "geoserver_data_volume"
vol_data_size = "20"
vol_data_device = "/dev/vdb" vol_data_device = "/dev/vdb"
} }
} }
locals { #Default geoserver_instances_map is EMPTY. Override it to create a proper geoserver plan
geoserver_instances = { variable "geoserver_instances_map" {
"geona" = { name = "geoserver-geona", description = "Geoserver geona instance", flavor = var.flavor_list.m1_xlarge, vol_data_name = "geoserver-geona_data_volume", vol_data_size = "50" }, type = map(object({
"esquiline" = { name = "geoserver-esquiline", description = "Geoserver esquiline instance", flavor = var.flavor_list.m2_small, vol_data_name = "geoserver-esquiline_data_volume", vol_data_size = "20" }, name = string
"ariadne" = { name = "geoserver-ariadne", description = "Geoserver ariadne instance", flavor = var.flavor_list.m2_small, vol_data_name = "geoserver-ariadne_data_volume", vol_data_size = "20" }, description = string
"grsf" = { name = "geoserver-grsf", description = "Geoserver grsf instance", flavor = var.flavor_list.m1_large, vol_data_name = "geoserver-grsf_data_volume", vol_data_size = "40" }, flavor = string
"protectedareaimpactmaps" = { name = "geoserver-protectedareaimpactmaps", description = "Geoserver protectedareaimpactmaps instance", flavor = var.flavor_list.c1_large, vol_data_name = "geoserver-protectedareaimpactmaps_data_volume", vol_data_size = "70" }, vol_data_name = string
"sdi-lab" = { name = "geoserver-sdi-lab", description = "Geoserver sdi-lab instance", flavor = var.flavor_list.m1_large, vol_data_name = "geoserver-sdi-lab_data_volume", vol_data_size = "100" }, vol_data_size = string
"tunaatlas" = { name = "geoserver-tunaatlas", description = "Geoserver tunaatlas instance", flavor = var.flavor_list.m1_large, vol_data_name = "geoserver-tunaatlas_data_volume", vol_data_size = "60" }, }))
"wecafc-firms" = { name = "geoserver-wecafc-firms", description = "Geoserver wecafc-firms instance", flavor = var.flavor_list.m1_large, vol_data_name = "geoserver-wecafc-firms_data_volume", vol_data_size = "40" }, default = {
"aquacultureatlas" = { name = "geoserver-aquacultureatlas", description = "Geoserver aquacultureatlas instance", flavor = var.flavor_list.m1_large, vol_data_name = "geoserver-aquacultureatlas_data_volume", vol_data_size = "50" } geoserver = { name = "", description = "", flavor = "", vol_data_name = "", vol_data_size = "" }
} }
} }