Merge pull request 'luca' (#9) from luca into main

Reviewed-on: InfraScience/infrastructure-as-code#9
This commit is contained in:
Luca Frosini 2023-12-05 16:03:07 +01:00
commit d07329d0c1
13 changed files with 373 additions and 55 deletions

View File

@ -17,26 +17,42 @@ data "terraform_remote_state" "privnet_dns_router" {
}
}
#
# Uses common_variables as module
#
module "common_variables" {
source = "../../modules/common_variables"
}
module "smartgears_service_generic" {
source = "../../modules/generic_smartgears_service"
#
# Creates the server group "accounting-service"
#
resource "openstack_compute_servergroup_v2" "accounting_service_server_group" {
name = "accounting-service"
policies = [module.common_variables.policy_list.soft_anti_affinity]
}
smartgears_service_instances_map = {
module "instance_without_data_volume" {
source = "../../modules/instance_without_data_volume"
instances_without_data_volume_map = {
accounting_service_1 = {
name = "accounting-service-1",
description = "This instance serves accounting service",
flavor = "m1.medium",
flavor = module.common_variables.flavor_list.m1_medium,
networks = ["d4s-dev-cloud-main", "timescaledb-net"],
security_groups = ["default", "http and https from the load balancers"]
block_device_uuid = "7ed6a2cd-2b07-482e-8ce4-f018dff16c89" #ubuntu_18_04.uuid of DEV
security_groups = [module.common_variables.security_group_list.default, module.common_variables.security_group_list.http_and_https_from_the_load_balancers],
server_groups_ids = [openstack_compute_servergroup_v2.accounting_service_server_group.id],
image_ref = module.common_variables.ubuntu_1804
},
accounting_service_2 = {
name = "accounting-service-2",
description = "This instance serves accounting service",
flavor = "m1.medium",
flavor = module.common_variables.flavor_list.m1_medium,
networks = ["d4s-dev-cloud-main", "timescaledb-net"],
security_groups = ["default", "http and https from the load balancers"]
block_device_uuid = "7ed6a2cd-2b07-482e-8ce4-f018dff16c89" #ubuntu_18_04.uuid of DEV
security_groups = [module.common_variables.security_group_list.default, module.common_variables.security_group_list.http_and_https_from_the_load_balancers],
server_groups_ids = [openstack_compute_servergroup_v2.accounting_service_server_group.id],
image_ref = module.common_variables.ubuntu_1804
}
}
}

View File

@ -17,26 +17,44 @@ data "terraform_remote_state" "privnet_dns_router" {
}
}
#
# Uses common_variables as module
#
module "common_variables" {
source = "../../modules/common_variables"
}
module "smartgears_service_generic" {
source = "../../modules/generic_smartgears_service"
smartgears_service_instances_map = {
#
# Creates the server group "gcat"
#
resource "openstack_compute_servergroup_v2" "gcat_server_group" {
name = "gcat"
policies = [module.common_variables.policy_list.soft_anti_affinity]
}
module "instance_without_data_volume" {
source = "../../modules/instance_without_data_volume"
instances_without_data_volume_map = {
gcat_1 = {
name = "gcat-1",
description = "This instance serves gcat service",
flavor = "m1.medium",
flavor = module.common_variables.flavor_list.m1_medium,
networks = ["d4s-dev-cloud-main"],
security_groups = ["default", "http and https from the load balancers"]
block_device_uuid = "7ed6a2cd-2b07-482e-8ce4-f018dff16c89" #ubuntu_18_04.uuid of DEV
security_groups = [module.common_variables.security_group_list.default, module.common_variables.security_group_list.http_and_https_from_the_load_balancers],
server_groups_ids = [openstack_compute_servergroup_v2.gcat_server_group.id],
image_ref = module.common_variables.ubuntu_1804
},
gcat_2 = {
name = "gcat-2",
description = "This instance serves gcat service",
flavor = "m1.medium",
flavor = module.common_variables.flavor_list.m1_medium,
networks = ["d4s-dev-cloud-main"],
security_groups = ["default", "http and https from the load balancers"]
block_device_uuid = "7ed6a2cd-2b07-482e-8ce4-f018dff16c89" #ubuntu_18_04.uuid of DEV
security_groups = [module.common_variables.security_group_list.default, module.common_variables.security_group_list.http_and_https_from_the_load_balancers],
server_groups_ids = [openstack_compute_servergroup_v2.gcat_server_group.id],
image_ref = module.common_variables.ubuntu_1804
}
}
}

View File

@ -1,7 +1,7 @@
{
"version": 4,
"terraform_version": "1.6.4",
"serial": 3,
"serial": 19,
"lineage": "8a740e95-13ce-029b-b372-f1b423772e3f",
"outputs": {},
"resources": [
@ -51,7 +51,38 @@
]
},
{
"module": "module.smartgears_service_generic",
"mode": "managed",
"type": "openstack_compute_servergroup_v2",
"name": "gcat_server_group",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "f580e6ef-93ec-4926-b7fb-6db6fc7160a5",
"members": [
"60eb54dd-39c7-42d9-8231-f360492e9405",
"4f58c353-0a5c-46a9-9ffb-19d70de366cb"
],
"name": "gcat",
"policies": [
"soft-anti-affinity"
],
"region": "isti_area_pi_1",
"rules": [
{
"max_server_per_host": 0
}
],
"value_specs": null
},
"sensitive_attributes": [],
"private": "bnVsbA=="
}
]
},
{
"module": "module.instance_without_data_volume",
"mode": "managed",
"type": "openstack_compute_instance_v2",
"name": "smartgears_service",
@ -61,7 +92,7 @@
"index_key": "gcat_1",
"schema_version": 0,
"attributes": {
"access_ip_v4": "10.1.31.228",
"access_ip_v4": "10.1.28.132",
"access_ip_v6": "",
"admin_pass": null,
"all_metadata": {},
@ -84,12 +115,12 @@
}
],
"config_drive": null,
"created": "2023-12-04 16:02:03 +0000 UTC",
"created": "2023-12-05 14:43:16 +0000 UTC",
"flavor_id": "4",
"flavor_name": "m1.medium",
"floating_ip": null,
"force_delete": false,
"id": "b3b38ab3-3efa-4c38-a1f9-ffb616b6f6d9",
"id": "5d8ebe4f-b77b-4fbf-9991-ea402da3d98c",
"image_id": "Attempt to boot from volume - no image supplied",
"image_name": null,
"key_pair": "pc-frosini_key",
@ -98,10 +129,10 @@
"network": [
{
"access_network": false,
"fixed_ip_v4": "10.1.31.228",
"fixed_ip_v4": "10.1.28.132",
"fixed_ip_v6": "",
"floating_ip": "",
"mac": "fa:16:3e:bd:10:bd",
"mac": "fa:16:3e:73:dd:c3",
"name": "d4s-dev-cloud-main",
"port": "",
"uuid": "e0af5eba-f24a-4d0d-8184-bc654b980c4a"
@ -111,7 +142,18 @@
"personality": [],
"power_state": "active",
"region": "isti_area_pi_1",
"scheduler_hints": [],
"scheduler_hints": [
{
"additional_properties": null,
"build_near_host_ip": "",
"different_cell": [],
"different_host": [],
"group": "f580e6ef-93ec-4926-b7fb-6db6fc7160a5",
"query": [],
"same_host": [],
"target_cell": ""
}
],
"security_groups": [
"default",
"http and https from the load balancers"
@ -119,19 +161,22 @@
"stop_before_destroy": false,
"tags": null,
"timeouts": null,
"updated": "2023-12-04 16:05:31 +0000 UTC",
"user_data": "47d4769e61324c305c4b70ed6673de4fad84150d",
"updated": "2023-12-05 14:43:49 +0000 UTC",
"user_data": "ef3d6e5deb29bd1e5de5a76ae6860f3ee872738c",
"vendor_options": [],
"volume": []
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19"
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19",
"dependencies": [
"openstack_compute_servergroup_v2.gcat_server_group"
]
},
{
"index_key": "gcat_2",
"schema_version": 0,
"attributes": {
"access_ip_v4": "10.1.28.108",
"access_ip_v4": "10.1.28.210",
"access_ip_v6": "",
"admin_pass": null,
"all_metadata": {},
@ -154,12 +199,12 @@
}
],
"config_drive": null,
"created": "2023-12-04 16:02:03 +0000 UTC",
"created": "2023-12-05 14:43:15 +0000 UTC",
"flavor_id": "4",
"flavor_name": "m1.medium",
"floating_ip": null,
"force_delete": false,
"id": "0aa5726b-f6cc-4127-8216-34cdbc679b5f",
"id": "91fe0237-c8ba-4396-ba8e-b66d33aeeffa",
"image_id": "Attempt to boot from volume - no image supplied",
"image_name": null,
"key_pair": "pc-frosini_key",
@ -168,10 +213,10 @@
"network": [
{
"access_network": false,
"fixed_ip_v4": "10.1.28.108",
"fixed_ip_v4": "10.1.28.210",
"fixed_ip_v6": "",
"floating_ip": "",
"mac": "fa:16:3e:33:94:ce",
"mac": "fa:16:3e:9d:22:fd",
"name": "d4s-dev-cloud-main",
"port": "",
"uuid": "e0af5eba-f24a-4d0d-8184-bc654b980c4a"
@ -181,7 +226,18 @@
"personality": [],
"power_state": "active",
"region": "isti_area_pi_1",
"scheduler_hints": [],
"scheduler_hints": [
{
"additional_properties": null,
"build_near_host_ip": "",
"different_cell": [],
"different_host": [],
"group": "f580e6ef-93ec-4926-b7fb-6db6fc7160a5",
"query": [],
"same_host": [],
"target_cell": ""
}
],
"security_groups": [
"default",
"http and https from the load balancers"
@ -189,13 +245,16 @@
"stop_before_destroy": false,
"tags": null,
"timeouts": null,
"updated": "2023-12-04 16:03:23 +0000 UTC",
"user_data": "47d4769e61324c305c4b70ed6673de4fad84150d",
"updated": "2023-12-05 14:43:53 +0000 UTC",
"user_data": "ef3d6e5deb29bd1e5de5a76ae6860f3ee872738c",
"vendor_options": [],
"volume": []
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19"
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19",
"dependencies": [
"openstack_compute_servergroup_v2.gcat_server_group"
]
}
]
}

View File

@ -17,26 +17,42 @@ data "terraform_remote_state" "privnet_dns_router" {
}
}
#
# Uses common_variables as module
#
module "common_variables" {
source = "../../modules/common_variables"
}
module "smartgears_service_generic" {
source = "../../modules/generic_smartgears_service"
#
# Creates the server group "grsf-publisher"
#
resource "openstack_compute_servergroup_v2" "grsf_publisher_server_group" {
name = "grsf-publisher"
policies = [module.common_variables.policy_list.soft_anti_affinity]
}
smartgears_service_instances_map = {
module "instance_without_data_volume" {
source = "../../modules/instance_without_data_volume"
instances_without_data_volume_map = {
grsf_publisher_1 = {
name = "grsf-publisher-1",
description = "This instance serves GRSF Publisher service",
flavor = "m1.medium",
flavor = module.common_variables.flavor_list.m1_medium,
networks = ["d4s-dev-cloud-main"],
security_groups = ["default", "http and https from the load balancers"]
block_device_uuid = "7ed6a2cd-2b07-482e-8ce4-f018dff16c89" #ubuntu_18_04.uuid of DEV
security_groups = [module.common_variables.security_group_list.default, module.common_variables.security_group_list.http_and_https_from_the_load_balancers],
server_groups_ids = [openstack_compute_servergroup_v2.grsf_publisher_server_group.id],
image_ref = module.common_variables.ubuntu_1804
},
grsf_publisher_2 = {
name = "grsf-publisher-2",
description = "This instance serves GRSF Publisher service",
flavor = "m1.medium",
flavor = module.common_variables.flavor_list.m1_medium,
networks = ["d4s-dev-cloud-main"],
security_groups = ["default", "http and https from the load balancers"]
block_device_uuid = "7ed6a2cd-2b07-482e-8ce4-f018dff16c89" #ubuntu_18_04.uuid of DEV
security_groups = [module.common_variables.security_group_list.default, module.common_variables.security_group_list.http_and_https_from_the_load_balancers],
server_groups_ids = [openstack_compute_servergroup_v2.grsf_publisher_server_group.id],
image_ref = module.common_variables.ubuntu_1804
}
}
}

View File

@ -17,26 +17,42 @@ data "terraform_remote_state" "privnet_dns_router" {
}
}
#
# Uses common_variables as module
#
module "common_variables" {
source = "../../modules/common_variables"
}
module "smartgears_service_generic" {
source = "../../modules/generic_smartgears_service"
#
# Creates the server group "resource-registry"
#
resource "openstack_compute_servergroup_v2" "resource_registry_server_group" {
name = "resource-registry"
policies = [module.common_variables.policy_list.soft_anti_affinity]
}
smartgears_service_instances_map = {
module "instance_without_data_volume" {
source = "../../modules/instance_without_data_volume"
instances_without_data_volume_map = {
resource_registry_1 = {
name = "resource-registry-1",
description = "This instance serves resource-registry service",
flavor = "m1.medium",
flavor = module.common_variables.flavor_list.m1_medium,
networks = ["d4s-dev-cloud-main", "orientdb-net"],
security_groups = ["default", "http and https from the load balancers"]
block_device_uuid = "7ed6a2cd-2b07-482e-8ce4-f018dff16c89" #ubuntu_18_04.uuid of DEV
security_groups = [module.common_variables.security_group_list.default, module.common_variables.security_group_list.http_and_https_from_the_load_balancers],
server_groups_ids = [openstack_compute_servergroup_v2.resource_registry_server_group.id],
image_ref = module.common_variables.ubuntu_1804
},
resource_registry_2 = {
name = "resource-registry-1",
description = "This instance serves resource-registry service",
flavor = "m1.medium",
networks = ["d4s-dev-cloud-main", "orientdb-net"],
security_groups = ["default", "http and https from the load balancers"]
block_device_uuid = "7ed6a2cd-2b07-482e-8ce4-f018dff16c89" #ubuntu_18_04.uuid of DEV
security_groups = [module.common_variables.security_group_list.default, module.common_variables.security_group_list.http_and_https_from_the_load_balancers],
server_groups_ids = [openstack_compute_servergroup_v2.resource_registry_server_group.id],
image_ref = module.common_variables.ubuntu_1804
}
}
}

View File

@ -0,0 +1,64 @@
# Module used
module "ssh_settings" {
source = "../../modules/ssh-key-ref"
}
# Module used
module "common_variables" {
source = "../../modules/common_variables"
}
resource "openstack_blockstorage_volume_v3" "instance_data_volume" {
for_each = var.instances_with_data_volume_map
name = each.value.volume.name
size = each.value.volume.size
}
# Generic smartgears_service instance
resource "openstack_compute_instance_v2" "instance_with_data_volume" {
for_each = var.instances_with_data_volume_map
name = each.value.name
availability_zone_hints = module.common_variables.availability_zone_no_gpu_name
flavor_name = each.value.flavor
key_pair = module.ssh_settings.ssh_key_name
security_groups = each.value.security_groups
block_device {
uuid = each.value.image_ref.uuid
source_type = "image"
volume_size = 10
boot_index = 0
destination_type = "volume"
delete_on_termination = false
}
# Creates the networks according to input networks
dynamic "network" {
for_each = each.value.networks
content {
name = network.value
}
}
# Creates the scheduler_hints (i.e. server groups) according to input server_groups_ids
dynamic "scheduler_hints" {
for_each = each.value.server_groups_ids
content {
group = scheduler_hints.value
}
}
#user_data script used
user_data = file("${each.value.image_ref.user_data_file}")
}
# Attach the additional volume
resource "openstack_compute_volume_attach_v2" "attach_volume" {
for_each = var.instances_with_data_volume_map
instance_id = openstack_compute_instance_v2.instance_with_data_volume[each.key].id
volume_id = openstack_blockstorage_volume_v3.instance_data_volume[each.key].id
device = each.value.volume.device
depends_on = [openstack_compute_instance_v2.instance_with_data_volume]
}

View File

@ -0,0 +1,4 @@
output "instances_with_data_volume_map" {
value = var.instances_with_data_volume_map
}

View File

@ -0,0 +1,11 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.53.0"
}
}
}

View File

@ -0,0 +1,27 @@
#Default smartgears_service is EMPTY. Override it to create a proper smartegears plan
variable "instances_with_data_volume_map" {
type = map(object({
name = string
description = string
flavor = string
networks = list(string)
security_groups = list(string)
server_groups_ids = list(string)
image_ref = map(string)
volume = map(string)
}))
default = {
smartgears_service = {
name = "",
description = "",
flavor = "",
networks = [],
security_groups = [],
server_groups_ids = [],
image_ref = {},
volume = {}
}
}
}

View File

@ -0,0 +1,47 @@
# Module used
module "ssh_settings" {
source = "../../modules/ssh-key-ref"
}
# Module used
module "common_variables" {
source = "../../modules/common_variables"
}
# Generic smartgears_service instance
resource "openstack_compute_instance_v2" "smartgears_service" {
for_each = var.instances_without_data_volume_map
name = each.value.name
availability_zone_hints = module.common_variables.availability_zone_no_gpu_name
flavor_name = each.value.flavor
key_pair = module.ssh_settings.ssh_key_name
security_groups = each.value.security_groups
block_device {
uuid = each.value.image_ref.uuid
source_type = "image"
volume_size = 10
boot_index = 0
destination_type = "volume"
delete_on_termination = false
}
# Creates the networks according to input networks
dynamic "network" {
for_each = each.value.networks
content {
name = network.value
}
}
# Creates the scheduler_hints (i.e. server groups) according to input server_groups_ids
dynamic "scheduler_hints" {
for_each = each.value.server_groups_ids
content {
group = scheduler_hints.value
}
}
#user_data script used
user_data = file("${each.value.image_ref.user_data_file}")
}

View File

@ -0,0 +1,4 @@
output "instances_without_data_volume_map" {
value = var.instances_without_data_volume_map
}

View File

@ -0,0 +1,11 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.53.0"
}
}
}

View File

@ -0,0 +1,25 @@
# Default instances without data volume is EMPTY. Override it to create a proper instance plan
variable "instances_without_data_volume_map" {
type = map(object({
name = string
description = string
flavor = string
networks = list(string)
security_groups = list(string)
server_groups_ids = list(string)
image_ref = map(string)
}))
default = {
smartgears_service = {
name = "",
description = "",
flavor = "",
networks = [],
security_groups = [],
server_groups_ids = [],
image_ref = {}
}
}
}