Skip to content

Commit

Permalink
feat(AZ-1088): apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
zfiel committed Nov 25, 2024
1 parent 04be372 commit 5866a8b
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 55 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ module "private_dns_resolver" {
resource_group_name = module.rg.name
## Bring Your Own VNet
# If set, `vnet_cidr` will not be used
# vnet_id = module.my_vnet.id
# If set, `virtual_network_id` will not be used
# virtual_network_id = module.my_vnet.id
vnet_cidr = local.private_dns_resolver_vnet_cidr
virtual_network_cidr = local.private_dns_resolver_vnet_cidr
inbound_endpoints = [
{
Expand Down Expand Up @@ -130,16 +130,16 @@ module "private_dns_resolver" {
]
dns_forwarding_rulesets = [
# VNets cannot be linked to multiple forwarding ruleset
# Therefore, keep in mind that the first ruleset is the default one because the VNet of the Private DNS Resolver is linked to this ruleset
# Virtual Networks cannot be linked to multiple forwarding ruleset
# Therefore, keep in mind that the first ruleset is the default one because the Virtual Network of the Private DNS Resolver is linked to this ruleset
{
name = "foo"
custom_name = "forwarding-ruleset"
# Ref to the first outbound endpoint
target_outbound_endpoints = ["foo"]
vnets_ids = slice(module.vnets_to_be_linked[*].id, 0, 4)
virtual_networks_ids = slice(module.vnets_to_be_linked[*].id, 0, 4)
rules = [
{
Expand All @@ -165,7 +165,7 @@ module "private_dns_resolver" {
# "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Network/dnsResolvers/dnsResolver1/outboundEndpoints/outboundEndpoint1",
]
vnets_ids = slice(module.vnets_to_be_linked[*].id, 4, 8)
virtual_networks_ids = slice(module.vnets_to_be_linked[*].id, 4, 8)
rules = [
{
Expand Down Expand Up @@ -221,7 +221,7 @@ module "private_dns_resolver" {
| client\_name | Client name/account used in naming. | `string` | n/a | yes |
| custom\_name | Custom Private DNS Resolver name, generated if not set. | `string` | `""` | no |
| default\_tags\_enabled | Option to enable or disable default tags. | `bool` | `true` | no |
| dns\_forwarding\_rulesets | List of DNS forwarding ruleset objects. The first DNS forwarding ruleset in the list is the default one because the VNet of the Private DNS Resolver is linked to it.<pre>name = Short DNS forwarding ruleset name, used to generate the DNS forwarding ruleset resource name.<br/>custom_name = Custom DNS forwarding ruleset name, overrides the DNS forwarding ruleset default resource name.<br/>target_outbound_endpoints = List of outbound endpoints to link to the DNS forwarding ruleset. Can be the short name of the outbound endpoint or an outbound endpoint ID.<br/>vnets_ids = List of VNets IDs to link to the DNS forwarding ruleset.<br/>rules = List of forwarding rule objects that the DNS forwarding ruleset contains.<br/> name = Short forwarding rule name, used to generate the forwarding rule resource name.<br/> domain_name = Specifies the target domain name of the forwarding rule.<br/> dns_servers_ips = List of target DNS servers IPs for the specified domain name.<br/> custom_name = Custom forwarding rule name, overrides the forwarding rule default resource name.<br/> enabled = Whether the forwarding rule is enabled or not. Default to `true`.</pre> | <pre>list(object({<br/> name = string<br/> custom_name = optional(string)<br/> target_outbound_endpoints = optional(list(string), [])<br/> vnets_ids = optional(list(string), [])<br/> rules = optional(list(object({<br/> name = string<br/> domain_name = string<br/> dns_servers_ips = list(string)<br/> custom_name = optional(string)<br/> enabled = optional(bool, true)<br/> })), [])<br/> }))</pre> | `[]` | no |
| dns\_forwarding\_rulesets | List of DNS forwarding ruleset objects. The first DNS forwarding ruleset in the list is the default one because the Virtual Network of the Private DNS Resolver is linked to it.<pre>name = Short DNS forwarding ruleset name, used to generate the DNS forwarding ruleset resource name.<br/>custom_name = Custom DNS forwarding ruleset name, overrides the DNS forwarding ruleset default resource name.<br/>target_outbound_endpoints = List of outbound endpoints to link to the DNS forwarding ruleset. Can be the short name of the outbound endpoint or an outbound endpoint ID.<br/>virtual_networks_ids = List of Virtual Networks IDs to link to the DNS forwarding ruleset.<br/>rules = List of forwarding rule objects that the DNS forwarding ruleset contains.<br/> name = Short forwarding rule name, used to generate the forwarding rule resource name.<br/> domain_name = Specifies the target domain name of the forwarding rule.<br/> dns_servers_ips = List of target DNS servers IPs for the specified domain name.<br/> custom_name = Custom forwarding rule name, overrides the forwarding rule default resource name.<br/> enabled = Whether the forwarding rule is enabled or not. Default to `true`.</pre> | <pre>list(object({<br/> name = string<br/> custom_name = optional(string)<br/> target_outbound_endpoints = optional(list(string), [])<br/> virtual_networks_ids = optional(list(string), [])<br/> rules = optional(list(object({<br/> name = string<br/> domain_name = string<br/> dns_servers_ips = list(string)<br/> custom_name = optional(string)<br/> enabled = optional(bool, true)<br/> })), [])<br/> }))</pre> | `[]` | no |
| environment | Project environment. | `string` | n/a | yes |
| extra\_tags | Extra tags to add. | `map(string)` | `{}` | no |
| inbound\_endpoints | List of inbound endpoint objects.<pre>name = Short inbound endpoint name, used to generate the inbound endpoint resource name.<br/>cidr = CIDR of the inbound endpoint Subnet.<br/>custom_name = Custom inbound endpoint name, overrides the inbound endpoint default resource name.<br/>subnet_custom_name = Custom Subnet name, overrides the Subnet default resource name.<br/>default_outbound_access_enabled = Enable or disable default outbound access in Azure. See [documentation](https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/default-outbound-access).</pre> | <pre>list(object({<br/> name = string<br/> cidr = string<br/> custom_name = optional(string)<br/> subnet_custom_name = optional(string)<br/> default_outbound_access_enabled = optional(bool, false)<br/> }))</pre> | `[]` | no |
Expand All @@ -232,9 +232,9 @@ module "private_dns_resolver" {
| outbound\_endpoints | List of outbound endpoint objects.<pre>name = Short outbound endpoint name, used to generate the outbound endpoint resource name.<br/>cidr = CIDR of the outbound endpoint Subnet.<br/>custom_name = Custom outbound endpoint name, overrides the outbound endpoint default resource name.<br/>subnet_custom_name = Custom Subnet name, overrides the Subnet default resource name.<br/>default_outbound_access_enabled = Enable or disable default outbound access in Azure. See [documentation](https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/default-outbound-access).</pre> | <pre>list(object({<br/> name = string<br/> cidr = string<br/> custom_name = optional(string)<br/> subnet_custom_name = optional(string)<br/> default_outbound_access_enabled = optional(bool, false)<br/> }))</pre> | `[]` | no |
| resource\_group\_name | Resource Group name. | `string` | n/a | yes |
| stack | Project stack name. | `string` | n/a | yes |
| vnet\_cidr | CIDR of the VNet to create for the Private DNS Resolver. One of `vnet_id` or `vnet_cidr` must be specified. | `string` | `""` | no |
| vnet\_custom\_name | Custom VNet name, generated if not set. | `string` | `""` | no |
| vnet\_id | ID of the existing VNet in which the Private DNS Resolver will be created. One of `vnet_id` or `vnet_cidr` must be specified. | `string` | `""` | no |
| virtual\_network\_cidr | CIDR of the Virtual Network to create for the Private DNS Resolver. One of `virtual_network_id` or `virtual_network_cidr` must be specified. | `string` | `""` | no |
| virtual\_network\_custom\_name | Custom Virtual Network name, generated if not set. | `string` | `""` | no |
| virtual\_network\_id | ID of the existing Virtual Network in which the Private DNS Resolver will be created. One of `virtual_network_id` or `virtual_network_cidr` must be specified. | `string` | `""` | no |

## Outputs

Expand All @@ -244,7 +244,7 @@ module "private_dns_resolver" {
| id | Private DNS Resolver ID. |
| inbound\_endpoints | Maps of Private DNS Resolver inbound endpoints. |
| module\_subnets | Subnets module outputs. |
| module\_vnet | Virtual Network module outputs. |
| module\_virtual\_network | Virtual Network module outputs. |
| name | Private DNS Resolver name. |
| outbound\_endpoints | Maps of Private DNS Resolver outbound endpoints. |
| resource | Private DNS Resolver resource object. |
Expand Down
14 changes: 7 additions & 7 deletions examples/main/modules.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ module "private_dns_resolver" {
resource_group_name = module.rg.name

## Bring Your Own VNet
# If set, `vnet_cidr` will not be used
# vnet_id = module.my_vnet.id
# If set, `virtual_network_id` will not be used
# virtual_network_id = module.my_vnet.id

vnet_cidr = local.private_dns_resolver_vnet_cidr
virtual_network_cidr = local.private_dns_resolver_vnet_cidr

inbound_endpoints = [
{
Expand Down Expand Up @@ -93,16 +93,16 @@ module "private_dns_resolver" {
]

dns_forwarding_rulesets = [
# VNets cannot be linked to multiple forwarding ruleset
# Therefore, keep in mind that the first ruleset is the default one because the VNet of the Private DNS Resolver is linked to this ruleset
# Virtual Networks cannot be linked to multiple forwarding ruleset
# Therefore, keep in mind that the first ruleset is the default one because the Virtual Network of the Private DNS Resolver is linked to this ruleset
{
name = "foo"
custom_name = "forwarding-ruleset"

# Ref to the first outbound endpoint
target_outbound_endpoints = ["foo"]

vnets_ids = slice(module.vnets_to_be_linked[*].id, 0, 4)
virtual_networks_ids = slice(module.vnets_to_be_linked[*].id, 0, 4)

rules = [
{
Expand All @@ -128,7 +128,7 @@ module "private_dns_resolver" {
# "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Network/dnsResolvers/dnsResolver1/outboundEndpoints/outboundEndpoint1",
]

vnets_ids = slice(module.vnets_to_be_linked[*].id, 4, 8)
virtual_networks_ids = slice(module.vnets_to_be_linked[*].id, 4, 8)

rules = [
{
Expand Down
8 changes: 4 additions & 4 deletions locals-outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ locals {

dns_forwarding_rulesets_output = {
for ruleset_name in keys(local.dns_forwarding_rulesets) : ruleset_name => {
id = azurerm_private_dns_resolver_dns_forwarding_ruleset.main[ruleset_name].id
name = azurerm_private_dns_resolver_dns_forwarding_ruleset.main[ruleset_name].name
rules_ids = [for rule in local.forwarding_rules : azurerm_private_dns_resolver_forwarding_rule.main[rule.name].id if rule.ruleset_name == ruleset_name]
vnet_links_ids = [for index, link in local.vnet_links_flattened : azurerm_private_dns_resolver_virtual_network_link.main[index].id if link.ruleset_name == ruleset_name]
id = azurerm_private_dns_resolver_dns_forwarding_ruleset.main[ruleset_name].id
name = azurerm_private_dns_resolver_dns_forwarding_ruleset.main[ruleset_name].name
rules_ids = [for rule in local.forwarding_rules : azurerm_private_dns_resolver_forwarding_rule.main[rule.name].id if rule.ruleset_name == ruleset_name]
virtual_network_links_ids = [for index, link in local.virtual_network_links_flattened : azurerm_private_dns_resolver_virtual_network_link.main[index].id if link.ruleset_name == ruleset_name]
}
}
}
18 changes: 9 additions & 9 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ locals {

endpoints = merge(local.inbound_endpoints, local.outbound_endpoints)

vnet_id = one(compact(concat(
[var.vnet_id],
virtual_network_id = one(compact(concat(
[var.virtual_network_id],
module.vnet[*].id,
)))

vnet_name = one(compact(concat(
[element(reverse(split("/", var.vnet_id)), 0)],
virtual_network_name = one(compact(concat(
[element(reverse(split("/", var.virtual_network_id)), 0)],
module.vnet[*].name,
)))

vnet_links_flattened = flatten([
virtual_network_links_flattened = flatten([
for index, ruleset in var.dns_forwarding_rulesets : [
for id in concat(index == 0 ? [local.vnet_id] : [], ruleset.vnets_ids) : {
name = format("%s-link", element(reverse(split("/", id)), 0))
vnet_id = id
ruleset_name = ruleset.name
for id in concat(index == 0 ? [local.virtual_network_id] : [], ruleset.virtual_networks_ids) : {
name = format("%s-link", element(reverse(split("/", id)), 0))
virtual_network_id = id
ruleset_name = ruleset.name
}
]
])
Expand Down
8 changes: 4 additions & 4 deletions m-network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module "vnet" {
source = "claranet/vnet/azurerm"
version = "~> 8.0.0"

count = var.vnet_id == "" ? 1 : 0
count = var.virtual_network_id == "" ? 1 : 0

location = var.location
location_short = var.location_short
Expand All @@ -14,9 +14,9 @@ module "vnet" {

name_prefix = local.name_prefix
name_suffix = local.name_suffix
custom_name = var.vnet_custom_name
custom_name = var.virtual_network_custom_name

cidrs = [var.vnet_cidr]
cidrs = [var.virtual_network_cidr]

default_tags_enabled = var.default_tags_enabled

Expand All @@ -40,7 +40,7 @@ module "subnets" {
name_suffix = each.value.subnet_custom_name != "" ? local.name_suffix != "" ? format("%s-%s", local.name_suffix, each.key) : each.key : ""
custom_name = each.value.subnet_custom_name

virtual_network_name = local.vnet_name
virtual_network_name = local.virtual_network_name
delegations = local.subnets_delegation

private_link_service_enabled = true
Expand Down
6 changes: 3 additions & 3 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ output "resource_virtual_network_link" {
value = azurerm_private_dns_resolver_virtual_network_link.main
}

output "module_vnet" {
output "module_virtual_network" {
description = "Virtual Network module outputs."
value = module.vnet
}
Expand All @@ -50,12 +50,12 @@ output "name" {

output "virtual_network_id" {
description = "Private DNS Resolver Virtual Network ID."
value = local.vnet_id
value = local.virtual_network_id
}

output "virtual_network_name" {
description = "Private DNS Resolver Virtual Network name."
value = local.vnet_name
value = local.virtual_network_name
}

output "inbound_endpoints" {
Expand Down
10 changes: 5 additions & 5 deletions r-private-dns-resolver.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resource "azurerm_private_dns_resolver" "main" {

resource_group_name = var.resource_group_name

virtual_network_id = local.vnet_id
virtual_network_id = local.virtual_network_id

tags = merge(local.default_tags, var.extra_tags)
}
Expand Down Expand Up @@ -99,12 +99,12 @@ moved {
}

resource "azurerm_private_dns_resolver_virtual_network_link" "main" {
count = length(local.vnet_links_flattened)
count = length(local.virtual_network_links_flattened)

name = local.vnet_links_flattened[count.index].name
name = local.virtual_network_links_flattened[count.index].name

dns_forwarding_ruleset_id = azurerm_private_dns_resolver_dns_forwarding_ruleset.main[local.vnet_links_flattened[count.index].ruleset_name].id
virtual_network_id = local.vnet_links_flattened[count.index].vnet_id
dns_forwarding_ruleset_id = azurerm_private_dns_resolver_dns_forwarding_ruleset.main[local.virtual_network_links_flattened[count.index].ruleset_name].id
virtual_network_id = local.virtual_network_links_flattened[count.index].virtual_network_id
}

moved {
Expand Down
4 changes: 2 additions & 2 deletions variables-naming.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ variable "custom_name" {
default = ""
}

variable "vnet_custom_name" {
description = "Custom VNet name, generated if not set."
variable "virtual_network_custom_name" {
description = "Custom Virtual Network name, generated if not set."
type = string
default = ""
}
18 changes: 9 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ variable "resource_group_name" {
type = string
}

variable "vnet_id" {
description = "ID of the existing VNet in which the Private DNS Resolver will be created. One of `vnet_id` or `vnet_cidr` must be specified."
variable "virtual_network_id" {
description = "ID of the existing Virtual Network in which the Private DNS Resolver will be created. One of `virtual_network_id` or `virtual_network_cidr` must be specified."
type = string
default = ""
}

variable "vnet_cidr" {
description = "CIDR of the VNet to create for the Private DNS Resolver. One of `vnet_id` or `vnet_cidr` must be specified."
variable "virtual_network_cidr" {
description = "CIDR of the Virtual Network to create for the Private DNS Resolver. One of `virtual_network_id` or `virtual_network_cidr` must be specified."
type = string
default = ""
}
Expand Down Expand Up @@ -108,12 +108,12 @@ EOD

variable "dns_forwarding_rulesets" {
description = <<EOD
List of DNS forwarding ruleset objects. The first DNS forwarding ruleset in the list is the default one because the VNet of the Private DNS Resolver is linked to it.
List of DNS forwarding ruleset objects. The first DNS forwarding ruleset in the list is the default one because the Virtual Network of the Private DNS Resolver is linked to it.
```
name = Short DNS forwarding ruleset name, used to generate the DNS forwarding ruleset resource name.
custom_name = Custom DNS forwarding ruleset name, overrides the DNS forwarding ruleset default resource name.
target_outbound_endpoints = List of outbound endpoints to link to the DNS forwarding ruleset. Can be the short name of the outbound endpoint or an outbound endpoint ID.
vnets_ids = List of VNets IDs to link to the DNS forwarding ruleset.
virtual_networks_ids = List of Virtual Networks IDs to link to the DNS forwarding ruleset.
rules = List of forwarding rule objects that the DNS forwarding ruleset contains.
name = Short forwarding rule name, used to generate the forwarding rule resource name.
domain_name = Specifies the target domain name of the forwarding rule.
Expand All @@ -126,7 +126,7 @@ EOD
name = string
custom_name = optional(string)
target_outbound_endpoints = optional(list(string), [])
vnets_ids = optional(list(string), [])
virtual_networks_ids = optional(list(string), [])
rules = optional(list(object({
name = string
domain_name = string
Expand All @@ -141,8 +141,8 @@ EOD
error_message = "Forwarding rules are limited to 25 per DNS forwarding ruleset."
}
validation {
condition = alltrue([for ruleset in var.dns_forwarding_rulesets : length(ruleset.vnets_ids) <= 10])
error_message = "VNet links are limited to 10 per DNS forwarding ruleset."
condition = alltrue([for ruleset in var.dns_forwarding_rulesets : length(ruleset.virtual_networks_ids) <= 10])
error_message = "Virtual Network links are limited to 10 per DNS forwarding ruleset."
}
validation {
condition = alltrue([for ruleset in var.dns_forwarding_rulesets : length(ruleset.target_outbound_endpoints) <= 2])
Expand Down

0 comments on commit 5866a8b

Please sign in to comment.