Skip to content

Commit

Permalink
pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jtracey93 committed Jun 25, 2024
1 parent a8b8709 commit 9ebbf35
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 368 deletions.
428 changes: 313 additions & 115 deletions README.md

Large diffs are not rendered by default.

29 changes: 6 additions & 23 deletions examples/default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

This deploys the module in its simplest form.

It will deploy all known Azure Private DNS Zones for Azure Services that support Private Link in a new Resource Group that it will create with the name provided.

```hcl
terraform {
required_version = "~> 1.5"
Expand All @@ -22,46 +24,30 @@ provider "azurerm" {
features {}
}
## Section to provide a random Azure region for the resource group
# This allows us to randomize the region for the resource group.
module "regions" {
source = "Azure/regions/azurerm"
version = "~> 0.3"
}
# This allows us to randomize the region for the resource group.
resource "random_integer" "region_index" {
max = length(module.regions.regions) - 1
min = 0
}
## End of section to provide a random Azure region for the resource group
# This ensures we have unique CAF compliant names for our resources.
module "naming" {
source = "Azure/naming/azurerm"
version = "~> 0.3"
}
# This is required for resource modules
resource "azurerm_resource_group" "this" {
location = module.regions.regions[random_integer.region_index.result].name
name = module.naming.resource_group.name_unique
}
# This is the module call
# Do not specify location here due to the randomization above.
# Leaving location as `null` will cause the module to use the resource group location
# with a data source.
module "test" {
source = "../../"
# source = "Azure/avm-ptn-network-private-link-private-dns-zones/azurerm"
# ...
location = azurerm_resource_group.this.location
name = "TODO" # TODO update with module.naming.<RESOURCE_TYPE>.name_unique
resource_group_name = azurerm_resource_group.this.name
location = module.regions.regions[random_integer.region_index.result].name
resource_group_name = module.naming.resource_group.name_unique
enable_telemetry = var.enable_telemetry
enable_telemetry = var.enable_telemetry # see variables.tf
}
```

Expand All @@ -80,15 +66,12 @@ The following requirements are needed by this module:

The following providers are used by this module:

- <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) (~> 3.74)

