Mongodb: add a swap volume.

This commit is contained in:
Andrea Dell'Amico 2024-07-12 18:27:49 +02:00
parent c38b2b3b29
commit b5e666e8e3
Signed by: andrea.dellamico
GPG Key ID: 147ABE6CEB9E20FF
4 changed files with 480 additions and 5 deletions

View File

@ -3,6 +3,7 @@ mongodb_cluster_data = {
name = "mongodb-replica"
flavor = "m2.large"
data_disk_size = 10000
swap_disk_size = 8
image_type_name = "Ubuntu-Focal-20.04"
image_type_uuid = "75c23040-2be7-49e9-8029-a16dc9f755d1"
}
@ -13,6 +14,7 @@ mongodb_vol_data = {
name = "mongodb-vol"
flavor = "m1.medium"
data_disk_size = 200
swap_disk_size = 8
image_type_name = "Ubuntu-Focal-20.04"
image_type_uuid = "75c23040-2be7-49e9-8029-a16dc9f755d1"
}

View File

@ -1,7 +1,7 @@
{
"version": 4,
"terraform_version": "1.7.5",
"serial": 66,
"serial": 77,
"lineage": "8125b507-dffc-191e-5c2e-5ad0afce4380",
"outputs": {},
"resources": [
@ -217,6 +217,27 @@
"postgreSQL": "PostgreSQL service",
"public_HTTPS": "Public HTTPS"
},
"shared_postgresql_network_data": {
"admin_state_up": true,
"all_tags": [],
"availability_zone_hints": [],
"description": "Network used to communicate with the shared postgresql service",
"dns_domain": "cloud.d4science.org.",
"external": false,
"id": "f6450bc8-1345-4b52-8f34-2903c0cca7f8",
"mtu": 8942,
"name": "postgresql-srv-net",
"port_security_enabled": true,
"qos_policy_id": "",
"region": "isti_area_pi_1",
"segments": [],
"shared": false,
"tags": [],
"tenant_id": "1b45adf388934758b56d0dfdb4bfacf3",
"timeouts": null,
"transparent_vlan": false,
"value_specs": null
},
"shared_postgresql_server_data": {
"allocation_pool_end": "192.168.3.254",
"allocation_pool_start": "192.168.0.100",
@ -234,6 +255,39 @@
"vol_data_name": "shared-postgresql-data",
"vol_data_size": "300"
},
"shared_postgresql_subnet_data": {
"all_tags": [],
"allocation_pool": [
{
"end": "192.168.3.254",
"start": "192.168.0.100"
}
],
"cidr": "192.168.0.0/22",
"description": "subnet used to connect to the shared PostgreSQL service",
"dns_nameservers": [
"146.48.29.97",
"146.48.29.98",
"146.48.29.99"
],
"enable_dhcp": true,
"gateway_ip": "",
"id": "761c3c40-5963-40df-a677-cd9b51b72b4d",
"ip_version": 4,
"ipv6_address_mode": "",
"ipv6_ra_mode": "",
"name": "shared-postgresql-subnet",
"network_id": "f6450bc8-1345-4b52-8f34-2903c0cca7f8",
"no_gateway": true,
"prefix_length": null,
"region": "isti_area_pi_1",
"service_types": [],
"subnetpool_id": "",
"tags": [],
"tenant_id": "1b45adf388934758b56d0dfdb4bfacf3",
"timeouts": null,
"value_specs": null
},
"smartexecutor_addresses": {},
"ssh_jump_proxy": {
"flavor": "m2.small",
@ -2063,10 +2117,119 @@
"map",
"string"
],
"shared_postgresql_network_data": [
"object",
{
"admin_state_up": "bool",
"all_tags": [
"set",
"string"
],
"availability_zone_hints": [
"set",
"string"
],
"description": "string",
"dns_domain": "string",
"external": "bool",
"id": "string",
"mtu": "number",
"name": "string",
"port_security_enabled": "bool",
"qos_policy_id": "string",
"region": "string",
"segments": [
"set",
[
"object",
{
"network_type": "string",
"physical_network": "string",
"segmentation_id": "number"
}
]
],
"shared": "bool",
"tags": [
"set",
"string"
],
"tenant_id": "string",
"timeouts": [
"object",
{
"create": "string",
"delete": "string"
}
],
"transparent_vlan": "bool",
"value_specs": [
"map",
"string"
]
}
],
"shared_postgresql_server_data": [
"map",
"string"
],
"shared_postgresql_subnet_data": [
"object",
{
"all_tags": [
"set",
"string"
],
"allocation_pool": [
"set",
[
"object",
{
"end": "string",
"start": "string"
}
]
],
"cidr": "string",
"description": "string",
"dns_nameservers": [
"list",
"string"
],
"enable_dhcp": "bool",
"gateway_ip": "string",
"id": "string",
"ip_version": "number",
"ipv6_address_mode": "string",
"ipv6_ra_mode": "string",
"name": "string",
"network_id": "string",
"no_gateway": "bool",
"prefix_length": "number",
"region": "string",
"service_types": [
"list",
"string"
],
"subnetpool_id": "string",
"tags": [
"set",
"string"
],
"tenant_id": "string",
"timeouts": [
"object",
{
"create": "string",
"delete": "string"
}
],
"value_specs": [
"map",
"string"
]
}
],
"smartexecutor_addresses": [
"map",
"string"
@ -5192,6 +5355,151 @@
}
]
},
{
"mode": "managed",
"type": "openstack_blockstorage_volume_v3",
"name": "mongodb_cluster_swap_vol",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [
{
"index_key": 0,
"schema_version": 0,
"attributes": {
"attachment": [],
"availability_zone": "nova",
"consistency_group_id": null,
"description": "",
"enable_online_resize": null,
"id": "d46aaaec-7502-4f0c-855a-ce6b0e8f6f42",
"image_id": null,
"metadata": {},
"multiattach": null,
"name": "swap-mongodb-replica-02",
"region": "isti_area_pi_1",
"scheduler_hints": [],
"size": 8,
"snapshot_id": "",
"source_replica": null,
"source_vol_id": "",
"timeouts": null,
"volume_type": "cephUnencrypted"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0="
},
{
"index_key": 1,
"schema_version": 0,
"attributes": {
"attachment": [],
"availability_zone": "nova",
"consistency_group_id": null,
"description": "",
"enable_online_resize": null,
"id": "c44cc719-545b-423d-b2b6-f25fa5cfc71c",
"image_id": null,
"metadata": {},
"multiattach": null,
"name": "swap-mongodb-replica-03",
"region": "isti_area_pi_1",
"scheduler_hints": [],
"size": 8,
"snapshot_id": "",
"source_replica": null,
"source_vol_id": "",
"timeouts": null,
"volume_type": "cephUnencrypted"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0="
},
{
"index_key": 2,
"schema_version": 0,
"attributes": {
"attachment": [],
"availability_zone": "nova",
"consistency_group_id": null,
"description": "",
"enable_online_resize": null,
"id": "b16cf091-f949-458b-87d8-cfaf66813f5f",
"image_id": null,
"metadata": {},
"multiattach": null,
"name": "swap-mongodb-replica-04",
"region": "isti_area_pi_1",
"scheduler_hints": [],
"size": 8,
"snapshot_id": "",
"source_replica": null,
"source_vol_id": "",
"timeouts": null,
"volume_type": "cephUnencrypted"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0="
},
{
"index_key": 3,
"schema_version": 0,
"attributes": {
"attachment": [],
"availability_zone": "nova",
"consistency_group_id": null,
"description": "",
"enable_online_resize": null,
"id": "b049e2ae-a2bb-4965-a2ed-033749b44f8e",
"image_id": null,
"metadata": {},
"multiattach": null,
"name": "swap-mongodb-replica-05",
"region": "isti_area_pi_1",
"scheduler_hints": [],
"size": 8,
"snapshot_id": "",
"source_replica": null,
"source_vol_id": "",
"timeouts": null,
"volume_type": "cephUnencrypted"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0="
}
]
},
{
"mode": "managed",
"type": "openstack_blockstorage_volume_v3",
"name": "mongodb_volatile__swap_vol",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"attachment": [],
"availability_zone": "nova",
"consistency_group_id": null,
"description": "",
"enable_online_resize": null,
"id": "1aa9de4e-077a-4b62-a61d-a0e0d1991c2d",
"image_id": null,
"metadata": {},
"multiattach": null,
"name": "mongodb vol swap volume",
"region": "isti_area_pi_1",
"scheduler_hints": [],
"size": 8,
"snapshot_id": "",
"source_replica": null,
"source_vol_id": "",
"timeouts": null,
"volume_type": "cephUnencrypted"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0="
}
]
},
{
"mode": "managed",
"type": "openstack_compute_floatingip_associate_v2",
@ -5688,7 +5996,7 @@
"region": "isti_area_pi_1",
"scheduler_hints": [
{
"additional_properties": null,
"additional_properties": {},
"build_near_host_ip": "",
"different_cell": [],
"different_host": [],
@ -5703,7 +6011,7 @@
"mongodb_cluster_traffic"
],
"stop_before_destroy": false,
"tags": null,
"tags": [],
"timeouts": null,
"updated": "2024-06-27 16:15:02 +0000 UTC",
"user_data": "bb83b25fd1219aa1b850ece9be8d7b0f31714608",
@ -5825,6 +6133,7 @@
"attributes": {
"id": "9b123bae-b320-439b-a638-3cdb20127d67",
"members": [
"c6b1d9c6-b3dc-4470-80b1-009f81b0284b",
"c49bbdcb-64a8-465c-8a8f-5473031cf149",
"123694fe-a8d6-4b00-99e6-316f5c47e104",
"3f8048f9-6e59-47d9-b47d-505e0d604e97"
@ -5846,6 +6155,135 @@
}
]
},
{
"mode": "managed",
"type": "openstack_compute_volume_attach_v2",
"name": "mongodb_cluster_swap_attach_vol",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [
{
"index_key": 0,
"schema_version": 0,
"attributes": {
"device": "/dev/vdc",
"id": "c49bbdcb-64a8-465c-8a8f-5473031cf149/d46aaaec-7502-4f0c-855a-ce6b0e8f6f42",
"instance_id": "c49bbdcb-64a8-465c-8a8f-5473031cf149",
"multiattach": null,
"region": "isti_area_pi_1",
"timeouts": null,
"vendor_options": [],
"volume_id": "d46aaaec-7502-4f0c-855a-ce6b0e8f6f42"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=",
"dependencies": [
"data.terraform_remote_state.privnet_dns_router",
"openstack_blockstorage_volume_v3.mongodb_cluster_swap_vol",
"openstack_compute_instance_v2.mongodb_cluster_nodes",
"openstack_compute_servergroup_v2.mongodb",
"openstack_networking_secgroup_v2.mongodb_cluster_traffic"
]
},
{
"index_key": 1,
"schema_version": 0,
"attributes": {
"device": "/dev/vdc",
"id": "3f8048f9-6e59-47d9-b47d-505e0d604e97/c44cc719-545b-423d-b2b6-f25fa5cfc71c",
"instance_id": "3f8048f9-6e59-47d9-b47d-505e0d604e97",
"multiattach": null,
"region": "isti_area_pi_1",
"timeouts": null,
"vendor_options": [],
"volume_id": "c44cc719-545b-423d-b2b6-f25fa5cfc71c"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=",
"dependencies": [
"data.terraform_remote_state.privnet_dns_router",
"openstack_blockstorage_volume_v3.mongodb_cluster_swap_vol",
"openstack_compute_instance_v2.mongodb_cluster_nodes",
"openstack_compute_servergroup_v2.mongodb",
"openstack_networking_secgroup_v2.mongodb_cluster_traffic"
]
},
{
"index_key": 2,
"schema_version": 0,
"attributes": {
"device": "/dev/vdc",
"id": "123694fe-a8d6-4b00-99e6-316f5c47e104/b16cf091-f949-458b-87d8-cfaf66813f5f",
"instance_id": "123694fe-a8d6-4b00-99e6-316f5c47e104",
"multiattach": null,
"region": "isti_area_pi_1",
"timeouts": null,
"vendor_options": [],
"volume_id": "b16cf091-f949-458b-87d8-cfaf66813f5f"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=",
"dependencies": [
"data.terraform_remote_state.privnet_dns_router",
"openstack_blockstorage_volume_v3.mongodb_cluster_swap_vol",
"openstack_compute_instance_v2.mongodb_cluster_nodes",
"openstack_compute_servergroup_v2.mongodb",
"openstack_networking_secgroup_v2.mongodb_cluster_traffic"
]
},
{
"index_key": 3,
"schema_version": 0,
"attributes": {
"device": "/dev/vdc",
"id": "c6b1d9c6-b3dc-4470-80b1-009f81b0284b/b049e2ae-a2bb-4965-a2ed-033749b44f8e",
"instance_id": "c6b1d9c6-b3dc-4470-80b1-009f81b0284b",
"multiattach": null,
"region": "isti_area_pi_1",
"timeouts": null,
"vendor_options": [],
"volume_id": "b049e2ae-a2bb-4965-a2ed-033749b44f8e"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=",
"dependencies": [
"data.terraform_remote_state.privnet_dns_router",
"openstack_blockstorage_volume_v3.mongodb_cluster_swap_vol",
"openstack_compute_instance_v2.mongodb_cluster_nodes",
"openstack_compute_servergroup_v2.mongodb",
"openstack_networking_secgroup_v2.mongodb_cluster_traffic"
]
}
]
},
{
"mode": "managed",
"type": "openstack_compute_volume_attach_v2",
"name": "mongodb_volatile_swap_attach_vol",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"device": "/dev/vdc",
"id": "1cbd5e71-b19d-49ab-bd5d-45d10adb7435/1aa9de4e-077a-4b62-a61d-a0e0d1991c2d",
"instance_id": "1cbd5e71-b19d-49ab-bd5d-45d10adb7435",
"multiattach": null,
"region": "isti_area_pi_1",
"timeouts": null,
"vendor_options": [],
"volume_id": "1aa9de4e-077a-4b62-a61d-a0e0d1991c2d"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=",
"dependencies": [
"data.terraform_remote_state.privnet_dns_router",
"openstack_blockstorage_volume_v3.mongodb_volatile__swap_vol",
"openstack_compute_instance_v2.mongodb_vol_node",
"openstack_networking_secgroup_v2.mongodb_cluster_traffic"
]
}
]
},
{
"mode": "managed",
"type": "openstack_dns_recordset_v2",
@ -6092,10 +6530,10 @@
"description": "MongoDB cluster node mongodb-replica-05",
"dns_domain": "",
"dns_name": "",
"fixed_ip": "",
"fixed_ip": "10.1.40.23",
"id": "530a4d43-742d-415d-9f9e-389922c3c17c",
"pool": "external-network",
"port_id": "",
"port_id": "13b84ff2-71fb-40ff-81a3-87f0ae0bff64",
"region": "isti_area_pi_1",
"subnet_id": null,
"subnet_ids": null,

View File

@ -59,6 +59,14 @@ resource "openstack_networking_secgroup_rule_v2" "mongodb_prometheus_exporter" {
remote_ip_prefix = join("/",[data.terraform_remote_state.infrastructure_data.outputs.prometheus_public_ip_address,"32"])
}
#
# Swap device
#
resource "openstack_blockstorage_volume_v3" "mongodb_cluster_swap_vol" {
count = var.mongodb_cluster_data.count
name = format("swap-%s-%02d", var.mongodb_cluster_data.name, count.index + 2)
size = var.mongodb_cluster_data.swap_disk_size
}
#
# Mongodb cluster VMs
#
@ -105,6 +113,15 @@ resource "openstack_compute_instance_v2" "mongodb_cluster_nodes" {
}
}
# Attach the swap volume
resource "openstack_compute_volume_attach_v2" "mongodb_cluster_swap_attach_vol" {
count = var.mongodb_cluster_data.count
instance_id = element(openstack_compute_instance_v2.mongodb_cluster_nodes.*.id, count.index)
volume_id = element(openstack_blockstorage_volume_v3.mongodb_cluster_swap_vol.*.id, count.index)
device = "/dev/vdc"
depends_on = [openstack_compute_instance_v2.mongodb_cluster_nodes]
}
# Allocate a floating IP
resource "openstack_networking_floatingip_v2" "mongodb_cluster_floating_ip" {
count = var.mongodb_cluster_data.count
@ -136,6 +153,14 @@ resource "openstack_dns_recordset_v2" "mongodb_cluster_dns_recordsets" {
#
# MongoDB vol node
#
#
# Swap device
#
resource "openstack_blockstorage_volume_v3" "mongodb_volatile__swap_vol" {
name = "mongodb vol swap volume"
size = var.mongodb_vol_data.swap_disk_size
}
# Instance
resource "openstack_compute_instance_v2" "mongodb_vol_node" {
name = "mongodb-vol"
@ -175,6 +200,14 @@ resource "openstack_compute_instance_v2" "mongodb_vol_node" {
}
}
# Attach the swap volume
resource "openstack_compute_volume_attach_v2" "mongodb_volatile_swap_attach_vol" {
instance_id = openstack_compute_instance_v2.mongodb_vol_node.id
volume_id = openstack_blockstorage_volume_v3.mongodb_volatile__swap_vol.id
device = "/dev/vdc"
depends_on = [openstack_compute_instance_v2.mongodb_vol_node]
}
# Allocate a floating IP
resource "openstack_networking_floatingip_v2" "mongodb_vol_floating_ip" {
pool = var.floating_ip_pools.main_public_ip_pool

View File

@ -5,6 +5,7 @@ variable "mongodb_cluster_data" {
name = "mongodb-replica"
flavor = "m1.small"
data_disk_size = 100
swap_disk_size = 8
image_type_name = "Ubuntu-Focal-20.04"
image_type_uuid = "75c23040-2be7-49e9-8029-a16dc9f755d1"
}
@ -22,6 +23,7 @@ variable "mongodb_vol_data" {
name = "mongodb-vol"
flavor = "m1.small"
data_disk_size = 100
swap_disk_size = 8
image_type_name = "Ubuntu-Focal-20.04"
image_type_uuid = "75c23040-2be7-49e9-8029-a16dc9f755d1"
}