Skip to content

Commit

Permalink
Merge branch 'rework/AZ-1088-v8' into 'master'
Browse files Browse the repository at this point in the history
feat(AZ-1088): apply suggestions

Closes AZ-1088

See merge request claranet/projects/cloud/azure/terraform/modules/private-dns-resolver!72
  • Loading branch information
rossifumax committed Nov 25, 2024
2 parents 2d50d53 + 5866a8b commit 7ad4f94
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 110 deletions.
54 changes: 27 additions & 27 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 All @@ -123,23 +123,23 @@ module "private_dns_resolver" {
},
{
name = "bar"
custom_subnet_name = "bar-outbound-endpoint-subnet"
subnet_custom_name = "bar-outbound-endpoint-subnet"
cidr = local.private_dns_resolver_subnets_cidrs[3]
# cidr = local.my_subnets_cidrs[3]
},
]
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
# 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 @@ -157,15 +157,15 @@ module "private_dns_resolver" {
{
name = "bar"
# Ref to all Outbound Endpoints
# Can be an Oubound Endpoint ID, in case you want to use this DNS Forwarding Ruleset with an existing Outbound Endpoint
# Ref to all outbound endpoints
# Can be an outbound endpoint ID, in case you want to use this DNS forwarding ruleset with an existing outbound endpoint
target_outbound_endpoints = [
"foo",
"bar",
# "/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 @@ -220,41 +220,41 @@ 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 |
| custom\_vnet\_name | Custom VNet 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 Oubound 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/>custom_subnet_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/> custom_subnet_name = optional(string)<br/> default_outbound_access_enabled = optional(bool, false)<br/> }))</pre> | `[]` | 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 |
| location | Azure location. | `string` | n/a | yes |
| location\_short | Short string for Azure location. | `string` | n/a | yes |
| name\_prefix | Optional prefix for the generated name. | `string` | `""` | no |
| name\_suffix | Optional suffix for the generated name. | `string` | `""` | no |
| 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/>custom_subnet_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/> custom_subnet_name = optional(string)<br/> default_outbound_access_enabled = optional(bool, false)<br/> }))</pre> | `[]` | no |
| 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\_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

| Name | Description |
|------|-------------|
| dns\_forwarding\_rulesets | Maps of Private DNS Resolver DNS Forwarding Rulesets. |
| dns\_forwarding\_rulesets | Maps of Private DNS Resolver DNS forwarding rulesets. |
| id | Private DNS Resolver ID. |
| inbound\_endpoints | Maps of Private DNS Resolver Inbound Endpoints. |
| 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. |
| outbound\_endpoints | Maps of Private DNS Resolver outbound endpoints. |
| resource | Private DNS Resolver resource object. |
| resource\_dns\_forwarding\_ruleset | Private DNS Resolver DNS Forwarding Ruleset resource object. |
| resource\_forwarding\_rule | Private DNS Resolver Forwarding Rule resource object. |
| resource\_inbound\_endpoint | Private DNS Resolver Inbound Endpoint resource object. |
| resource\_outbound\_endpoint | Private DNS Resolver Outbound Endpoint resource object. |
| resource\_dns\_forwarding\_ruleset | Private DNS Resolver DNS forwarding ruleset resource object. |
| resource\_forwarding\_rule | Private DNS Resolver forwarding rule resource object. |
| resource\_inbound\_endpoint | Private DNS Resolver inbound endpoint resource object. |
| resource\_outbound\_endpoint | Private DNS Resolver outbound endpoint resource object. |
| resource\_virtual\_network\_link | Private DNS Resolver Virtual Network Link resource object. |
| vnet\_id | Private DNS Resolver Virtual Network ID. |
| vnet\_name | Private DNS Resolver Virtual Network name. |
| virtual\_network\_id | Private DNS Resolver Virtual Network ID. |
| virtual\_network\_name | Private DNS Resolver Virtual Network name. |
<!-- END_TF_DOCS -->

## Related documentation
Expand Down
22 changes: 11 additions & 11 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 All @@ -86,23 +86,23 @@ module "private_dns_resolver" {
},
{
name = "bar"
custom_subnet_name = "bar-outbound-endpoint-subnet"
subnet_custom_name = "bar-outbound-endpoint-subnet"
cidr = local.private_dns_resolver_subnets_cidrs[3]
# cidr = local.my_subnets_cidrs[3]
},
]

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
# 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 @@ -120,15 +120,15 @@ module "private_dns_resolver" {
{
name = "bar"

# Ref to all Outbound Endpoints
# Can be an Oubound Endpoint ID, in case you want to use this DNS Forwarding Ruleset with an existing Outbound Endpoint
# Ref to all outbound endpoints
# Can be an outbound endpoint ID, in case you want to use this DNS forwarding ruleset with an existing outbound endpoint
target_outbound_endpoints = [
"foo",
"bar",
# "/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
12 changes: 6 additions & 6 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.custom_vnet_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 @@ -37,10 +37,10 @@ module "subnets" {
resource_group_name = var.resource_group_name

name_prefix = local.name_prefix
name_suffix = each.value.custom_subnet_name != "" ? local.name_suffix != "" ? format("%s-%s", local.name_suffix, each.key) : each.key : ""
custom_name = each.value.custom_subnet_name
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
Loading

0 comments on commit 7ad4f94

Please sign in to comment.