Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Terraform Module to create all privatelink dns zones

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.7 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | >= 4 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | >= 4, < 5.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | >= 4 |
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | >= 4, < 5.0 |

## Modules

Expand All @@ -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 |
|------|-------------|------|---------|:--------:|
| <a name="input_location"></a> [location](#input\_location) | Location used for the resource group and in some Private DNS Zones | `string` | n/a | yes |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of the resource group in which to create the resources. | `string` | n/a | yes |
| <a name="input_shortlocation"></a> [shortlocation](#input\_shortlocation) | shortcode of the location used in some Private DNS Zones | `string` | n/a | yes |
| <a name="input_additional_zones"></a> [additional\_zones](#input\_additional\_zones) | Additional Private DNS Zones to create | `list(string)` | `[]` | no |
| <a name="input_resource_group"></a> [resource\_group](#input\_resource\_group) | The name of the resource group in which to create the resources. | <pre>object({<br> name = string<br> })</pre> | <pre>{<br> "name": null<br>}</pre> | no |
| <a name="input_query_zones"></a> [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 |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to the resources. | `map(string)` | `{}` | no |
| <a name="input_virtual_network_id"></a> [virtual\_network\_id](#input\_virtual\_network\_id) | The ID of the virtual network to link the Private DNS Zones to | `string` | `null` | no |

Expand Down
11 changes: 4 additions & 7 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ provider "azurerm" {
module "private_dns_zones" {
source = "../.."

resource_group = {
name = "example-rg"
}

location = "West Europe"
shortlocation = "weu"
virtual_network_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet"
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"

# some sql database types need a dedicated DNS zone, supply them in a seperate list, i.e.
additional_zones = ["privatelink.a1b2c3d4e5f6.database.windows.net"]
Expand Down
15 changes: 11 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -9,10 +10,16 @@ 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
resource_group_name = azurerm_resource_group.this[0].name

tags = merge(
var.tags,
Expand All @@ -25,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

Expand Down
6 changes: 3 additions & 3 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -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"
value = azurerm_resource_group.this.id
description = "ID of the Resource Group created by the module"
value = azurerm_resource_group.this[0].id
}
6 changes: 3 additions & 3 deletions terraform.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
16 changes: 8 additions & 8 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down Expand Up @@ -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
}
Loading