From 6441603dc2f9b8359e54eca2233b514edccc7d25 Mon Sep 17 00:00:00 2001 From: simoncolincap Date: Mon, 9 Oct 2023 11:16:12 +0000 Subject: [PATCH 1/6] OPS-5263 Added opentelekomcloud-csv-to-dns module --- modules/opentelekomcloud-csv-to-dns/main.tf | 15 +++++++++++++++ modules/opentelekomcloud-csv-to-dns/variables.tf | 9 +++++++++ modules/opentelekomcloud-csv-to-dns/versions.tf | 8 ++++++++ 3 files changed, 32 insertions(+) create mode 100644 modules/opentelekomcloud-csv-to-dns/main.tf create mode 100644 modules/opentelekomcloud-csv-to-dns/variables.tf create mode 100644 modules/opentelekomcloud-csv-to-dns/versions.tf diff --git a/modules/opentelekomcloud-csv-to-dns/main.tf b/modules/opentelekomcloud-csv-to-dns/main.tf new file mode 100644 index 0000000..59fa6f6 --- /dev/null +++ b/modules/opentelekomcloud-csv-to-dns/main.tf @@ -0,0 +1,15 @@ +resource "opentelekomcloud_dns_recordset_v2" "email_hpi_schul_cloud_de" { + + for_each = { for record in csvdecode(file(var.file_path)) : record.domain => record } + + zone_id = var.zone_id + name = lower("${each.value.domain}") + ttl = 300 + type = each.value.type + # txt records have a max length of 255 characters + records = [replace(each.value.record, "/(.{255})/", "$1\" \"")] + + lifecycle { + ignore_changes = [zone_id] + } +} diff --git a/modules/opentelekomcloud-csv-to-dns/variables.tf b/modules/opentelekomcloud-csv-to-dns/variables.tf new file mode 100644 index 0000000..8fa7714 --- /dev/null +++ b/modules/opentelekomcloud-csv-to-dns/variables.tf @@ -0,0 +1,9 @@ +variable "file_path" { + type = string + description = "Path to the CSV file containing the records to create, expected fields are domain, type and record." +} + +variable "zone_id" { + type = string + description = "OTC DNS zone ID." +} \ No newline at end of file diff --git a/modules/opentelekomcloud-csv-to-dns/versions.tf b/modules/opentelekomcloud-csv-to-dns/versions.tf new file mode 100644 index 0000000..0e597a3 --- /dev/null +++ b/modules/opentelekomcloud-csv-to-dns/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_version = ">= 1.5.4" + required_providers { + opentelekomcloud = { + source = "opentelekomcloud/opentelekomcloud" + } + } +} From f4ba435c0cc88e982d8668c4d4bb7499536085d6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 9 Oct 2023 11:17:27 +0000 Subject: [PATCH 2/6] terraform-docs: automated action --- modules/opentelekomcloud-csv-to-dns/README.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 modules/opentelekomcloud-csv-to-dns/README.md diff --git a/modules/opentelekomcloud-csv-to-dns/README.md b/modules/opentelekomcloud-csv-to-dns/README.md new file mode 100644 index 0000000..2276b26 --- /dev/null +++ b/modules/opentelekomcloud-csv-to-dns/README.md @@ -0,0 +1,30 @@ + + +## Providers + +| Name | Version | +|------|---------| +| [opentelekomcloud](#provider\_opentelekomcloud) | n/a | +## Modules + +No modules. +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [file\_path](#input\_file\_path) | Path to the CSV file containing the records to create, expected fields are domain, type and record. | `string` | n/a | yes | +| [zone\_id](#input\_zone\_id) | OTC DNS zone ID. | `string` | n/a | yes | +## Outputs + +No outputs. +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.5.4 | +## Resources + +| Name | Type | +|------|------| +| [opentelekomcloud_dns_recordset_v2.email_hpi_schul_cloud_de](https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest/docs/resources/dns_recordset_v2) | resource | + \ No newline at end of file From 9096f546de9749bc55038bbcc024324b5d058fe8 Mon Sep 17 00:00:00 2001 From: simoncolincap Date: Mon, 9 Oct 2023 14:59:15 +0000 Subject: [PATCH 3/6] OPS-5263 Comments from review --- modules/opentelekomcloud-csv-to-dns/main.tf | 4 ++-- modules/opentelekomcloud-csv-to-dns/variables.tf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/opentelekomcloud-csv-to-dns/main.tf b/modules/opentelekomcloud-csv-to-dns/main.tf index 59fa6f6..9238d30 100644 --- a/modules/opentelekomcloud-csv-to-dns/main.tf +++ b/modules/opentelekomcloud-csv-to-dns/main.tf @@ -1,6 +1,6 @@ -resource "opentelekomcloud_dns_recordset_v2" "email_hpi_schul_cloud_de" { +resource "opentelekomcloud_dns_recordset_v2" "records" { - for_each = { for record in csvdecode(file(var.file_path)) : record.domain => record } + for_each = { for record in csvdecode(file(var.csv_file_path)) : record.domain => record } zone_id = var.zone_id name = lower("${each.value.domain}") diff --git a/modules/opentelekomcloud-csv-to-dns/variables.tf b/modules/opentelekomcloud-csv-to-dns/variables.tf index 8fa7714..72c97dd 100644 --- a/modules/opentelekomcloud-csv-to-dns/variables.tf +++ b/modules/opentelekomcloud-csv-to-dns/variables.tf @@ -1,4 +1,4 @@ -variable "file_path" { +variable "csv_file_path" { type = string description = "Path to the CSV file containing the records to create, expected fields are domain, type and record." } From 90e26e810dc9c4064d178933e1461e81931db51c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 9 Oct 2023 15:00:41 +0000 Subject: [PATCH 4/6] terraform-docs: automated action --- modules/opentelekomcloud-csv-to-dns/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/opentelekomcloud-csv-to-dns/README.md b/modules/opentelekomcloud-csv-to-dns/README.md index 2276b26..8715a37 100644 --- a/modules/opentelekomcloud-csv-to-dns/README.md +++ b/modules/opentelekomcloud-csv-to-dns/README.md @@ -12,7 +12,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [file\_path](#input\_file\_path) | Path to the CSV file containing the records to create, expected fields are domain, type and record. | `string` | n/a | yes | +| [csv\_file\_path](#input\_csv\_file\_path) | Path to the CSV file containing the records to create, expected fields are domain, type and record. | `string` | n/a | yes | | [zone\_id](#input\_zone\_id) | OTC DNS zone ID. | `string` | n/a | yes | ## Outputs @@ -26,5 +26,5 @@ No outputs. | Name | Type | |------|------| -| [opentelekomcloud_dns_recordset_v2.email_hpi_schul_cloud_de](https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest/docs/resources/dns_recordset_v2) | resource | +| [opentelekomcloud_dns_recordset_v2.records](https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest/docs/resources/dns_recordset_v2) | resource | \ No newline at end of file From f4be5567bca4835f7901328e75cfcd034230e6c3 Mon Sep 17 00:00:00 2001 From: simoncolincap Date: Wed, 11 Oct 2023 06:27:55 +0000 Subject: [PATCH 5/6] OPS-5263 Add support for multiple records and description --- modules/opentelekomcloud-csv-to-dns/main.tf | 3 ++- modules/opentelekomcloud-csv-to-dns/variables.tf | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/opentelekomcloud-csv-to-dns/main.tf b/modules/opentelekomcloud-csv-to-dns/main.tf index 9238d30..17735a9 100644 --- a/modules/opentelekomcloud-csv-to-dns/main.tf +++ b/modules/opentelekomcloud-csv-to-dns/main.tf @@ -7,7 +7,8 @@ resource "opentelekomcloud_dns_recordset_v2" "records" { ttl = 300 type = each.value.type # txt records have a max length of 255 characters - records = [replace(each.value.record, "/(.{255})/", "$1\" \"")] + records = [ for record in split("|", each.value.record) : replace(record, "/(.{255})/", "$1\" \"")] + description = each.value.description lifecycle { ignore_changes = [zone_id] diff --git a/modules/opentelekomcloud-csv-to-dns/variables.tf b/modules/opentelekomcloud-csv-to-dns/variables.tf index 72c97dd..45d29a4 100644 --- a/modules/opentelekomcloud-csv-to-dns/variables.tf +++ b/modules/opentelekomcloud-csv-to-dns/variables.tf @@ -1,6 +1,6 @@ variable "csv_file_path" { type = string - description = "Path to the CSV file containing the records to create, expected fields are domain, type and record." + description = "Path to the CSV file containing the records to create, expected fields are domain, type, record and description (can be empty). Multiple records can be separated using a pipe (|) character." } variable "zone_id" { From c4948b92a4eea47367ba2e6e7393a1d28d86ef31 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 11 Oct 2023 06:30:56 +0000 Subject: [PATCH 6/6] terraform-docs: automated action --- modules/opentelekomcloud-csv-to-dns/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/opentelekomcloud-csv-to-dns/README.md b/modules/opentelekomcloud-csv-to-dns/README.md index 8715a37..8898936 100644 --- a/modules/opentelekomcloud-csv-to-dns/README.md +++ b/modules/opentelekomcloud-csv-to-dns/README.md @@ -12,7 +12,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [csv\_file\_path](#input\_csv\_file\_path) | Path to the CSV file containing the records to create, expected fields are domain, type and record. | `string` | n/a | yes | +| [csv\_file\_path](#input\_csv\_file\_path) | Path to the CSV file containing the records to create, expected fields are domain, type, record and description (can be empty). Multiple records can be separated using a pipe (\|) character. | `string` | n/a | yes | | [zone\_id](#input\_zone\_id) | OTC DNS zone ID. | `string` | n/a | yes | ## Outputs