From b241902461b983e3549e5ed5336275ead5dcc81d Mon Sep 17 00:00:00 2001 From: Dennis van der Meulen Date: Tue, 4 Mar 2025 13:12:54 +0100 Subject: [PATCH 1/7] add query option --- main.tf | 11 +++++++++-- outputs.tf | 4 ++-- terraform.tf | 6 +++--- variables.tf | 16 ++++++++-------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/main.tf b/main.tf index 4e49815..003e7b3 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,6 @@ resource "azurerm_resource_group" "this" { - name = var.resource_group.name + count = var.query_zones ? 0 : 1 + name = var.resource_group_name location = var.location tags = merge( var.tags, @@ -9,8 +10,14 @@ resource "azurerm_resource_group" "this" { ) } +data "azurerm_private_dns_zone" "this" { + for_each = var.query_zones ? local.private_dns_zones : {} + name = each.key + resource_group_name = var.resource_group_name +} + resource "azurerm_private_dns_zone" "this" { - for_each = local.private_dns_zones + for_each = var.query_zones ? {} : local.private_dns_zones name = each.key resource_group_name = azurerm_resource_group.this.name diff --git a/outputs.tf b/outputs.tf index ab69baa..e489752 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,9 +1,9 @@ output "private_dns_zones" { description = "object with all created Private DNS Zones" - value = azurerm_private_dns_zone.this + value = var.query_zones ? data.azurerm_private_dns_zone.this : azurerm_private_dns_zone.this } output "resource_group_id" { - description = "ID of the Resource Group created by the module" + description = "ID of the Resource Group created by the module" value = azurerm_resource_group.this.id } \ No newline at end of file diff --git a/terraform.tf b/terraform.tf index ca9101b..da589f3 100644 --- a/terraform.tf +++ b/terraform.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 1.7" + required_version = ">= 1.9" required_providers { azurerm = { source = "hashicorp/azurerm" - version = ">= 4" + version = ">= 4, < 5.0" } } -} +} \ No newline at end of file diff --git a/variables.tf b/variables.tf index 7a8becd..43faa67 100644 --- a/variables.tf +++ b/variables.tf @@ -1,12 +1,6 @@ -variable "resource_group" { +variable "resource_group_name" { description = "The name of the resource group in which to create the resources." - type = object({ - name = string - }) - default = { - name = null - } - nullable = false + type = string } variable "location" { @@ -36,3 +30,9 @@ variable "virtual_network_id" { type = string default = null } + +variable "query_zones" { + description = "if set to true will query for created zones instead of creating them, used for creating vnet links" + type = bool + default = false +} From bcc31ed9450e4adf1cf8cbb117f3075345064f11 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 4 Mar 2025 12:19:01 +0000 Subject: [PATCH 2/7] docs(readme): update module usage --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 662a1e3..6183f9f 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,14 @@ Terraform Module to create all privatelink dns zones | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 1.7 | -| [azurerm](#requirement\_azurerm) | >= 4 | +| [terraform](#requirement\_terraform) | >= 1.9 | +| [azurerm](#requirement\_azurerm) | >= 4, < 5.0 | ## Providers | Name | Version | |------|---------| -| [azurerm](#provider\_azurerm) | >= 4 | +| [azurerm](#provider\_azurerm) | >= 4, < 5.0 | ## Modules @@ -26,15 +26,17 @@ No modules. | [azurerm_private_dns_zone.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone) | resource | | [azurerm_private_dns_zone_virtual_network_link.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone_virtual_network_link) | resource | | [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource | +| [azurerm_private_dns_zone.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/private_dns_zone) | data source | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [location](#input\_location) | Location used for the resource group and in some Private DNS Zones | `string` | n/a | yes | +| [resource\_group\_name](#input\_resource\_group\_name) | The name of the resource group in which to create the resources. | `string` | n/a | yes | | [shortlocation](#input\_shortlocation) | shortcode of the location used in some Private DNS Zones | `string` | n/a | yes | | [additional\_zones](#input\_additional\_zones) | Additional Private DNS Zones to create | `list(string)` | `[]` | no | -| [resource\_group](#input\_resource\_group) | The name of the resource group in which to create the resources. |
object({
name = string
})
|
{
"name": null
}
| no | +| [query\_zones](#input\_query\_zones) | if set to true will query for created zones instead of creating them, used for creating vnet links | `bool` | `false` | no | | [tags](#input\_tags) | A map of tags to assign to the resources. | `map(string)` | `{}` | no | | [virtual\_network\_id](#input\_virtual\_network\_id) | The ID of the virtual network to link the Private DNS Zones to | `string` | `null` | no | From a1b6ad0e51307b68dd85602c30f7b831c6857ba2 Mon Sep 17 00:00:00 2001 From: Dennis van der Meulen Date: Tue, 4 Mar 2025 13:20:54 +0100 Subject: [PATCH 3/7] fix example --- examples/basic/main.tf | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/basic/main.tf b/examples/basic/main.tf index ac7ea4a..dfb6d53 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -17,10 +17,7 @@ provider "azurerm" { module "private_dns_zones" { source = "../.." - resource_group = { - name = "example-rg" - } - + resource_group_name "example-rsg" location = "West Europe" shortlocation = "weu" virtual_network_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet" From 68c4dcc9927c575be17e80e697c775ad51131bf6 Mon Sep 17 00:00:00 2001 From: Dennis van der Meulen Date: Tue, 4 Mar 2025 13:22:23 +0100 Subject: [PATCH 4/7] fix example --- examples/basic/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/basic/main.tf b/examples/basic/main.tf index dfb6d53..9b553c6 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -17,7 +17,7 @@ provider "azurerm" { module "private_dns_zones" { source = "../.." - resource_group_name "example-rsg" + resource_group_name = "example-rsg" location = "West Europe" shortlocation = "weu" virtual_network_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet" From 09ce2464f61bc73bc7b2ae58e5541e2f9c90f16f Mon Sep 17 00:00:00 2001 From: Dennis van der Meulen Date: Tue, 4 Mar 2025 13:23:06 +0100 Subject: [PATCH 5/7] fix example --- examples/basic/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 9b553c6..ae0f8a2 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -18,9 +18,9 @@ module "private_dns_zones" { source = "../.." resource_group_name = "example-rsg" - location = "West Europe" - shortlocation = "weu" - virtual_network_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet" + location = "West Europe" + shortlocation = "weu" + virtual_network_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet" # some sql database types need a dedicated DNS zone, supply them in a seperate list, i.e. additional_zones = ["privatelink.a1b2c3d4e5f6.database.windows.net"] From b3dc1356bfd107b36b27cc2af2eddef74188046c Mon Sep 17 00:00:00 2001 From: Dennis van der Meulen Date: Tue, 4 Mar 2025 13:29:51 +0100 Subject: [PATCH 6/7] fix count --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 003e7b3..62468a4 100644 --- a/main.tf +++ b/main.tf @@ -19,7 +19,7 @@ data "azurerm_private_dns_zone" "this" { resource "azurerm_private_dns_zone" "this" { for_each = var.query_zones ? {} : local.private_dns_zones name = each.key - resource_group_name = azurerm_resource_group.this.name + resource_group_name = azurerm_resource_group.this[0].name tags = merge( var.tags, @@ -32,7 +32,7 @@ resource "azurerm_private_dns_zone" "this" { resource "azurerm_private_dns_zone_virtual_network_link" "this" { for_each = var.virtual_network_id != null ? local.private_dns_zones : {} name = "${each.key}-vnet-link" - resource_group_name = azurerm_resource_group.this.name + resource_group_name = azurerm_resource_group.this[0].name private_dns_zone_name = azurerm_private_dns_zone.this[each.key].name virtual_network_id = var.virtual_network_id From e956955166506b53be094e23f75ac02d91a7af2f Mon Sep 17 00:00:00 2001 From: Dennis van der Meulen Date: Tue, 4 Mar 2025 13:31:48 +0100 Subject: [PATCH 7/7] output with count --- outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outputs.tf b/outputs.tf index e489752..7e05b58 100644 --- a/outputs.tf +++ b/outputs.tf @@ -5,5 +5,5 @@ output "private_dns_zones" { output "resource_group_id" { description = "ID of the Resource Group created by the module" - value = azurerm_resource_group.this.id + value = azurerm_resource_group.this[0].id } \ No newline at end of file