From 89b9165f582ddefb61994a1ebac18e8791e9d21f Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 5 Dec 2023 12:12:07 +0100 Subject: [PATCH 1/5] Fixed gcat terraform plan --- openstack-tf/d4s-dev/gcat/main.tf | 30 +++++-- openstack-tf/d4s-dev/gcat/terraform.tfstate | 90 +++++++++++++++++---- 2 files changed, 97 insertions(+), 23 deletions(-) diff --git a/openstack-tf/d4s-dev/gcat/main.tf b/openstack-tf/d4s-dev/gcat/main.tf index ff15b8c0..bb980e3b 100644 --- a/openstack-tf/d4s-dev/gcat/main.tf +++ b/openstack-tf/d4s-dev/gcat/main.tf @@ -17,6 +17,22 @@ data "terraform_remote_state" "privnet_dns_router" { } } +# +# Uses common_variables as module +# +module "common_variables" { + source = "../../modules/common_variables" +} + + +# +# Creates the server group "uri-resolver" +# +resource "openstack_compute_servergroup_v2" "gcat_server_group" { + name = "gcat" + policies = [module.common_variables.policy_list.soft_anti_affinity] +} + module "smartgears_service_generic" { source = "../../modules/generic_smartgears_service" @@ -25,18 +41,20 @@ module "smartgears_service_generic" { 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 } } } diff --git a/openstack-tf/d4s-dev/gcat/terraform.tfstate b/openstack-tf/d4s-dev/gcat/terraform.tfstate index bc60d6f0..89402e19 100644 --- a/openstack-tf/d4s-dev/gcat/terraform.tfstate +++ b/openstack-tf/d4s-dev/gcat/terraform.tfstate @@ -1,7 +1,7 @@ { "version": 4, "terraform_version": "1.6.4", - "serial": 3, + "serial": 9, "lineage": "8a740e95-13ce-029b-b372-f1b423772e3f", "outputs": {}, "resources": [ @@ -50,6 +50,34 @@ } ] }, + { + "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": [], + "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.smartgears_service_generic", "mode": "managed", @@ -61,7 +89,7 @@ "index_key": "gcat_1", "schema_version": 0, "attributes": { - "access_ip_v4": "10.1.31.228", + "access_ip_v4": "10.1.31.87", "access_ip_v6": "", "admin_pass": null, "all_metadata": {}, @@ -84,12 +112,12 @@ } ], "config_drive": null, - "created": "2023-12-04 16:02:03 +0000 UTC", + "created": "2023-12-05 11:09:51 +0000 UTC", "flavor_id": "4", "flavor_name": "m1.medium", "floating_ip": null, "force_delete": false, - "id": "b3b38ab3-3efa-4c38-a1f9-ffb616b6f6d9", + "id": "d92bed2c-cca3-4681-8a40-d01a639ff6f3", "image_id": "Attempt to boot from volume - no image supplied", "image_name": null, "key_pair": "pc-frosini_key", @@ -98,10 +126,10 @@ "network": [ { "access_network": false, - "fixed_ip_v4": "10.1.31.228", + "fixed_ip_v4": "10.1.31.87", "fixed_ip_v6": "", "floating_ip": "", - "mac": "fa:16:3e:bd:10:bd", + "mac": "fa:16:3e:a1:e7:ee", "name": "d4s-dev-cloud-main", "port": "", "uuid": "e0af5eba-f24a-4d0d-8184-bc654b980c4a" @@ -111,7 +139,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 +158,22 @@ "stop_before_destroy": false, "tags": null, "timeouts": null, - "updated": "2023-12-04 16:05:31 +0000 UTC", + "updated": "2023-12-05 11:10:49 +0000 UTC", "user_data": "47d4769e61324c305c4b70ed6673de4fad84150d", "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.29.12", "access_ip_v6": "", "admin_pass": null, "all_metadata": {}, @@ -154,12 +196,12 @@ } ], "config_drive": null, - "created": "2023-12-04 16:02:03 +0000 UTC", + "created": "2023-12-05 11:09:51 +0000 UTC", "flavor_id": "4", "flavor_name": "m1.medium", "floating_ip": null, "force_delete": false, - "id": "0aa5726b-f6cc-4127-8216-34cdbc679b5f", + "id": "3cdfe9a1-61c4-4c3e-8f8e-5af2fa2e6f3d", "image_id": "Attempt to boot from volume - no image supplied", "image_name": null, "key_pair": "pc-frosini_key", @@ -168,10 +210,10 @@ "network": [ { "access_network": false, - "fixed_ip_v4": "10.1.28.108", + "fixed_ip_v4": "10.1.29.12", "fixed_ip_v6": "", "floating_ip": "", - "mac": "fa:16:3e:33:94:ce", + "mac": "fa:16:3e:4e:14:19", "name": "d4s-dev-cloud-main", "port": "", "uuid": "e0af5eba-f24a-4d0d-8184-bc654b980c4a" @@ -181,7 +223,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 +242,16 @@ "stop_before_destroy": false, "tags": null, "timeouts": null, - "updated": "2023-12-04 16:03:23 +0000 UTC", + "updated": "2023-12-05 11:10:25 +0000 UTC", "user_data": "47d4769e61324c305c4b70ed6673de4fad84150d", "vendor_options": [], "volume": [] }, "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19" + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19", + "dependencies": [ + "openstack_compute_servergroup_v2.gcat_server_group" + ] } ] } From 265f71f359e51737bd0bfbd1c7f3cf88eb295b08 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 5 Dec 2023 14:14:53 +0100 Subject: [PATCH 2/5] Fixed terraform gcat and resource-registry plan --- openstack-tf/d4s-dev/gcat/main.tf | 2 +- openstack-tf/d4s-dev/gcat/terraform.tfstate | 35 ++++++++++--------- .../d4s-dev/resource-registry/main.tf | 28 ++++++++++++--- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/openstack-tf/d4s-dev/gcat/main.tf b/openstack-tf/d4s-dev/gcat/main.tf index bb980e3b..6b02b94c 100644 --- a/openstack-tf/d4s-dev/gcat/main.tf +++ b/openstack-tf/d4s-dev/gcat/main.tf @@ -26,7 +26,7 @@ module "common_variables" { # -# Creates the server group "uri-resolver" +# Creates the server group "gcat" # resource "openstack_compute_servergroup_v2" "gcat_server_group" { name = "gcat" diff --git a/openstack-tf/d4s-dev/gcat/terraform.tfstate b/openstack-tf/d4s-dev/gcat/terraform.tfstate index 89402e19..150fe918 100644 --- a/openstack-tf/d4s-dev/gcat/terraform.tfstate +++ b/openstack-tf/d4s-dev/gcat/terraform.tfstate @@ -1,7 +1,7 @@ { "version": 4, "terraform_version": "1.6.4", - "serial": 9, + "serial": 14, "lineage": "8a740e95-13ce-029b-b372-f1b423772e3f", "outputs": {}, "resources": [ @@ -60,7 +60,10 @@ "schema_version": 0, "attributes": { "id": "f580e6ef-93ec-4926-b7fb-6db6fc7160a5", - "members": [], + "members": [ + "3cdfe9a1-61c4-4c3e-8f8e-5af2fa2e6f3d", + "d92bed2c-cca3-4681-8a40-d01a639ff6f3" + ], "name": "gcat", "policies": [ "soft-anti-affinity" @@ -89,7 +92,7 @@ "index_key": "gcat_1", "schema_version": 0, "attributes": { - "access_ip_v4": "10.1.31.87", + "access_ip_v4": "10.1.30.176", "access_ip_v6": "", "admin_pass": null, "all_metadata": {}, @@ -112,12 +115,12 @@ } ], "config_drive": null, - "created": "2023-12-05 11:09:51 +0000 UTC", + "created": "2023-12-05 11:41:32 +0000 UTC", "flavor_id": "4", "flavor_name": "m1.medium", "floating_ip": null, "force_delete": false, - "id": "d92bed2c-cca3-4681-8a40-d01a639ff6f3", + "id": "60eb54dd-39c7-42d9-8231-f360492e9405", "image_id": "Attempt to boot from volume - no image supplied", "image_name": null, "key_pair": "pc-frosini_key", @@ -126,10 +129,10 @@ "network": [ { "access_network": false, - "fixed_ip_v4": "10.1.31.87", + "fixed_ip_v4": "10.1.30.176", "fixed_ip_v6": "", "floating_ip": "", - "mac": "fa:16:3e:a1:e7:ee", + "mac": "fa:16:3e:31:89:35", "name": "d4s-dev-cloud-main", "port": "", "uuid": "e0af5eba-f24a-4d0d-8184-bc654b980c4a" @@ -158,8 +161,8 @@ "stop_before_destroy": false, "tags": null, "timeouts": null, - "updated": "2023-12-05 11:10:49 +0000 UTC", - "user_data": "47d4769e61324c305c4b70ed6673de4fad84150d", + "updated": "2023-12-05 11:42:04 +0000 UTC", + "user_data": "ef3d6e5deb29bd1e5de5a76ae6860f3ee872738c", "vendor_options": [], "volume": [] }, @@ -173,7 +176,7 @@ "index_key": "gcat_2", "schema_version": 0, "attributes": { - "access_ip_v4": "10.1.29.12", + "access_ip_v4": "10.1.28.116", "access_ip_v6": "", "admin_pass": null, "all_metadata": {}, @@ -196,12 +199,12 @@ } ], "config_drive": null, - "created": "2023-12-05 11:09:51 +0000 UTC", + "created": "2023-12-05 11:41:31 +0000 UTC", "flavor_id": "4", "flavor_name": "m1.medium", "floating_ip": null, "force_delete": false, - "id": "3cdfe9a1-61c4-4c3e-8f8e-5af2fa2e6f3d", + "id": "4f58c353-0a5c-46a9-9ffb-19d70de366cb", "image_id": "Attempt to boot from volume - no image supplied", "image_name": null, "key_pair": "pc-frosini_key", @@ -210,10 +213,10 @@ "network": [ { "access_network": false, - "fixed_ip_v4": "10.1.29.12", + "fixed_ip_v4": "10.1.28.116", "fixed_ip_v6": "", "floating_ip": "", - "mac": "fa:16:3e:4e:14:19", + "mac": "fa:16:3e:a0:2f:e6", "name": "d4s-dev-cloud-main", "port": "", "uuid": "e0af5eba-f24a-4d0d-8184-bc654b980c4a" @@ -242,8 +245,8 @@ "stop_before_destroy": false, "tags": null, "timeouts": null, - "updated": "2023-12-05 11:10:25 +0000 UTC", - "user_data": "47d4769e61324c305c4b70ed6673de4fad84150d", + "updated": "2023-12-05 11:42:08 +0000 UTC", + "user_data": "ef3d6e5deb29bd1e5de5a76ae6860f3ee872738c", "vendor_options": [], "volume": [] }, diff --git a/openstack-tf/d4s-dev/resource-registry/main.tf b/openstack-tf/d4s-dev/resource-registry/main.tf index a7cf0cce..c62a3bc3 100644 --- a/openstack-tf/d4s-dev/resource-registry/main.tf +++ b/openstack-tf/d4s-dev/resource-registry/main.tf @@ -17,6 +17,22 @@ data "terraform_remote_state" "privnet_dns_router" { } } +# +# Uses common_variables as module +# +module "common_variables" { + source = "../../modules/common_variables" +} + + +# +# 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] +} + module "smartgears_service_generic" { source = "../../modules/generic_smartgears_service" @@ -25,18 +41,20 @@ module "smartgears_service_generic" { 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 } } } From 58991984a3661b39bf61abc955209a82b77bd149 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 5 Dec 2023 15:55:09 +0100 Subject: [PATCH 3/5] Created generic modules --- .../instance_with_data_volume.tf | 64 +++++++++++++++++++ .../instance_with_data_volume/outputs.tf | 4 ++ .../terraform-provider.tf | 11 ++++ .../variables_generic_smartgears_service.tf | 27 ++++++++ .../instance_without_data_volume.tf | 47 ++++++++++++++ .../instance_without_data_volume/outputs.tf | 4 ++ .../terraform-provider.tf | 11 ++++ .../variables_generic_smartgears_service.tf | 25 ++++++++ 8 files changed, 193 insertions(+) create mode 100644 openstack-tf/modules/instance_with_data_volume/instance_with_data_volume.tf create mode 100644 openstack-tf/modules/instance_with_data_volume/outputs.tf create mode 100644 openstack-tf/modules/instance_with_data_volume/terraform-provider.tf create mode 100644 openstack-tf/modules/instance_with_data_volume/variables_generic_smartgears_service.tf create mode 100644 openstack-tf/modules/instance_without_data_volume/instance_without_data_volume.tf create mode 100644 openstack-tf/modules/instance_without_data_volume/outputs.tf create mode 100644 openstack-tf/modules/instance_without_data_volume/terraform-provider.tf create mode 100644 openstack-tf/modules/instance_without_data_volume/variables_generic_smartgears_service.tf diff --git a/openstack-tf/modules/instance_with_data_volume/instance_with_data_volume.tf b/openstack-tf/modules/instance_with_data_volume/instance_with_data_volume.tf new file mode 100644 index 00000000..abac3921 --- /dev/null +++ b/openstack-tf/modules/instance_with_data_volume/instance_with_data_volume.tf @@ -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 = var.each.value.volume.device + depends_on = [openstack_compute_instance_v2.instance_with_data_volume] +} diff --git a/openstack-tf/modules/instance_with_data_volume/outputs.tf b/openstack-tf/modules/instance_with_data_volume/outputs.tf new file mode 100644 index 00000000..c0cca10a --- /dev/null +++ b/openstack-tf/modules/instance_with_data_volume/outputs.tf @@ -0,0 +1,4 @@ + +output "instances_with_data_volume_map" { + value = var.instances_with_data_volume_map +} diff --git a/openstack-tf/modules/instance_with_data_volume/terraform-provider.tf b/openstack-tf/modules/instance_with_data_volume/terraform-provider.tf new file mode 100644 index 00000000..a4b36e6a --- /dev/null +++ b/openstack-tf/modules/instance_with_data_volume/terraform-provider.tf @@ -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" + } + } +} + diff --git a/openstack-tf/modules/instance_with_data_volume/variables_generic_smartgears_service.tf b/openstack-tf/modules/instance_with_data_volume/variables_generic_smartgears_service.tf new file mode 100644 index 00000000..5182a9d0 --- /dev/null +++ b/openstack-tf/modules/instance_with_data_volume/variables_generic_smartgears_service.tf @@ -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 = {} + } + } + +} diff --git a/openstack-tf/modules/instance_without_data_volume/instance_without_data_volume.tf b/openstack-tf/modules/instance_without_data_volume/instance_without_data_volume.tf new file mode 100644 index 00000000..5a52a057 --- /dev/null +++ b/openstack-tf/modules/instance_without_data_volume/instance_without_data_volume.tf @@ -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}") +} diff --git a/openstack-tf/modules/instance_without_data_volume/outputs.tf b/openstack-tf/modules/instance_without_data_volume/outputs.tf new file mode 100644 index 00000000..f9c0edd0 --- /dev/null +++ b/openstack-tf/modules/instance_without_data_volume/outputs.tf @@ -0,0 +1,4 @@ + +output "instances_without_data_volume_map" { + value = var.instances_without_data_volume_map +} diff --git a/openstack-tf/modules/instance_without_data_volume/terraform-provider.tf b/openstack-tf/modules/instance_without_data_volume/terraform-provider.tf new file mode 100644 index 00000000..a4b36e6a --- /dev/null +++ b/openstack-tf/modules/instance_without_data_volume/terraform-provider.tf @@ -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" + } + } +} + diff --git a/openstack-tf/modules/instance_without_data_volume/variables_generic_smartgears_service.tf b/openstack-tf/modules/instance_without_data_volume/variables_generic_smartgears_service.tf new file mode 100644 index 00000000..13be6131 --- /dev/null +++ b/openstack-tf/modules/instance_without_data_volume/variables_generic_smartgears_service.tf @@ -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 = {} + } + } + +} From 2f676b6130ea22b81349053c1ca31fd082ca0776 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 5 Dec 2023 15:56:40 +0100 Subject: [PATCH 4/5] Migrated services to generic module --- .../d4s-dev/accounting-service/main.tf | 34 ++++++++++++++----- openstack-tf/d4s-dev/gcat/main.tf | 6 ++-- openstack-tf/d4s-dev/gcat/terraform.tfstate | 32 ++++++++--------- openstack-tf/d4s-dev/grsf-publisher/main.tf | 34 ++++++++++++++----- .../d4s-dev/resource-registry/main.tf | 8 ++--- 5 files changed, 72 insertions(+), 42 deletions(-) diff --git a/openstack-tf/d4s-dev/accounting-service/main.tf b/openstack-tf/d4s-dev/accounting-service/main.tf index 2f8e849d..0b784b9d 100644 --- a/openstack-tf/d4s-dev/accounting-service/main.tf +++ b/openstack-tf/d4s-dev/accounting-service/main.tf @@ -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 } } } diff --git a/openstack-tf/d4s-dev/gcat/main.tf b/openstack-tf/d4s-dev/gcat/main.tf index 6b02b94c..eb20575b 100644 --- a/openstack-tf/d4s-dev/gcat/main.tf +++ b/openstack-tf/d4s-dev/gcat/main.tf @@ -34,10 +34,10 @@ resource "openstack_compute_servergroup_v2" "gcat_server_group" { } -module "smartgears_service_generic" { - source = "../../modules/generic_smartgears_service" +module "instance_without_data_volume" { + source = "../../modules/instance_without_data_volume" - smartgears_service_instances_map = { + instances_without_data_volume_map = { gcat_1 = { name = "gcat-1", description = "This instance serves gcat service", diff --git a/openstack-tf/d4s-dev/gcat/terraform.tfstate b/openstack-tf/d4s-dev/gcat/terraform.tfstate index 150fe918..771e3c4f 100644 --- a/openstack-tf/d4s-dev/gcat/terraform.tfstate +++ b/openstack-tf/d4s-dev/gcat/terraform.tfstate @@ -1,7 +1,7 @@ { "version": 4, "terraform_version": "1.6.4", - "serial": 14, + "serial": 19, "lineage": "8a740e95-13ce-029b-b372-f1b423772e3f", "outputs": {}, "resources": [ @@ -61,8 +61,8 @@ "attributes": { "id": "f580e6ef-93ec-4926-b7fb-6db6fc7160a5", "members": [ - "3cdfe9a1-61c4-4c3e-8f8e-5af2fa2e6f3d", - "d92bed2c-cca3-4681-8a40-d01a639ff6f3" + "60eb54dd-39c7-42d9-8231-f360492e9405", + "4f58c353-0a5c-46a9-9ffb-19d70de366cb" ], "name": "gcat", "policies": [ @@ -82,7 +82,7 @@ ] }, { - "module": "module.smartgears_service_generic", + "module": "module.instance_without_data_volume", "mode": "managed", "type": "openstack_compute_instance_v2", "name": "smartgears_service", @@ -92,7 +92,7 @@ "index_key": "gcat_1", "schema_version": 0, "attributes": { - "access_ip_v4": "10.1.30.176", + "access_ip_v4": "10.1.28.132", "access_ip_v6": "", "admin_pass": null, "all_metadata": {}, @@ -115,12 +115,12 @@ } ], "config_drive": null, - "created": "2023-12-05 11:41:32 +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": "60eb54dd-39c7-42d9-8231-f360492e9405", + "id": "5d8ebe4f-b77b-4fbf-9991-ea402da3d98c", "image_id": "Attempt to boot from volume - no image supplied", "image_name": null, "key_pair": "pc-frosini_key", @@ -129,10 +129,10 @@ "network": [ { "access_network": false, - "fixed_ip_v4": "10.1.30.176", + "fixed_ip_v4": "10.1.28.132", "fixed_ip_v6": "", "floating_ip": "", - "mac": "fa:16:3e:31:89:35", + "mac": "fa:16:3e:73:dd:c3", "name": "d4s-dev-cloud-main", "port": "", "uuid": "e0af5eba-f24a-4d0d-8184-bc654b980c4a" @@ -161,7 +161,7 @@ "stop_before_destroy": false, "tags": null, "timeouts": null, - "updated": "2023-12-05 11:42:04 +0000 UTC", + "updated": "2023-12-05 14:43:49 +0000 UTC", "user_data": "ef3d6e5deb29bd1e5de5a76ae6860f3ee872738c", "vendor_options": [], "volume": [] @@ -176,7 +176,7 @@ "index_key": "gcat_2", "schema_version": 0, "attributes": { - "access_ip_v4": "10.1.28.116", + "access_ip_v4": "10.1.28.210", "access_ip_v6": "", "admin_pass": null, "all_metadata": {}, @@ -199,12 +199,12 @@ } ], "config_drive": null, - "created": "2023-12-05 11:41:31 +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": "4f58c353-0a5c-46a9-9ffb-19d70de366cb", + "id": "91fe0237-c8ba-4396-ba8e-b66d33aeeffa", "image_id": "Attempt to boot from volume - no image supplied", "image_name": null, "key_pair": "pc-frosini_key", @@ -213,10 +213,10 @@ "network": [ { "access_network": false, - "fixed_ip_v4": "10.1.28.116", + "fixed_ip_v4": "10.1.28.210", "fixed_ip_v6": "", "floating_ip": "", - "mac": "fa:16:3e:a0:2f:e6", + "mac": "fa:16:3e:9d:22:fd", "name": "d4s-dev-cloud-main", "port": "", "uuid": "e0af5eba-f24a-4d0d-8184-bc654b980c4a" @@ -245,7 +245,7 @@ "stop_before_destroy": false, "tags": null, "timeouts": null, - "updated": "2023-12-05 11:42:08 +0000 UTC", + "updated": "2023-12-05 14:43:53 +0000 UTC", "user_data": "ef3d6e5deb29bd1e5de5a76ae6860f3ee872738c", "vendor_options": [], "volume": [] diff --git a/openstack-tf/d4s-dev/grsf-publisher/main.tf b/openstack-tf/d4s-dev/grsf-publisher/main.tf index 9a583e66..c8b5a710 100644 --- a/openstack-tf/d4s-dev/grsf-publisher/main.tf +++ b/openstack-tf/d4s-dev/grsf-publisher/main.tf @@ -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 } } } diff --git a/openstack-tf/d4s-dev/resource-registry/main.tf b/openstack-tf/d4s-dev/resource-registry/main.tf index c62a3bc3..23b4aa81 100644 --- a/openstack-tf/d4s-dev/resource-registry/main.tf +++ b/openstack-tf/d4s-dev/resource-registry/main.tf @@ -24,7 +24,6 @@ module "common_variables" { source = "../../modules/common_variables" } - # # Creates the server group "resource-registry" # @@ -33,11 +32,10 @@ resource "openstack_compute_servergroup_v2" "resource_registry_server_group" { policies = [module.common_variables.policy_list.soft_anti_affinity] } +module "instance_without_data_volume" { + source = "../../modules/instance_without_data_volume" -module "smartgears_service_generic" { - source = "../../modules/generic_smartgears_service" - - smartgears_service_instances_map = { + instances_without_data_volume_map = { resource_registry_1 = { name = "resource-registry-1", description = "This instance serves resource-registry service", From 8c0c3fbd78ab2207660591a2cd5b202f6e3e40a1 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 5 Dec 2023 16:02:41 +0100 Subject: [PATCH 5/5] Fixed module --- .../instance_with_data_volume/instance_with_data_volume.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openstack-tf/modules/instance_with_data_volume/instance_with_data_volume.tf b/openstack-tf/modules/instance_with_data_volume/instance_with_data_volume.tf index abac3921..023f6ad5 100644 --- a/openstack-tf/modules/instance_with_data_volume/instance_with_data_volume.tf +++ b/openstack-tf/modules/instance_with_data_volume/instance_with_data_volume.tf @@ -59,6 +59,6 @@ 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 = var.each.value.volume.device + device = each.value.volume.device depends_on = [openstack_compute_instance_v2.instance_with_data_volume] }