diff --git a/README.md b/README.md index 0d52c19..0db3a28 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,10 @@ -# terraform-azurerm-avm-template +# terraform-azurerm-avm-ptn-network-private-link-private-dns-zones -This is a template repo for Terraform Azure Verified Modules. +This module deploys all known Azure Private DNS Zones for Azure Services that support Private Link as documented and detailed here in [Azure Private Endpoint private DNS zone values](https://learn.microsoft.com/azure/private-link/private-endpoint-dns). -Things to do: - -1. Set up a GitHub repo environment called `test`. -1. Configure environment protection rule to ensure that approval is required before deploying to this environment. -1. Create a user-assigned managed identity in your test subscription. -1. Create a role assignment for the managed identity on your test subscription, use the minimum required role. -1. Configure federated identity credentials on the user assigned managed identity. Use the GitHub environment. -1. Search and update TODOs within the code and remove the TODO comments once complete. +> [!NOTE] +> This module only supports Azure Public/Commercial today and **NOT** Azure US Government Cloud (a.k.a. Fairfax) or Azure China Cloud (a.k.a. Mooncake). If you would like to see support added for these clouds please raise an issue/feature request on this repo/module. > [!IMPORTANT] > As the overall AVM framework is not GA (generally available) yet - the CI framework and test automation is not fully functional and implemented across all supported languages yet - breaking changes are expected, and additional customer feedback is yet to be gathered and incorporated. Hence, modules **MUST NOT** be published at version `1.0.0` or higher at this time. @@ -42,13 +36,8 @@ The following providers are used by this module: The following resources are used by this module: -- [azurerm_management_lock.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/management_lock) (resource) -- [azurerm_private_endpoint.this_managed_dns_zone_groups](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint) (resource) -- [azurerm_private_endpoint.this_unmanaged_dns_zone_groups](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint) (resource) -- [azurerm_private_endpoint_application_security_group_association.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint_application_security_group_association) (resource) -- [azurerm_resource_group.TODO](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource) +- [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource) - [azurerm_resource_group_template_deployment.telemetry](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group_template_deployment) (resource) -- [azurerm_role_assignment.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) (resource) - [random_id.telem](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) (resource) @@ -58,19 +47,13 @@ The following input variables are required: ### [location](#input\_location) -Description: Azure region where the resource should be deployed. - -Type: `string` - -### [name](#input\_name) - -Description: The name of the this resource. +Description: Azure region where the each of the Private Link Private DNS Zones created and Resource Group, if created, will be deployed. Type: `string` ### [resource\_group\_name](#input\_resource\_group\_name) -Description: The resource group where the resources will be deployed. +Description: The resource group where the resources will be deployed. Either the name of the new resource group to create or the name of an existing resource group. Type: `string` @@ -78,33 +61,9 @@ Type: `string` The following input variables are optional (have default values): -### [customer\_managed\_key](#input\_customer\_managed\_key) - -Description: A map describing customer-managed keys to associate with the resource. This includes the following properties: -- `key_vault_resource_id` - The resource ID of the Key Vault where the key is stored. -- `key_name` - The name of the key. -- `key_version` - (Optional) The version of the key. If not specified, the latest version is used. -- `user_assigned_identity` - (Optional) An object representing a user-assigned identity with the following properties: - - `resource_id` - The resource ID of the user-assigned identity. - -Type: - -```hcl -object({ - key_vault_resource_id = string - key_name = string - key_version = optional(string, null) - user_assigned_identity = optional(object({ - resource_id = string - }), null) - }) -``` - -Default: `null` - ### [diagnostic\_settings](#input\_diagnostic\_settings) -Description: A map of diagnostic settings to create on the Key Vault. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. +Description: A map of diagnostic settings to create on each of the Private Link Private DNS Zones created. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. - `name` - (Optional) The name of the diagnostic setting. One will be generated if not set, however this will not be unique if you want to create multiple diagnostic setting resources. - `log_categories` - (Optional) A set of log categories to send to the log analytics workspace. Defaults to `[]`. @@ -148,7 +107,7 @@ Default: `true` ### [lock](#input\_lock) -Description: Controls the Resource Lock configuration for this resource. The following properties can be specified: +Description: Controls the Resource Lock configuration for each of the Private Link Private DNS Zones created and Resource Group, if created. The following properties can be specified: - `kind` - (Required) The type of lock. Possible values are `\"CanNotDelete\"` and `\"ReadOnly\"`. - `name` - (Optional) The name of the lock. If not specified, a name will be generated based on the `kind` value. Changing this forces the creation of a new resource. @@ -164,91 +123,312 @@ object({ Default: `null` -### [managed\_identities](#input\_managed\_identities) +### [private\_link\_dns\_zones\_role\_assignments](#input\_private\_link\_dns\_zones\_role\_assignments) -Description: Controls the Managed Identity configuration on this resource. The following properties can be specified: +Description: A map of role assignments to create on each of the Private Link Private DNS Zones created. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. -- `system_assigned` - (Optional) Specifies if the System Assigned Managed Identity should be enabled. -- `user_assigned_resource_ids` - (Optional) Specifies a list of User Assigned Managed Identity resource IDs to be assigned to this resource. +- `role_definition_id_or_name` - The ID or name of the role definition to assign to the principal. +- `principal_id` - The ID of the principal to assign the role to. +- `description` - The description of the role assignment. +- `skip_service_principal_aad_check` - If set to true, skips the Azure Active Directory check for the service principal in the tenant. Defaults to false. +- `condition` - The condition which will be used to scope the role assignment. +- `condition_version` - The version of the condition syntax. Valid values are '2.0'. + +> Note: only set `skip_service_principal_aad_check` to true if you are assigning a role to a service principal. Type: ```hcl -object({ - system_assigned = optional(bool, false) - user_assigned_resource_ids = optional(set(string), []) - }) +map(object({ + role_definition_id_or_name = string + principal_id = string + description = optional(string, null) + skip_service_principal_aad_check = optional(bool, false) + condition = optional(string, null) + condition_version = optional(string, null) + delegated_managed_identity_resource_id = optional(string, null) + })) ``` Default: `{}` -### [private\_endpoints](#input\_private\_endpoints) - -Description: A map of private endpoints to create on this resource. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. - -- `name` - (Optional) The name of the private endpoint. One will be generated if not set. -- `role_assignments` - (Optional) A map of role assignments to create on the private endpoint. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. See `var.role_assignments` for more information. -- `lock` - (Optional) The lock level to apply to the private endpoint. Default is `None`. Possible values are `None`, `CanNotDelete`, and `ReadOnly`. -- `tags` - (Optional) A mapping of tags to assign to the private endpoint. -- `subnet_resource_id` - The resource ID of the subnet to deploy the private endpoint in. -- `private_dns_zone_group_name` - (Optional) The name of the private DNS zone group. One will be generated if not set. -- `private_dns_zone_resource_ids` - (Optional) A set of resource IDs of private DNS zones to associate with the private endpoint. If not set, no zone groups will be created and the private endpoint will not be associated with any private DNS zones. DNS records must be managed external to this module. -- `application_security_group_resource_ids` - (Optional) A map of resource IDs of application security groups to associate with the private endpoint. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. -- `private_service_connection_name` - (Optional) The name of the private service connection. One will be generated if not set. -- `network_interface_name` - (Optional) The name of the network interface. One will be generated if not set. -- `location` - (Optional) The Azure location where the resources will be deployed. Defaults to the location of the resource group. -- `resource_group_name` - (Optional) The resource group where the resources will be deployed. Defaults to the resource group of this resource. -- `ip_configurations` - (Optional) A map of IP configurations to create on the private endpoint. If not specified the platform will create one. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. - - `name` - The name of the IP configuration. - - `private_ip_address` - The private IP address of the IP configuration. +### [private\_link\_private\_dns\_zones](#input\_private\_link\_private\_dns\_zones) + +Description: A set of Private Link Private DNS Zones to create. Each element must be a valid DNS zone name. + +**NOTE:** + +- Private Link Private DNS Zones that have `{{regionCode}}` in the name will be replaced with the Geo Code of the Region you specified in the `location` variable, if available, as documented [here](https://learn.microsoft.com/azure/private-link/private-endpoint-dns#:~:text=Note-,In%20the%20above%20text%2C%20%7BregionCode%7D%20refers%20to%20the%20region%20code%20(for%20example%2C%20eus%20for%20East%20US%20and%20ne%20for%20North%20Europe).%20Refer%20to%20the%20following%20lists%20for%20regions%20codes%3A,-All%20public%20clouds). + - e.g. If `UK South` or `uksouth` was specified as the region in the `location` variable, `{{regionCode}}` would be replaced with `uks` in the Private DNS Zone name. +- Private Link Private DNS Zones that have `{{regionName}}` in the name will be replaced with the short name of the Region you specified in the `location` variable, if available, as documented [here](https://learn.microsoft.com/azure/private-link/private-endpoint-dns). + - e.g. If `UK South` or `uksouth` was specified as the region in the `location` variable, `{{regionName}}` would be replaced with `uksouth` in the Private DNS Zone name. + +**IMPORTANT:** + +The folowing Private Link Private DNS Zones have been removed from the default value for this variable as they require additional placeholders to be replaced that will only be known by the caller of the module at runtime and cannot be determined by the module itself. If you have a requirement to create these Private Link Private DNS Zones, you must provide the full list of Private Link Private DNS Zones to create as a set in the `private_link_private_dns_zones` variable, using the default value as a reference. The list of Private Link Private DNS Zones that have been removed are: + +- `{subzone}.privatelink.{regionName}.azmk8s.io` +- `privatelink.{dnsPrefix}.database.windows.net` +- `privatelink.{partitionId}.azurestaticapps.net` + +We have also removed the following Private Link Private DNS Zones from the default value for this variable as they should only be created and used with in specific scenarios: + +- `privatelink.azure.com` Type: ```hcl map(object({ - name = optional(string, null) - role_assignments = optional(map(object({ - role_definition_id_or_name = string - principal_id = string - description = optional(string, null) - skip_service_principal_aad_check = optional(bool, false) - condition = optional(string, null) - condition_version = optional(string, null) - delegated_managed_identity_resource_id = optional(string, null) - })), {}) - lock = optional(object({ - kind = string - name = optional(string, null) - }), null) - tags = optional(map(string), null) - subnet_resource_id = string - private_dns_zone_group_name = optional(string, "default") - private_dns_zone_resource_ids = optional(set(string), []) - application_security_group_associations = optional(map(string), {}) - private_service_connection_name = optional(string, null) - network_interface_name = optional(string, null) - location = optional(string, null) - resource_group_name = optional(string, null) - ip_configurations = optional(map(object({ - name = string - private_ip_address = string - })), {}) + zone_name = optional(string, null) })) ``` -Default: `{}` +Default: + +```json +{ + "azure_acr_data": { + "zone_name": "{regionName}.data.privatelink.azurecr.io" + }, + "azure_acr_registry": { + "zone_name": "privatelink.azurecr.io" + }, + "azure_ai_cog_svcs": { + "zone_name": "privatelink.cognitiveservices.azure.com" + }, + "azure_ai_oai": { + "zone_name": "privatelink.openai.azure.com" + }, + "azure_aks_mgmt": { + "zone_name": "privatelink.{regionName}.azmk8s.io" + }, + "azure_api_management": { + "zone_name": "privatelink.azure-api.net" + }, + "azure_app_configuration": { + "zone_name": "privatelink.azconfig.io" + }, + "azure_app_service": { + "zone_name": "privatelink.azurewebsites.net" + }, + "azure_app_service_scm": { + "zone_name": "scm.privatelink.azurewebsites.net" + }, + "azure_arc_guest_configuration": { + "zone_name": "privatelink.guestconfiguration.azure.com" + }, + "azure_arc_hybrid_compute": { + "zone_name": "privatelink.his.arc.azure.com" + }, + "azure_arc_kubernetes": { + "zone_name": "privatelink.dp.kubernetesconfiguration.azure.com" + }, + "azure_attestation": { + "zone_name": "privatelink.attest.azure.net" + }, + "azure_automation": { + "zone_name": "privatelink.azure-automation.net" + }, + "azure_avd_feed_mgmt": { + "zone_name": "privatelink.wvd.microsoft.com" + }, + "azure_avd_global": { + "zone_name": "privatelink-global.wvd.microsoft.com" + }, + "azure_backup": { + "zone_name": "privatelink.{regionCode}.backup.windowsazure.com" + }, + "azure_batch_account": { + "zone_name": "{regionName}.privatelink.batch.azure.com" + }, + "azure_batch_node_mgmt": { + "zone_name": "{regionName}.service.privatelink.batch.azure.com" + }, + "azure_bot_svc_bot": { + "zone_name": "privatelink.directline.botframework.com" + }, + "azure_bot_svc_token": { + "zone_name": "privatelink.token.botframework.com" + }, + "azure_cosmos_db_analytical": { + "zone_name": "privatelink.analytics.cosmos.azure.com" + }, + "azure_cosmos_db_cassandra": { + "zone_name": "privatelink.cassandra.cosmos.azure.com" + }, + "azure_cosmos_db_gremlin": { + "zone_name": "privatelink.gremlin.cosmos.azure.com" + }, + "azure_cosmos_db_mongo": { + "zone_name": "privatelink.mongo.cosmos.azure.com" + }, + "azure_cosmos_db_postgres": { + "zone_name": "privatelink.postgres.cosmos.azure.com" + }, + "azure_cosmos_db_sql": { + "zone_name": "privatelink.documents.azure.com" + }, + "azure_cosmos_db_table": { + "zone_name": "privatelink.table.cosmos.azure.com" + }, + "azure_data_explorer": { + "zone_name": "privatelink.{regionName}.kusto.windows.net" + }, + "azure_data_factory": { + "zone_name": "privatelink.datafactory.azure.net" + }, + "azure_data_factory_portal": { + "zone_name": "privatelink.adf.azure.com" + }, + "azure_data_lake_gen2": { + "zone_name": "privatelink.dfs.core.windows.net" + }, + "azure_databricks_ui_api": { + "zone_name": "privatelink.azuredatabricks.net" + }, + "azure_digital_twins": { + "zone_name": "privatelink.digitaltwins.azure.net" + }, + "azure_event_grid": { + "zone_name": "privatelink.eventgrid.azure.net" + }, + "azure_file_sync": { + "zone_name": "privatelink.afs.azure.net" + }, + "azure_grafana": { + "zone_name": "privatelink.grafana.azure.com" + }, + "azure_hdinsight": { + "zone_name": "privatelink.azurehdinsight.net" + }, + "azure_healthcare_dicom": { + "zone_name": "privatelink.dicom.azurehealthcareapis.com" + }, + "azure_healthcare_fhir": { + "zone_name": "privatelink.fhir.azurehealthcareapis.com" + }, + "azure_healthcare_workspaces": { + "zone_name": "privatelink.workspace.azurehealthcareapis.com" + }, + "azure_iot_central": { + "zone_name": "privatelink.azureiotcentral.com" + }, + "azure_iot_hub": { + "zone_name": "privatelink.azure-devices.net" + }, + "azure_iot_hub_provisioning": { + "zone_name": "privatelink.azure-devices-provisioning.net" + }, + "azure_iot_hub_update": { + "zone_name": "privatelink.api.adu.microsoft.com" + }, + "azure_key_vault": { + "zone_name": "privatelink.vaultcore.azure.net" + }, + "azure_log_analytics": { + "zone_name": "privatelink.oms.opinsights.azure.com" + }, + "azure_log_analytics_data": { + "zone_name": "privatelink.ods.opinsights.azure.com" + }, + "azure_managed_hsm": { + "zone_name": "privatelink.managedhsm.azure.net" + }, + "azure_maria_db_server": { + "zone_name": "privatelink.mariadb.database.azure.com" + }, + "azure_media_services_delivery": { + "zone_name": "privatelink.media.azure.net" + }, + "azure_migration_service": { + "zone_name": "privatelink.prod.migration.windowsazure.com" + }, + "azure_ml": { + "zone_name": "privatelink.api.azureml.ms" + }, + "azure_ml_notebooks": { + "zone_name": "privatelink.notebooks.azure.net" + }, + "azure_monitor": { + "zone_name": "privatelink.monitor.azure.com" + }, + "azure_monitor_agent": { + "zone_name": "privatelink.agentsvc.azure-automation.net" + }, + "azure_mysql_db_server": { + "zone_name": "privatelink.mysql.database.azure.com" + }, + "azure_postgres_sql_server": { + "zone_name": "privatelink.postgres.database.azure.com" + }, + "azure_power_bi_dedicated": { + "zone_name": "privatelink.pbidedicated.windows.net" + }, + "azure_power_bi_power_query": { + "zone_name": "privatelink.tip1.powerquery.microsoft.com" + }, + "azure_power_bi_tenant_analysis": { + "zone_name": "privatelink.analysis.windows.net" + }, + "azure_purview_account": { + "zone_name": "privatelink.purview.azure.com" + }, + "azure_purview_studio": { + "zone_name": "privatelink.purviewstudio.azure.com" + }, + "azure_redis_cache": { + "zone_name": "privatelink.redis.cache.windows.net" + }, + "azure_redis_enterprise": { + "zone_name": "privatelink.redisenterprise.cache.azure.net" + }, + "azure_search": { + "zone_name": "privatelink.search.windows.net" + }, + "azure_service_hub": { + "zone_name": "privatelink.servicebus.windows.net" + }, + "azure_signalr_service": { + "zone_name": "privatelink.service.signalr.net" + }, + "azure_site_recovery": { + "zone_name": "privatelink.siterecovery.windowsazure.com" + }, + "azure_sql_server": { + "zone_name": "privatelink.database.windows.net" + }, + "azure_static_web_apps": { + "zone_name": "privatelink.azurestaticapps.net" + }, + "azure_storage_blob": { + "zone_name": "privatelink.blob.core.windows.net" + }, + "azure_storage_file": { + "zone_name": "privatelink.file.core.windows.net" + }, + "azure_storage_queue": { + "zone_name": "privatelink.queue.core.windows.net" + }, + "azure_storage_table": { + "zone_name": "privatelink.table.core.windows.net" + }, + "azure_storage_web": { + "zone_name": "privatelink.web.core.windows.net" + } +} +``` -### [private\_endpoints\_manage\_dns\_zone\_group](#input\_private\_endpoints\_manage\_dns\_zone\_group) +### [resoruce\_group\_creation\_enabled](#input\_resoruce\_group\_creation\_enabled) -Description: Whether to manage private DNS zone groups with this module. If set to false, you must manage private DNS zone groups externally, e.g. using Azure Policy. +Description: This variable controls whether or not the resource group should be created. If set to false, the resource group must be created elsewhere and the resource group name must be provided to the module. If set to true, the resource group will be created by the module using the name provided in `resource_group_name`. Type: `bool` Default: `true` -### [role\_assignments](#input\_role\_assignments) +### [resource\_group\_role\_assignments](#input\_resource\_group\_role\_assignments) -Description: A map of role assignments to create on this resource. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. +Description: A map of role assignments to create on the Resource Group, if `resoruce_group_creation_enabled` is set to `true`. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. - `role_definition_id_or_name` - The ID or name of the role definition to assign to the principal. - `principal_id` - The ID of the principal to assign the role to. @@ -283,21 +463,39 @@ Type: `map(string)` Default: `null` +### [virtual\_network\_resource\_ids\_to\_link\_to](#input\_virtual\_network\_resource\_ids\_to\_link\_to) + +Description: A map of objects of Virtual Network Resource IDs to link to the Private Link Private DNS Zones created. The map key is deliberately arbitrary to avoid issues where map keys maybe unknown at plan time. + +- `vnet_resource_id` - (Optional) The resource ID of the Virtual Network to link to the Private Link Private DNS Zones created to. + +Type: + +```hcl +map(object({ + vnet_resource_id = optional(string, null) + })) +``` + +Default: `{}` + ## Outputs The following outputs are exported: -### [private\_endpoints](#output\_private\_endpoints) +### [combined\_private\_link\_private\_dns\_zones\_replaced\_with\_vnets\_to\_link](#output\_combined\_private\_link\_private\_dns\_zones\_replaced\_with\_vnets\_to\_link) -Description: A map of the private endpoints created. +Description: n/a -### [resource](#output\_resource) +## Modules -Description: This is the full output for the resource. +The following Modules are called: -## Modules +### [avm\_res\_network\_privatednszone](#module\_avm\_res\_network\_privatednszone) + +Source: Azure/avm-res-network-privatednszone/azurerm -No modules. +Version: 0.1.1 ## Data Collection diff --git a/examples/default/README.md b/examples/default/README.md index 80cbc74..d5f3adb 100644 --- a/examples/default/README.md +++ b/examples/default/README.md @@ -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" @@ -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..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 } ``` @@ -80,15 +66,12 @@ The following requirements are needed by this module: The following providers are used by this module: -- [azurerm](#provider\_azurerm) (~> 3.74) - - [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) diff --git a/examples/default/_header.md b/examples/default/_header.md index aa2d189..e9e5a39 100644 --- a/examples/default/_header.md +++ b/examples/default/_header.md @@ -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. \ No newline at end of file +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. diff --git a/examples/with-vnet-link-existing-rg/README.md b/examples/with-vnet-link-existing-rg/README.md index 80cbc74..fee9824 100644 --- a/examples/with-vnet-link-existing-rg/README.md +++ b/examples/with-vnet-link-existing-rg/README.md @@ -1,7 +1,9 @@ -# 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 { @@ -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..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 } ``` @@ -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) diff --git a/examples/with-vnet-link-existing-rg/_header.md b/examples/with-vnet-link-existing-rg/_header.md index f2262de..821785f 100644 --- a/examples/with-vnet-link-existing-rg/_header.md +++ b/examples/with-vnet-link-existing-rg/_header.md @@ -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. \ No newline at end of file +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. diff --git a/examples/with-vnet-link-existing-rg/main.tf b/examples/with-vnet-link-existing-rg/main.tf index 1778da6..b37f47d 100644 --- a/examples/with-vnet-link-existing-rg/main.tf +++ b/examples/with-vnet-link-existing-rg/main.tf @@ -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" { diff --git a/locals.tf b/locals.tf index be9b85b..ed0f42a 100644 --- a/locals.tf +++ b/locals.tf @@ -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", @@ -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 : { @@ -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" } diff --git a/outputs.tf b/outputs.tf index 450da15..2847e28 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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 -# } -# } diff --git a/variables.tf b/variables.tf index ae10a5b..cf16a92 100644 --- a/variables.tf +++ b/variables.tf @@ -1,7 +1,6 @@ -variable "resoruce_group_creation_enabled" { - type = bool - default = true - description = "This variable controls whether or not the resource group should be created. If set to false, the resource group must be created elsewhere and the resource group name must be provided to the module. If set to true, the resource group will be created by the module using the name provided in `resource_group_name`." +variable "location" { + type = string + description = "Azure region where the each of the Private Link Private DNS Zones created and Resource Group, if created, will be deployed." nullable = false } @@ -10,6 +9,107 @@ variable "resource_group_name" { description = "The resource group where the resources will be deployed. Either the name of the new resource group to create or the name of an existing resource group." } +variable "diagnostic_settings" { + type = map(object({ + name = optional(string, null) + log_categories = optional(set(string), []) + log_groups = optional(set(string), ["allLogs"]) + metric_categories = optional(set(string), ["AllMetrics"]) + log_analytics_destination_type = optional(string, "Dedicated") + workspace_resource_id = optional(string, null) + storage_account_resource_id = optional(string, null) + event_hub_authorization_rule_resource_id = optional(string, null) + event_hub_name = optional(string, null) + marketplace_partner_resource_id = optional(string, null) + })) + default = {} + description = <. +If it is set to false, then no telemetry will be collected. +DESCRIPTION +} + +variable "lock" { + type = object({ + kind = string + name = optional(string, null) + }) + default = null + description = < Note: only set `skip_service_principal_aad_check` to true if you are assigning a role to a service principal. +DESCRIPTION + nullable = false +} + variable "private_link_private_dns_zones" { type = map(object({ zone_name = optional(string, null) @@ -268,131 +368,12 @@ We have also removed the following Private Link Private DNS Zones from the defau DESCRIPTION nullable = false - } -variable "virtual_network_resource_ids_to_link_to" { - type = map(object({ - vnet_resource_id = optional(string, null) - })) - default = {} - nullable = false - description = <. -If it is set to false, then no telemetry will be collected. -DESCRIPTION -} - -variable "location" { - type = string - nullable = false - description = "Azure region where the each of the Private Link Private DNS Zones created and Resource Group, if created, will be deployed." -} - -variable "lock" { - type = object({ - kind = string - name = optional(string, null) - }) - default = null - description = < Note: only set `skip_service_principal_aad_check` to true if you are assigning a role to a service principal. -DESCRIPTION + description = "This variable controls whether or not the resource group should be created. If set to false, the resource group must be created elsewhere and the resource group name must be provided to the module. If set to true, the resource group will be created by the module using the name provided in `resource_group_name`." nullable = false } @@ -428,3 +409,17 @@ variable "tags" { default = null description = "(Optional) Tags of the resource." } + +variable "virtual_network_resource_ids_to_link_to" { + type = map(object({ + vnet_resource_id = optional(string, null) + })) + default = {} + description = <