From c9a0c6d6b2ad831fb00bbbf1e36ba4867e40736c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 16 Jan 2024 11:03:06 +0100 Subject: [PATCH] Added module dns_resources. Using it into geonetwork project --- .../d4s-production/geonetwork/main.tf | 89 ++++++++++++------- .../modules/dns_resources/dns_resource.tf | 15 ++++ openstack-tf/modules/dns_resources/outputs.tf | 4 + .../dns_resources/terraform-provider.tf | 11 +++ .../dns_resources/variables_dns_resources.tf | 23 +++++ 5 files changed, 109 insertions(+), 33 deletions(-) create mode 100644 openstack-tf/modules/dns_resources/dns_resource.tf create mode 100644 openstack-tf/modules/dns_resources/outputs.tf create mode 100644 openstack-tf/modules/dns_resources/terraform-provider.tf create mode 100644 openstack-tf/modules/dns_resources/variables_dns_resources.tf diff --git a/openstack-tf/d4s-production/geonetwork/main.tf b/openstack-tf/d4s-production/geonetwork/main.tf index 1cfd5a1..ca5aef6 100644 --- a/openstack-tf/d4s-production/geonetwork/main.tf +++ b/openstack-tf/d4s-production/geonetwork/main.tf @@ -36,9 +36,9 @@ module "instance_with_data_volume" { server_groups_ids = [], image_ref = module.common_variables.ubuntu_1804 volume = { - name = "geonetwork_ariadne_data_volume", - size = "20", - device = "/dev/vdb" + name = "geonetwork_ariadne_data_volume", + size = "20", + device = "/dev/vdb" } }, geonetwork_fisherieatlas = { @@ -50,9 +50,9 @@ module "instance_with_data_volume" { server_groups_ids = [], image_ref = module.common_variables.ubuntu_1804 volume = { - name = "geonetwork_fisherieatlas_data_volume", - size = "20", - device = "/dev/vdb" + name = "geonetwork_fisherieatlas_data_volume", + size = "20", + device = "/dev/vdb" } }, geonetwork_grsf = { @@ -64,9 +64,9 @@ module "instance_with_data_volume" { server_groups_ids = [], image_ref = module.common_variables.ubuntu_1804 volume = { - name = "geonetwork_grsf_data_volume", - size = "20", - device = "/dev/vdb" + name = "geonetwork_grsf_data_volume", + size = "20", + device = "/dev/vdb" } }, geonetwork_iotcss3 = { @@ -79,9 +79,9 @@ module "instance_with_data_volume" { server_groups_ids = [], image_ref = module.common_variables.ubuntu_1804 volume = { - name = "geonetwork_iotcss3_data_volume", - size = "20", - device = "/dev/vdb" + name = "geonetwork_iotcss3_data_volume", + size = "20", + device = "/dev/vdb" } }, geonetwork_sdilab = { @@ -93,9 +93,9 @@ module "instance_with_data_volume" { server_groups_ids = [], image_ref = module.common_variables.ubuntu_1804 volume = { - name = "geonetwork_sdilab_data_volume", - size = "20", - device = "/dev/vdb" + name = "geonetwork_sdilab_data_volume", + size = "20", + device = "/dev/vdb" } }, geonetwork_spatialdata = { @@ -107,9 +107,9 @@ module "instance_with_data_volume" { image_ref = module.common_variables.ubuntu_1804 server_groups_ids = [], volume = { - name = "geonetwork_spatialdata_data_volume", - size = "20", - device = "/dev/vdb" + name = "geonetwork_spatialdata_data_volume", + size = "20", + device = "/dev/vdb" } }, geonetwork_wecafcfirms = { @@ -121,9 +121,9 @@ module "instance_with_data_volume" { image_ref = module.common_variables.ubuntu_1804 server_groups_ids = [], volume = { - name = "geonetwork_wecafcfirms_data_volume", - size = "20", - device = "/dev/vdb" + name = "geonetwork_wecafcfirms_data_volume", + size = "20", + device = "/dev/vdb" } }, geonetwork_bluecloud = { @@ -135,9 +135,9 @@ module "instance_with_data_volume" { image_ref = module.common_variables.ubuntu_1804 server_groups_ids = [], volume = { - name = "geonetwork_bluecloud_data_volume", - size = "30", - device = "/dev/vdb" + name = "geonetwork_bluecloud_data_volume", + size = "30", + device = "/dev/vdb" } }, geonetwork_tunaatlas = { @@ -149,9 +149,9 @@ module "instance_with_data_volume" { image_ref = module.common_variables.ubuntu_1804 server_groups_ids = [], volume = { - name = "geonetwork_tunaatlas_data_volume", - size = "20", - device = "/dev/vdb" + name = "geonetwork_tunaatlas_data_volume", + size = "20", + device = "/dev/vdb" } }, geonetwork_globalfisheriesatlas = { @@ -163,9 +163,9 @@ module "instance_with_data_volume" { image_ref = module.common_variables.ubuntu_1804 server_groups_ids = [], volume = { - name = "geonetwork_globalfisheriesatlas_data_volume", - size = "20", - device = "/dev/vdb" + name = "geonetwork_globalfisheriesatlas_data_volume", + size = "20", + device = "/dev/vdb" } }, geonetwork_prod = { @@ -177,10 +177,33 @@ module "instance_with_data_volume" { image_ref = module.common_variables.ubuntu_1804 server_groups_ids = [], volume = { - name = "geonetwork_prod_data_volume", - size = "40", - device = "/dev/vdb" + name = "geonetwork_prod_data_volume", + size = "40", + device = "/dev/vdb" } } } } + +locals { + cname_target = "main-lb.${data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.zone_name}" +} + +# +# Add DNS record/s +# +module "dns_records_create" { + source = "../../modules/dns_resources" + + dns_resources_map = { + geonetwork-globalfisheriesatlas = { + zone_id = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone_id + name = join(".", ["geonetwork-globalfisheriesatlas", data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.zone_name]) + description = "Geonetwork geonetwork-globalfisheriesatlas" + ttl = 8600 + type = "CNAME" + records = [local.cname_target] + } + + } +} diff --git a/openstack-tf/modules/dns_resources/dns_resource.tf b/openstack-tf/modules/dns_resources/dns_resource.tf new file mode 100644 index 0000000..3f6744a --- /dev/null +++ b/openstack-tf/modules/dns_resources/dns_resource.tf @@ -0,0 +1,15 @@ + +# Module used +module "ssh_settings" { + source = "../../modules/ssh-key-ref" +} + +resource "openstack_dns_recordset_v2" "add_dns_recordset" { + for_each = var.dns_resources_map + zone_id = each.value.zone_id + name = each.value.name + description = each.value.description + ttl = each.value.ttl + type = each.value.type + records = each.value.records +} diff --git a/openstack-tf/modules/dns_resources/outputs.tf b/openstack-tf/modules/dns_resources/outputs.tf new file mode 100644 index 0000000..d339a59 --- /dev/null +++ b/openstack-tf/modules/dns_resources/outputs.tf @@ -0,0 +1,4 @@ + +output "dns_resources_map" { + value = var.dns_resources_map +} diff --git a/openstack-tf/modules/dns_resources/terraform-provider.tf b/openstack-tf/modules/dns_resources/terraform-provider.tf new file mode 100644 index 0000000..a931880 --- /dev/null +++ b/openstack-tf/modules/dns_resources/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/dns_resources/variables_dns_resources.tf b/openstack-tf/modules/dns_resources/variables_dns_resources.tf new file mode 100644 index 0000000..6516ab1 --- /dev/null +++ b/openstack-tf/modules/dns_resources/variables_dns_resources.tf @@ -0,0 +1,23 @@ + +#Default DNS resource is EMPTY. Override it to create a proper plan +variable "dns_resources_map" { + type = map(object({ + zone_id = string + name = string + description = string + ttl = number + type = string + records = list(string) + })) + default = { + dns_record = { + zone_id = "" + name = "", + description = "", + ttl = 8600, + type = "CNAME", + records = [] + } + } + +}