- <a name="provider_random"></a> [random](#provider\_random) (~> 3.5)

## Resources

The following resources are used by this module:

- [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource)
- [random_integer.region_index](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) (resource)

<!-- markdownlint-disable MD013 -->
Expand Down
2 changes: 1 addition & 1 deletion examples/default/_header.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This deploys the module in its simplest form.

It will deploy all known Azure Private DNS Zones for Azure Services that support Private Link in a new Resource Group that it will create with the name provided.
It will deploy all known Azure Private DNS Zones for Azure Services that support Private Link in a new Resource Group that it will create with the name provided.
48 changes: 33 additions & 15 deletions examples/with-vnet-link-existing-rg/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<!-- BEGIN_TF_DOCS -->
# Default example
# Link Private DNS Zones to Virtual Networks and Deploy Private DNS Zones to an Existing Resource Group

This deploys the module in its simplest form.
This deploys the in a more advanced but more common configuration.

It will deploy all known Azure Private DNS Zones for Azure Services that support Private Link into an existing Resource Group and will also link each of the Private DNS Zones to the Virtual Networks provided via a Private DNS Zone Virtual Network Link.

```hcl
terraform {
Expand All @@ -23,45 +25,59 @@ provider "azurerm" {
}
## Section to provide a random Azure region for the resource group
# This allows us to randomize the region for the resource group.
module "regions" {
source = "Azure/regions/azurerm"
version = "~> 0.3"
}
# This allows us to randomize the region for the resource group.
resource "random_integer" "region_index" {
max = length(module.regions.regions) - 1
min = 0
}
## End of section to provide a random Azure region for the resource group
# This ensures we have unique CAF compliant names for our resources.
module "naming" {
source = "Azure/naming/azurerm"
version = "~> 0.3"
}
# This is required for resource modules
resource "azurerm_resource_group" "this" {
location = module.regions.regions[random_integer.region_index.result].name
name = module.naming.resource_group.name_unique
}
# This is the module call
# Do not specify location here due to the randomization above.
# Leaving location as `null` will cause the module to use the resource group location
# with a data source.
resource "azurerm_virtual_network" "this_1" {
address_space = ["10.0.1.0/24"]
location = azurerm_resource_group.this.location
name = "vnet1"
resource_group_name = azurerm_resource_group.this.name
}
resource "azurerm_virtual_network" "this_2" {
address_space = ["10.0.2.0/24"]
location = azurerm_resource_group.this.location
name = "vnet2"
resource_group_name = azurerm_resource_group.this.name
}
module "test" {
source = "../../"
# source = "Azure/avm-ptn-network-private-link-private-dns-zones/azurerm"
# ...
location = azurerm_resource_group.this.location
name = "TODO" # TODO update with module.naming.<RESOURCE_TYPE>.name_unique
resource_group_name = azurerm_resource_group.this.name
enable_telemetry = var.enable_telemetry # see variables.tf
resoruce_group_creation_enabled = false
virtual_network_resource_ids_to_link_to = {
"vnet1" = {
vnet_resource_id = azurerm_virtual_network.this_1.id
}
"vnet2" = {
vnet_resource_id = azurerm_virtual_network.this_2.id
}
}
enable_telemetry = var.enable_telemetry
}
```

Expand Down Expand Up @@ -89,6 +105,8 @@ The following providers are used by this module:
The following resources are used by this module:

- [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource)
- [azurerm_virtual_network.this_1](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) (resource)
- [azurerm_virtual_network.this_2](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) (resource)
- [random_integer.region_index](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) (resource)

<!-- markdownlint-disable MD013 -->
Expand Down
2 changes: 1 addition & 1 deletion examples/with-vnet-link-existing-rg/_header.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This deploys the in a more advanced but more common configuration.

It will deploy all known Azure Private DNS Zones for Azure Services that support Private Link into an existing Resource Group and will also link each of the Private DNS Zones to the Virtual Networks provided via a Private DNS Zone Virtual Network Link.
It will deploy all known Azure Private DNS Zones for Azure Services that support Private Link into an existing Resource Group and will also link each of the Private DNS Zones to the Virtual Networks provided via a Private DNS Zone Virtual Network Link.
8 changes: 4 additions & 4 deletions examples/with-vnet-link-existing-rg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ resource "azurerm_resource_group" "this" {
}

resource "azurerm_virtual_network" "this_1" {
name = "vnet1"
address_space = ["10.0.1.0/24"]
location = azurerm_resource_group.this.location
name = "vnet1"
resource_group_name = azurerm_resource_group.this.name
address_space = ["10.0.1.0/24"]
}

resource "azurerm_virtual_network" "this_2" {
name = "vnet2"
address_space = ["10.0.2.0/24"]
location = azurerm_resource_group.this.location
name = "vnet2"
resource_group_name = azurerm_resource_group.this.name
address_space = ["10.0.2.0/24"]
}

module "test" {
Expand Down
143 changes: 68 additions & 75 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,69 +1,4 @@
locals {

role_definition_resource_substring = "/providers/Microsoft.Authorization/roleDefinitions"

location_lowered = lower(var.location)
location_short_name = strcontains(local.location_lowered, " ") ? local.azure_region_short_names_display_name_as_key[local.location_lowered] : local.location_lowered

azure_region_short_names_display_name_as_key = {
"australia southeast" : "australiasoutheast",
"west central us" : "westcentralus",
"chile central" : "chilecentral",
"east us 2 euap" : "eastus2euap",
"japan west" : "japanwest",
"west us 2" : "westus2",
"uae central" : "uaecentral",
"france central" : "francecentral",
"east us 2" : "eastus2",
"malaysia west" : "malaysiawest",
"korea south" : "koreasouth",
"switzerland west" : "switzerlandwest",
"west us" : "westus",
"australia central 2" : "australiacentral2",
"north europe" : "northeurope",
"switzerland north" : "switzerlandnorth",
"uae north" : "uaenorth",
"australia east" : "australiaeast",
"new zealand north" : "newzealandnorth",
"japan east" : "japaneast",
"norway east" : "norwayeast",
"south india" : "southindia",
"korea central" : "koreacentral",
"malaysia south" : "malaysiasouth",
"uk south" : "uksouth",
"qatar central" : "qatarcentral",
"canada east" : "canadaeast",
"north central us" : "northcentralus",
"east asia" : "eastasia",
"uk west" : "ukwest",
"brazil southeast" : "brazilsoutheast",
"canada central" : "canadacentral",
"germany north" : "germanynorth",
"west india" : "westindia",
"italy north" : "italynorth",
"israel central" : "israelcentral",
"brazil south" : "brazilsouth",
"central us euap" : "centraluseuap",
"germany west central" : "germanywestcentral",
"south africa north" : "southafricanorth",
"sweden south" : "swedensouth",
"poland central" : "polandcentral",
"spain central" : "spaincentral",
"south central us" : "southcentralus",
"east us" : "eastus",
"southeast asia" : "southeastasia",
"france south" : "francesouth",
"australia central" : "australiacentral",
"central us" : "centralus",
"central india" : "centralindia",
"norway west" : "norwaywest",
"mexico central" : "mexicocentral",
"west europe" : "westeurope",
"south africa west" : "southafricawest",
"west us 3" : "westus3",
"taiwan north" : "taiwannorth",
"sweden central" : "swedencentral"
}
azure_region_geo_codes_short_name_as_key = {
"uaenorth" : "uan",
"northcentralus" : "ncus",
Expand Down Expand Up @@ -123,15 +58,65 @@ locals {
"westus" : "wus",
"swedensouth" : "sds"
}

private_link_private_dns_zones_replaced_regionName_map = { for k, v in var.private_link_private_dns_zones : k => {
zone_name = replace(v.zone_name, "{regionName}", local.location_short_name)
} }

private_link_private_dns_zones_replaced_regionCode_map = { for k, v in local.private_link_private_dns_zones_replaced_regionName_map : k => {
zone_name = replace(v.zone_name, "{regionCode}", local.azure_region_geo_codes_short_name_as_key[local.location_short_name])
} }

azure_region_short_names_display_name_as_key = {
"australia southeast" : "australiasoutheast",
"west central us" : "westcentralus",
"chile central" : "chilecentral",
"east us 2 euap" : "eastus2euap",
"japan west" : "japanwest",
"west us 2" : "westus2",
"uae central" : "uaecentral",
"france central" : "francecentral",
"east us 2" : "eastus2",
"malaysia west" : "malaysiawest",
"korea south" : "koreasouth",
"switzerland west" : "switzerlandwest",
"west us" : "westus",
"australia central 2" : "australiacentral2",
"north europe" : "northeurope",
"switzerland north" : "switzerlandnorth",
"uae north" : "uaenorth",
"australia east" : "australiaeast",
"new zealand north" : "newzealandnorth",
"japan east" : "japaneast",
"norway east" : "norwayeast",
"south india" : "southindia",
"korea central" : "koreacentral",
"malaysia south" : "malaysiasouth",
"uk south" : "uksouth",
"qatar central" : "qatarcentral",
"canada east" : "canadaeast",
"north central us" : "northcentralus",
"east asia" : "eastasia",
"uk west" : "ukwest",
"brazil southeast" : "brazilsoutheast",
"canada central" : "canadacentral",
"germany north" : "germanynorth",
"west india" : "westindia",
"italy north" : "italynorth",
"israel central" : "israelcentral",
"brazil south" : "brazilsouth",
"central us euap" : "centraluseuap",
"germany west central" : "germanywestcentral",
"south africa north" : "southafricanorth",
"sweden south" : "swedensouth",
"poland central" : "polandcentral",
"spain central" : "spaincentral",
"south central us" : "southcentralus",
"east us" : "eastus",
"southeast asia" : "southeastasia",
"france south" : "francesouth",
"australia central" : "australiacentral",
"central us" : "centralus",
"central india" : "centralindia",
"norway west" : "norwaywest",
"mexico central" : "mexicocentral",
"west europe" : "westeurope",
"south africa west" : "southafricawest",
"west us 3" : "westus3",
"taiwan north" : "taiwannorth",
"sweden central" : "swedencentral"
}
combined_private_link_private_dns_zones_replaced_with_vnets_to_link = length(var.virtual_network_resource_ids_to_link_to) == 0 ? {
for item in flatten([
for zone_key, zone_value in local.private_link_private_dns_zones_replaced_regionCode_map : {
Expand Down Expand Up @@ -161,5 +146,13 @@ locals {
]
) : "${item.zone_key}" => item
}

location_lowered = lower(var.location)
location_short_name = strcontains(local.location_lowered, " ") ? local.azure_region_short_names_display_name_as_key[local.location_lowered] : local.location_lowered
private_link_private_dns_zones_replaced_regionCode_map = { for k, v in local.private_link_private_dns_zones_replaced_regionName_map : k => {
zone_name = replace(v.zone_name, "{regionCode}", local.azure_region_geo_codes_short_name_as_key[local.location_short_name])
} }
private_link_private_dns_zones_replaced_regionName_map = { for k, v in var.private_link_private_dns_zones : k => {
zone_name = replace(v.zone_name, "{regionName}", local.location_short_name)
} }
role_definition_resource_substring = "/providers/Microsoft.Authorization/roleDefinitions"
}
9 changes: 0 additions & 9 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Module owners should include the full resource via a 'resource' output
# https://azure.github.io/Azure-Verified-Modules/specs/terraform/#id-tffr2---category-outputs---additional-terraform-outputs

output "combined_private_link_private_dns_zones_replaced_with_vnets_to_link" {
value = local.combined_private_link_private_dns_zones_replaced_with_vnets_to_link
}

# output "private_link_private_dns_zones_resource_ids" {
# value = {for zone in module.avm_res_network_privatednszone :
# zone.key => zone.value.private_dns_zone_id
# }
# }
Loading

0 comments on commit 9ebbf35

Please sign in to comment.