From 944b280c42a824102c454b3a3a2ea347939c92f7 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 28 Nov 2023 16:40:10 +0100 Subject: [PATCH] Added and used map of objects instead of a local variable --- .../d4s-dev/geoserver/variables-geoserver.tf | 31 ++++++++++++++++++- openstack-tf/modules/geoserver/geoserver.tf | 22 ++++++++++--- .../modules/geoserver/variables-geoserver.tf | 27 ++++++++-------- 3 files changed, 62 insertions(+), 18 deletions(-) mode change 120000 => 100644 openstack-tf/d4s-dev/geoserver/variables-geoserver.tf diff --git a/openstack-tf/d4s-dev/geoserver/variables-geoserver.tf b/openstack-tf/d4s-dev/geoserver/variables-geoserver.tf deleted file mode 120000 index 36ea7702..00000000 --- a/openstack-tf/d4s-dev/geoserver/variables-geoserver.tf +++ /dev/null @@ -1 +0,0 @@ -../../modules/geoserver/variables-geoserver.tf \ No newline at end of file diff --git a/openstack-tf/d4s-dev/geoserver/variables-geoserver.tf b/openstack-tf/d4s-dev/geoserver/variables-geoserver.tf new file mode 100644 index 00000000..59e7ee4f --- /dev/null +++ b/openstack-tf/d4s-dev/geoserver/variables-geoserver.tf @@ -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" } + } + +} diff --git a/openstack-tf/modules/geoserver/geoserver.tf b/openstack-tf/modules/geoserver/geoserver.tf index 4d883c97..ca97c178 100644 --- a/openstack-tf/modules/geoserver/geoserver.tf +++ b/openstack-tf/modules/geoserver/geoserver.tf @@ -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' 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 size = each.value.vol_data_size } # Geoserver instance resource "openstack_compute_instance_v2" "geoserver" { - for_each = local.geoserver_instances + for_each = var.geoserver_instances_map name = each.value.name availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu flavor_name = each.value.flavor @@ -77,7 +91,7 @@ resource "openstack_compute_instance_v2" "geoserver" { # Attach the additional volume 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 volume_id = openstack_blockstorage_volume_v3.geoserver_data_volume[each.key].id device = var.geoserver_basic_data.vol_data_device diff --git a/openstack-tf/modules/geoserver/variables-geoserver.tf b/openstack-tf/modules/geoserver/variables-geoserver.tf index 9731ab59..17fa6cda 100644 --- a/openstack-tf/modules/geoserver/variables-geoserver.tf +++ b/openstack-tf/modules/geoserver/variables-geoserver.tf @@ -1,3 +1,4 @@ +#Not used variable "geoserver_basic" { type = map(string) default = { @@ -7,25 +8,25 @@ variable "geoserver_basic" { } } +#Default geoserver vol_data_device variable "geoserver_basic_data" { type = map(string) default = { - vol_data_name = "geoserver_data_volume" - vol_data_size = "20" vol_data_device = "/dev/vdb" } } -locals { - geoserver_instances = { - "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" }, - "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" }, - "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" }, - "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" }, - "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" }, - "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" }, - "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" }, - "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" } +#Default geoserver_instances_map is EMPTY. Override it to create a proper geoserver plan +variable "geoserver_instances_map" { + 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 = "" } } + }