Using local.geoserver_instances to create the geoserver instances with specific properties

This commit is contained in:
Francesco Mangiacrapa 2023-11-28 11:30:47 +01:00
parent 5189753454
commit 1dd83a0469
6 changed files with 82 additions and 20 deletions

1
.gitignore vendored
View File

@ -18,7 +18,6 @@ crash.*.log
*.tfvars *.tfvars
*.tfvars.json *.tfvars.json
!*.auto.tfvars !*.auto.tfvars
!geoserver*.tfvars
# Ignore override files as they are usually used to override resources locally and so # Ignore override files as they are usually used to override resources locally and so
# are not checked in # are not checked in
override.tf override.tf

Binary file not shown.

View File

@ -205,3 +205,19 @@ variable "smartexecutor_addresses" {
module "ssh_settings" { module "ssh_settings" {
source = "../../modules/ssh-key-ref" source = "../../modules/ssh-key-ref"
} }
# Added by Francesco
variable "flavor_list" {
type = map(string)
default = {
c1_small = "c1.small" #RAM 2 - VCPUs 2
c1_medium = "c1.medium" #RAM 4 - VCPUs 4
c1_large = "c1.large" #RAM 8 - VCPUs 8
m1_medium = "m1.medium" #RAM 4 - VCPUs 2
m1_large = "m1.large" #RAM 8 - VCPUs 4
m1_xlarge = "m1.xlarge" #RAM 16 - VCPUs 8
m2_small = "m2.small" #RAM 8 - VCPUs 2
m2_medium = "m2.medium" #RAM 16 - VCPUs 4
m2_large = "m2.large" #RAM 32 - VCPUs 8
}
}

View File

@ -1,15 +1,60 @@
# Creates single geoserver instance
# # Geoserver attached volume - used for 'geoserver_data'
# resource "openstack_blockstorage_volume_v3" "geoserver_data_vol" {
# name = var.geoserver_basic_data.vol_data_name
# size = var.geoserver_basic_data.vol_data_size
# }
# # Geoserver instance
# resource "openstack_compute_instance_v2" "geoserver" {
# name = var.geoserver_basic.name
# availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu
# flavor_name = var.geoserver_basic.flavor
# key_pair = module.ssh_settings.ssh_key_name
# security_groups = [var.security_group_list.default, var.security_group_list.http_and_https_from_the_load_balancers]
# block_device {
# uuid = var.ubuntu_1804.uuid
# source_type = "image"
# volume_size = 10
# boot_index = 0
# destination_type = "volume"
# delete_on_termination = false
# }
# network {
# name = var.main_private_network.name
# }
# network {
# name = var.shared_postgresql_server_data.network_name
# }
# user_data = file("${var.ubuntu1804_data_file}")
# }
# # Attach the additional volume
# resource "openstack_compute_volume_attach_v2" "geoserver_data_attach_vol" {
# instance_id = openstack_compute_instance_v2.geoserver.id
# volume_id = openstack_blockstorage_volume_v3.geoserver_data_vol.id
# device = var.geoserver_basic_data.vol_data_device
# depends_on = [openstack_compute_instance_v2.geoserver]
# }
# Creates all the geoserver instances with volumes declared in the locals.geoserver_instances
# Geoserver attached volume - used for 'geoserver_data' # Geoserver attached volume - used for 'geoserver_data'
resource "openstack_blockstorage_volume_v3" "geoserver_data_vol" { resource "openstack_blockstorage_volume_v3" "geoserver_data_volume" {
name = var.geoserver_basic_data.vol_data_name for_each = local.geoserver_instances
size = var.geoserver_basic_data.vol_data_size name = each.value.vol_data_name
size = each.value.vol_data_size
} }
# Geoserver instance # Geoserver instance
resource "openstack_compute_instance_v2" "geoserver" { resource "openstack_compute_instance_v2" "geoserver" {
name = var.geoserver_basic.name for_each = local.geoserver_instances
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 = var.geoserver_basic.flavor flavor_name = each.value.flavor
key_pair = module.ssh_settings.ssh_key_name key_pair = module.ssh_settings.ssh_key_name
security_groups = [var.security_group_list.default, var.security_group_list.http_and_https_from_the_load_balancers] security_groups = [var.security_group_list.default, var.security_group_list.http_and_https_from_the_load_balancers]
block_device { block_device {
@ -32,8 +77,9 @@ 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" {
instance_id = openstack_compute_instance_v2.geoserver.id for_each = local.geoserver_instances
volume_id = openstack_blockstorage_volume_v3.geoserver_data_vol.id 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 device = var.geoserver_basic_data.vol_data_device
depends_on = [openstack_compute_instance_v2.geoserver] depends_on = [openstack_compute_instance_v2.geoserver]
} }

View File

@ -1,12 +0,0 @@
geoserver_basic = {
name = "geoserver-geoportal"
description = "Geoserver geoportal instance"
flavor = "c1.medium"
}
geoserver_basic_data = {
vol_data_name = "geoserver_data_volume"
vol_data_size = "40"
vol_data_device = "/dev/vdb"
}

View File

@ -15,3 +15,16 @@ variable "geoserver_basic_data" {
vol_data_device = "/dev/vdb" 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" },
"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" }
}
}