From a494d283f903384a7aec843d4deddc043cfde6bc Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 19 Jul 2024 17:45:49 +0200 Subject: [PATCH] Added storagehub-3 on Ubuntu 24.04 --- openstack-tf/d4s-dev/storagehub/main.tf | 59 +++++- .../d4s-dev/storagehub/terraform.tfstate | 185 +++++++++++++++++- .../modules/common_variables/outputs.tf | 8 + .../modules/common_variables/variables.tf | 14 ++ .../openstack_vm_data_scripts/ubuntu2404.sh | 18 ++ 5 files changed, 280 insertions(+), 4 deletions(-) create mode 100644 openstack-tf/openstack_vm_data_scripts/ubuntu2404.sh diff --git a/openstack-tf/d4s-dev/storagehub/main.tf b/openstack-tf/d4s-dev/storagehub/main.tf index 9157672..801426a 100644 --- a/openstack-tf/d4s-dev/storagehub/main.tf +++ b/openstack-tf/d4s-dev/storagehub/main.tf @@ -34,8 +34,13 @@ resource "openstack_blockstorage_volume_v3" "storagehub_2204_1_dev_data_volume" size = "25" } +resource "openstack_blockstorage_volume_v3" "storagehub_3_dev_data_volume" { + name = "storagehub_3_data_volume" + size = "25" +} -# Instances + +# Instance 22.04 resource "openstack_compute_instance_v2" "storagehub_2204_1_dev" { name = "storagehub-2204-1" availability_zone_hints = module.common_variables.availability_zone_no_gpu_name @@ -73,12 +78,56 @@ resource "openstack_compute_instance_v2" "storagehub_2204_1_dev" { } +# Instances 3 +resource "openstack_compute_instance_v2" "storagehub_3_dev" { + name = "storagehub-3" + availability_zone_hints = module.common_variables.availability_zone_no_gpu_name + flavor_name = "m1.medium" + key_pair = module.ssh_settings.ssh_key_name + security_groups = [data.terraform_remote_state.privnet_dns_router.outputs.default_security_group_name, data.terraform_remote_state.privnet_dns_router.outputs.security_group_list.http_and_https_from_the_load_balancers] + block_device { + uuid = module.common_variables.ubuntu_2404.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 = toset([data.terraform_remote_state.privnet_dns_router.outputs.main_private_network.name, module.common_variables.networks_list.shared_postgresql]) + content { + name = network.value + } + } + + + # user_data script used + user_data = file("${module.common_variables.ubuntu_2404.user_data_file}") + # Do not replace the instance when the ssh key changes + lifecycle { + ignore_changes = [ + # Ignore changes to tags, e.g. because a management agent + # updates these based on some ruleset managed elsewhere. + key_pair, user_data, network + ] + } +} + + + resource "openstack_compute_volume_attach_v2" "storagehub_2204_1_dev_attach" { instance_id = openstack_compute_instance_v2.storagehub_2204_1_dev.id volume_id = openstack_blockstorage_volume_v3.storagehub_2204_1_dev_data_volume.id device = "/dev/vdb" } +resource "openstack_compute_volume_attach_v2" "storagehub_3_dev_attach" { + instance_id = openstack_compute_instance_v2.storagehub_3_dev.id + volume_id = openstack_blockstorage_volume_v3.storagehub_3_dev_data_volume.id + device = "/dev/vdb" +} locals { @@ -99,6 +148,14 @@ module "dns_records_create" { ttl = 8600 type = "CNAME" records = [local.cname_target] + }, + storagehub-3 = { + zone_id = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone_id + name = join(".", ["storagehub-3", data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.zone_name]) + description = "StorageHub 3" + ttl = 8600 + type = "CNAME" + records = [local.cname_target] } } } diff --git a/openstack-tf/d4s-dev/storagehub/terraform.tfstate b/openstack-tf/d4s-dev/storagehub/terraform.tfstate index 1ab36a5..a1f7715 100644 --- a/openstack-tf/d4s-dev/storagehub/terraform.tfstate +++ b/openstack-tf/d4s-dev/storagehub/terraform.tfstate @@ -1,7 +1,7 @@ { "version": 4, "terraform_version": "1.6.4", - "serial": 5, + "serial": 10, "lineage": "7ae19997-17fe-7f03-9bcb-e326176791ba", "outputs": {}, "resources": [ @@ -402,7 +402,13 @@ { "schema_version": 0, "attributes": { - "attachment": [], + "attachment": [ + { + "device": "/dev/vdb", + "id": "d036eaec-d5ff-448d-bd5e-fad39c45ae43", + "instance_id": "e46a5ce6-724a-4663-9352-67e8f0e6d847" + } + ], "availability_zone": "nova", "backup_id": "", "consistency_group_id": null, @@ -426,6 +432,39 @@ } ] }, + { + "mode": "managed", + "type": "openstack_blockstorage_volume_v3", + "name": "storagehub_3_dev_data_volume", + "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "attachment": [], + "availability_zone": "nova", + "backup_id": "", + "consistency_group_id": null, + "description": "", + "enable_online_resize": null, + "id": "760379aa-ba97-4d23-9e84-e10ddb7aae88", + "image_id": null, + "metadata": {}, + "name": "storagehub_3_data_volume", + "region": "isti_area_pi_1", + "scheduler_hints": [], + "size": 25, + "snapshot_id": "", + "source_replica": null, + "source_vol_id": "", + "timeouts": null, + "volume_type": "cephUnencrypted" + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=" + } + ] + }, { "mode": "managed", "type": "openstack_compute_instance_v2", @@ -498,7 +537,7 @@ "traffic_from_the_main_load_balancers" ], "stop_before_destroy": false, - "tags": null, + "tags": [], "timeouts": null, "updated": "2024-07-18 09:48:21 +0000 UTC", "user_data": "bb83b25fd1219aa1b850ece9be8d7b0f31714608", @@ -512,6 +551,92 @@ } ] }, + { + "mode": "managed", + "type": "openstack_compute_instance_v2", + "name": "storagehub_3_dev", + "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "access_ip_v4": "10.1.30.146", + "access_ip_v6": "", + "admin_pass": null, + "all_metadata": {}, + "all_tags": [], + "availability_zone": "cnr-isti-nova-a", + "availability_zone_hints": "cnr-isti-nova-a", + "block_device": [ + { + "boot_index": 0, + "delete_on_termination": false, + "destination_type": "volume", + "device_type": "", + "disk_bus": "", + "guest_format": "", + "multiattach": false, + "source_type": "image", + "uuid": "fc3f705d-3cf5-4866-8ef6-ff6e2cdd4075", + "volume_size": 10, + "volume_type": "" + } + ], + "config_drive": null, + "created": "2024-07-19 15:43:11 +0000 UTC", + "flavor_id": "4", + "flavor_name": "m1.medium", + "force_delete": false, + "id": "28fafca3-13db-48ce-8453-ae5a1bfd8640", + "image_id": "Attempt to boot from volume - no image supplied", + "image_name": null, + "key_pair": "Giancarlo Panichi", + "metadata": null, + "name": "storagehub-3", + "network": [ + { + "access_network": false, + "fixed_ip_v4": "10.1.30.146", + "fixed_ip_v6": "", + "mac": "fa:16:3e:58:5b:29", + "name": "d4s-dev-cloud-main", + "port": "", + "uuid": "e0af5eba-f24a-4d0d-8184-bc654b980c4a" + }, + { + "access_network": false, + "fixed_ip_v4": "192.168.2.6", + "fixed_ip_v6": "", + "mac": "fa:16:3e:82:98:4e", + "name": "postgresql-srv-net", + "port": "", + "uuid": "00422a4a-4b8b-4c85-acf9-ef733df842b9" + } + ], + "network_mode": null, + "personality": [], + "power_state": "active", + "region": "isti_area_pi_1", + "scheduler_hints": [], + "security_groups": [ + "default", + "traffic_from_the_main_load_balancers" + ], + "stop_before_destroy": false, + "tags": null, + "timeouts": null, + "updated": "2024-07-19 15:44:41 +0000 UTC", + "user_data": "bb83b25fd1219aa1b850ece9be8d7b0f31714608", + "vendor_options": [] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19", + "dependencies": [ + "data.terraform_remote_state.privnet_dns_router" + ] + } + ] + }, { "mode": "managed", "type": "openstack_compute_volume_attach_v2", @@ -541,6 +666,35 @@ } ] }, + { + "mode": "managed", + "type": "openstack_compute_volume_attach_v2", + "name": "storagehub_3_dev_attach", + "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "device": "/dev/vdb", + "id": "28fafca3-13db-48ce-8453-ae5a1bfd8640/760379aa-ba97-4d23-9e84-e10ddb7aae88", + "instance_id": "28fafca3-13db-48ce-8453-ae5a1bfd8640", + "multiattach": null, + "region": "isti_area_pi_1", + "tag": null, + "timeouts": null, + "vendor_options": [], + "volume_id": "760379aa-ba97-4d23-9e84-e10ddb7aae88" + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=", + "dependencies": [ + "data.terraform_remote_state.privnet_dns_router", + "openstack_blockstorage_volume_v3.storagehub_3_dev_data_volume", + "openstack_compute_instance_v2.storagehub_3_dev" + ] + } + ] + }, { "module": "module.dns_records_create", "mode": "managed", @@ -572,6 +726,31 @@ "dependencies": [ "data.terraform_remote_state.privnet_dns_router" ] + }, + { + "index_key": "storagehub-3", + "schema_version": 0, + "attributes": { + "description": "StorageHub 3", + "disable_status_check": false, + "id": "cbae638a-9d99-44aa-946c-0f5ffb7fc488/e810a552-62bf-451d-b78b-45138988b853", + "name": "storagehub-3.cloud-dev.d4science.org.", + "project_id": "e8f8ca72f30648a8b389b4e745ac83a9", + "records": [ + "main-lb.cloud-dev.d4science.org." + ], + "region": "isti_area_pi_1", + "timeouts": null, + "ttl": 8600, + "type": "CNAME", + "value_specs": null, + "zone_id": "cbae638a-9d99-44aa-946c-0f5ffb7fc488" + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwLCJ1cGRhdGUiOjYwMDAwMDAwMDAwMH19", + "dependencies": [ + "data.terraform_remote_state.privnet_dns_router" + ] } ] } diff --git a/openstack-tf/modules/common_variables/outputs.tf b/openstack-tf/modules/common_variables/outputs.tf index 8f6553b..f4f3fd8 100644 --- a/openstack-tf/modules/common_variables/outputs.tf +++ b/openstack-tf/modules/common_variables/outputs.tf @@ -52,6 +52,10 @@ output "ubuntu_2204" { value = var.ubuntu_2204 } +output "ubuntu_2404" { + value = var.ubuntu_2404 +} + output "centos_7" { value = var.centos_7 } @@ -68,6 +72,10 @@ output "ubuntu2204_data_file" { value = var.ubuntu2204_data_file } +output "ubuntu2404_data_file" { + value = var.ubuntu2404_data_file +} + output "el7_data_file" { value = var.el7_data_file } diff --git a/openstack-tf/modules/common_variables/variables.tf b/openstack-tf/modules/common_variables/variables.tf index ed3d22d..cd9f18c 100644 --- a/openstack-tf/modules/common_variables/variables.tf +++ b/openstack-tf/modules/common_variables/variables.tf @@ -56,6 +56,16 @@ variable "ubuntu_2204" { } } +variable "ubuntu_2404" { + type = map(string) + default = { + name = "Ubuntu-Noble-24.04.img" + uuid = "fc3f705d-3cf5-4866-8ef6-ff6e2cdd4075" + user_data_file = "../../openstack_vm_data_scripts/ubuntu2404.sh" + } +} + + variable "centos_7" { type = map(string) default = { @@ -80,6 +90,10 @@ variable "ubuntu2204_data_file" { default = "../../openstack_vm_data_scripts/ubuntu2204.sh" } +variable "ubuntu2404_data_file" { + default = "../../openstack_vm_data_scripts/ubuntu2404.sh" +} + variable "el7_data_file" { default = "../../openstack_vm_data_scripts/el7.sh" } diff --git a/openstack-tf/openstack_vm_data_scripts/ubuntu2404.sh b/openstack-tf/openstack_vm_data_scripts/ubuntu2404.sh new file mode 100644 index 0000000..2ce98b8 --- /dev/null +++ b/openstack-tf/openstack_vm_data_scripts/ubuntu2404.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +/usr/sbin/adduser --system --home /srv/ansible --shell /bin/bash --gecos "Used for the Ansible provisioning tasks" --group ansible + +# SSH keys of users authorized to execute ansible playbooks. +# The ones in the example belong to Andrea Dell'Amico and Tommaso Piccioli. +# Feel free to add yours if you are entitled to run the ansible provisioning on that server + +mkdir /srv/ansible/.ssh +echo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ovo8WS+qxcxpeBBnewEssgis2dzDSqx5HUmaOETAxxEHflapHWQLum0JjvXsG5jlf9jL44XJPkcHXAYk3gnhtyM0moJpUya+GX7+ttfWWvwxs0tYNDXNMRn91r1hMLWmas4D+T/Q== rcirillo@rcirillo-cnr" >> /srv/ansible/.ssh/authorized_keys +/bin/chown -R ansible:ansible /srv/ansible +/bin/chmod 700 /srv/ansible/.ssh +mkdir -p /etc/sudoers.d +echo "ansible ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/ansible-user +/bin/chmod 600 /etc/sudoers.d/ansible-user +