diff --git a/.tflint.override.hcl b/.tflint.override.hcl new file mode 100644 index 0000000..1ffe9e8 --- /dev/null +++ b/.tflint.override.hcl @@ -0,0 +1,11 @@ +rule "terraform_naming_convention" { + enabled = false +} + +rule "required_output_rmfr7" { + enabled = false +} + +rule "required_output_tffr2" { + enabled = false +} diff --git a/README.md b/README.md index 0d52c19..bfd8f04 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,17 @@ -# 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: +The module also has logic built in to it to handle the replacements of the following strings in the Private DNS Zone Names to the appropriate Azure Region name, short name or geo-code as required: -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. +- `...{regionName}...` +- `...{regionCode}...` + +> [!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. @@ -43,13 +44,11 @@ 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) +- [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) (data source) ## Required Inputs @@ -58,19 +57,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,64 +71,6 @@ 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. - -- `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 `[]`. -- `log_groups` - (Optional) A set of log groups to send to the log analytics workspace. Defaults to `["allLogs"]`. -- `metric_categories` - (Optional) A set of metric categories to send to the log analytics workspace. Defaults to `["AllMetrics"]`. -- `log_analytics_destination_type` - (Optional) The destination type for the diagnostic setting. Possible values are `Dedicated` and `AzureDiagnostics`. Defaults to `Dedicated`. -- `workspace_resource_id` - (Optional) The resource ID of the log analytics workspace to send logs and metrics to. -- `storage_account_resource_id` - (Optional) The resource ID of the storage account to send logs and metrics to. -- `event_hub_authorization_rule_resource_id` - (Optional) The resource ID of the event hub authorization rule to send logs and metrics to. -- `event_hub_name` - (Optional) The name of the event hub. If none is specified, the default event hub will be selected. -- `marketplace_partner_resource_id` - (Optional) The full ARM resource ID of the Marketplace resource to which you would like to send Diagnostic LogsLogs. - -Type: - -```hcl -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: `{}` - ### [enable\_telemetry](#input\_enable\_telemetry) Description: This variable controls whether or not telemetry is enabled for the module. @@ -148,7 +83,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 the Resource Group that hosts the Private DNS Zones. 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 +99,283 @@ object({ Default: `null` -### [managed\_identities](#input\_managed\_identities) +### [private\_link\_private\_dns\_zones](#input\_private\_link\_private\_dns\_zones) -Description: Controls the Managed Identity configuration on this resource. The following properties can be specified: +Description: A set of Private Link Private DNS Zones to create. Each element must be a valid DNS zone name. -- `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. +**NOTE:** -Type: +- 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. -```hcl -object({ - system_assigned = optional(bool, false) - user_assigned_resource_ids = optional(set(string), []) - }) -``` +**IMPORTANT:** -Default: `{}` +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: -### [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. +- `{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. 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 +410,43 @@ 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: The final map of private link private DNS zones to link to virtual networks including the region name replacements as required. -### [resource](#output\_resource) +### [resource\_group\_resource\_id](#output\_resource\_group\_resource\_id) -Description: This is the full output for the resource. +Description: The resource ID of the resource group that the Private DNS Zones are deployed into. ## Modules -No modules. +The following Modules are called: + +### [avm\_res\_network\_privatednszone](#module\_avm\_res\_network\_privatednszone) + +Source: Azure/avm-res-network-privatednszone/azurerm + +Version: 0.1.1 ## Data Collection diff --git a/_header.md b/_header.md index 518d2f6..b4ac775 100644 --- a/_header.md +++ b/_header.md @@ -1,15 +1,17 @@ -# 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: +The module also has logic built in to it to handle the replacements of the following strings in the Private DNS Zone Names to the appropriate Azure Region name, short name or geo-code as required: -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. +- `...{regionName}...` +- `...{regionCode}...` + + +> [!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. diff --git a/examples/default/README.md b/examples/default/README.md index 1abcc3c..dff10ff 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" @@ -19,49 +21,37 @@ terraform { } provider "azurerm" { - features {} + features { + resource_group { + prevent_deletion_if_contains_resources = false + } + } } - -## 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--/azurerm" - # ... - location = azurerm_resource_group.this.location - name = "TODO" # TODO update with module.naming..name_unique - resource_group_name = azurerm_resource_group.this.name + # source = "Azure/avm-ptn-network-private-link-private-dns-zones/azurerm" + 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 +70,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 9eb0b85..e9e5a39 100644 --- a/examples/default/_header.md +++ b/examples/default/_header.md @@ -1,3 +1,5 @@ # Default example 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. diff --git a/examples/default/main.tf b/examples/default/main.tf index 38cdd38..5bd4223 100644 --- a/examples/default/main.tf +++ b/examples/default/main.tf @@ -13,47 +13,35 @@ terraform { } provider "azurerm" { - features {} + features { + resource_group { + prevent_deletion_if_contains_resources = false + } + } } - -## 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--/azurerm" - # ... - location = azurerm_resource_group.this.location - name = "TODO" # TODO update with module.naming..name_unique - resource_group_name = azurerm_resource_group.this.name + # source = "Azure/avm-ptn-network-private-link-private-dns-zones/azurerm" + 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 } diff --git a/examples/with-vnet-link-existing-rg/README.md b/examples/with-vnet-link-existing-rg/README.md new file mode 100644 index 0000000..fa997b1 --- /dev/null +++ b/examples/with-vnet-link-existing-rg/README.md @@ -0,0 +1,165 @@ + +# Link Private DNS Zones to Virtual Networks and Deploy Private DNS Zones to an Existing Resource Group + +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 { + required_version = "~> 1.5" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.74" + } + random = { + source = "hashicorp/random" + version = "~> 3.5" + } + } +} + +provider "azurerm" { + features { + resource_group { + prevent_deletion_if_contains_resources = false + } + } +} + + +module "regions" { + source = "Azure/regions/azurerm" + version = "~> 0.3" +} + +resource "random_integer" "region_index" { + max = length(module.regions.regions) - 1 + min = 0 +} + +module "naming" { + source = "Azure/naming/azurerm" + version = "~> 0.3" +} + +resource "azurerm_resource_group" "this" { + location = module.regions.regions[random_integer.region_index.result].name + name = module.naming.resource_group.name_unique +} + +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 + resource_group_name = azurerm_resource_group.this.name + + 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 +} +``` + + +## Requirements + +The following requirements are needed by this module: + +- [terraform](#requirement\_terraform) (~> 1.5) + +- [azurerm](#requirement\_azurerm) (~> 3.74) + +- [random](#requirement\_random) (~> 3.5) + +## Providers + +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) +- [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) + + +## Required Inputs + +No required inputs. + +## Optional Inputs + +The following input variables are optional (have default values): + +### [enable\_telemetry](#input\_enable\_telemetry) + +Description: This variable controls whether or not telemetry is enabled for the module. +For more information see . +If it is set to false, then no telemetry will be collected. + +Type: `bool` + +Default: `true` + +## Outputs + +No outputs. + +## Modules + +The following Modules are called: + +### [naming](#module\_naming) + +Source: Azure/naming/azurerm + +Version: ~> 0.3 + +### [regions](#module\_regions) + +Source: Azure/regions/azurerm + +Version: ~> 0.3 + +### [test](#module\_test) + +Source: ../../ + +Version: + + +## Data Collection + +The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft’s privacy statement. Our privacy statement is located at . You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices. + \ No newline at end of file diff --git a/examples/with-vnet-link-existing-rg/_footer.md b/examples/with-vnet-link-existing-rg/_footer.md new file mode 100644 index 0000000..bc56bcb --- /dev/null +++ b/examples/with-vnet-link-existing-rg/_footer.md @@ -0,0 +1,4 @@ + +## Data Collection + +The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft’s privacy statement. Our privacy statement is located at . You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices. diff --git a/examples/with-vnet-link-existing-rg/_header.md b/examples/with-vnet-link-existing-rg/_header.md new file mode 100644 index 0000000..821785f --- /dev/null +++ b/examples/with-vnet-link-existing-rg/_header.md @@ -0,0 +1,5 @@ +# Link Private DNS Zones to Virtual Networks and Deploy Private DNS Zones to an Existing Resource Group + +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. diff --git a/examples/with-vnet-link-existing-rg/main.tf b/examples/with-vnet-link-existing-rg/main.tf new file mode 100644 index 0000000..9c1c332 --- /dev/null +++ b/examples/with-vnet-link-existing-rg/main.tf @@ -0,0 +1,77 @@ +terraform { + required_version = "~> 1.5" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.74" + } + random = { + source = "hashicorp/random" + version = "~> 3.5" + } + } +} + +provider "azurerm" { + features { + resource_group { + prevent_deletion_if_contains_resources = false + } + } +} + + +module "regions" { + source = "Azure/regions/azurerm" + version = "~> 0.3" +} + +resource "random_integer" "region_index" { + max = length(module.regions.regions) - 1 + min = 0 +} + +module "naming" { + source = "Azure/naming/azurerm" + version = "~> 0.3" +} + +resource "azurerm_resource_group" "this" { + location = module.regions.regions[random_integer.region_index.result].name + name = module.naming.resource_group.name_unique +} + +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 + resource_group_name = azurerm_resource_group.this.name + + 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 +} diff --git a/examples/with-vnet-link-existing-rg/variables.tf b/examples/with-vnet-link-existing-rg/variables.tf new file mode 100644 index 0000000..e52bbd6 --- /dev/null +++ b/examples/with-vnet-link-existing-rg/variables.tf @@ -0,0 +1,9 @@ +variable "enable_telemetry" { + type = bool + default = true + description = <. +If it is set to false, then no telemetry will be collected. +DESCRIPTION +} diff --git a/locals.telemetry.tf b/locals.telemetry.tf index ff0467b..1b36415 100644 --- a/locals.telemetry.tf +++ b/locals.telemetry.tf @@ -1,8 +1,6 @@ locals { - # TODO: change this to the name of the module. See https://azure.github.io/Azure-Verified-Modules/specs/shared/#id-sfr3---category-telemetry---deploymentusage-telemetry - module_name = "CHANGEME" - # TODO: Change this. Should be either `res` or `ptn` - module_type = "res" + module_name = "network-privatelinkprivatednszones" + module_type = "ptn" # This constructs the ARM deployment name that is used for the telemetry. # We shouldn't ever hit the 64 character limit but use substr just in case. telem_arm_deployment_name = substr( diff --git a/locals.tf b/locals.tf index 04b8074..4d16454 100644 --- a/locals.tf +++ b/locals.tf @@ -1,38 +1,158 @@ -# TODO: insert locals here. locals { - - managed_identities = { - system_assigned_user_assigned = (var.managed_identities.system_assigned || length(var.managed_identities.user_assigned_resource_ids) > 0) ? { - this = { - type = var.managed_identities.system_assigned && length(var.managed_identities.user_assigned_resource_ids) > 0 ? "SystemAssigned, UserAssigned" : length(var.managed_identities.user_assigned_resource_ids) > 0 ? "UserAssigned" : "SystemAssigned" - user_assigned_resource_ids = var.managed_identities.user_assigned_resource_ids - } - } : {} - system_assigned = var.managed_identities.system_assigned ? { - this = { - type = "SystemAssigned" - } - } : {} - user_assigned = length(var.managed_identities.user_assigned_resource_ids) > 0 ? { - this = { - type = "UserAssigned" - user_assigned_resource_ids = var.managed_identities.user_assigned_resource_ids - } - } : {} + azure_region_geo_codes_short_name_as_key = { + "uaenorth" : "uan", + "northcentralus" : "ncus", + "malaysiawest" : "myw", + "eastus" : "eus", + "uksouth" : "uks", + "westcentralus" : "wcus", + "israelcentral" : "ilc", + "southeastasia" : "sea", + "malaysiasouth" : "mys", + "koreacentral" : "krc", + "northeurope" : "ne", + "australiaeast" : "ae", + "southafricanorth" : "san", + "norwaywest" : "nww", + "norwayeast" : "nwe", + "westus3" : "wus3", + "eastus2euap" : "ecy", + "centralus" : "cus", + "mexicocentral" : "mxc", + "canadacentral" : "cnc", + "japaneast" : "jpe", + "swedencentral" : "sdc", + "taiwannorth" : "twn", + "germanynorth" : "gn", + "centralindia" : "inc", + "westindia" : "inw", + "newzealandnorth" : "nzn", + "australiacentral" : "acl", + "ukwest" : "ukw", + "germanywestcentral" : "gwc", + "brazilsouth" : "brs", + "francecentral" : "frc", + "brazilsoutheast" : "bse", + "westus2" : "wus2", + "eastus2" : "eus2", + "centraluseuap" : "ccy", + "australiacentral2" : "acl2", + "francesouth" : "frs", + "southafricawest" : "saw", + "koreasouth" : "krs", + "southindia" : "ins", + "canadaeast" : "cne", + "qatarcentral" : "qac", + "spaincentral" : "spc", + "westeurope" : "we", + "japanwest" : "jpw", + "southcentralus" : "scus", + "polandcentral" : "plc", + "switzerlandwest" : "szw", + "australiasoutheast" : "ase", + "switzerlandnorth" : "szn", + "italynorth" : "itn", + "uaecentral" : "uac", + "eastasia" : "ea", + "chilecentral" : "clc", + "westus" : "wus", + "swedensouth" : "sds" } - - # Private endpoint application security group associations. - # We merge the nested maps from private endpoints and application security group associations into a single map. - private_endpoint_application_security_group_associations = { for assoc in flatten([ - for pe_k, pe_v in var.private_endpoints : [ - for asg_k, asg_v in pe_v.application_security_group_associations : { - asg_key = asg_k - pe_key = pe_k - asg_resource_id = asg_v + 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 : { + zone_key = zone_key + zone_value = zone_value + vnets = null + has_vnet = false } - ] - ]) : "${assoc.pe_key}-${assoc.asg_key}" => assoc } - + ] + ) : item.zone_key => item + } : { + for item in flatten([ + for zone_key, zone_value in local.private_link_private_dns_zones_replaced_regionCode_map : [ + { + zone_key = zone_key + zone_value = zone_value + vnets = [ + for vnet_key, vnet_value in var.virtual_network_resource_ids_to_link_to : { + vnet_key = vnet_key + vnet_value = vnet_value + has_vnet = true + } + ] + has_vnet = true + } + ] + ] + ) : 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/main.privateendpoint.tf b/main.privateendpoint.tf deleted file mode 100644 index 53e8b71..0000000 --- a/main.privateendpoint.tf +++ /dev/null @@ -1,78 +0,0 @@ -# TODO remove this code & var.private_endpoints if private link is not support. Note it must be included in this module if it is supported. -resource "azurerm_private_endpoint" "this_managed_dns_zone_groups" { - for_each = var.private_endpoints - - location = each.value.location != null ? each.value.location : var.location - name = each.value.name != null ? each.value.name : "pe-${var.name}" - resource_group_name = each.value.resource_group_name != null ? each.value.resource_group_name : var.resource_group_name - subnet_id = each.value.subnet_resource_id - custom_network_interface_name = each.value.network_interface_name - tags = each.value.tags - - private_service_connection { - is_manual_connection = false - name = each.value.private_service_connection_name != null ? each.value.private_service_connection_name : "pse-${var.name}" - private_connection_resource_id = azurerm_resource_group.TODO.id # TODO: Replace this dummy resource azurerm_resource_group.TODO with your module resource - subresource_names = ["TODO subresource name, see https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-overview#private-link-resource"] - } - dynamic "ip_configuration" { - for_each = each.value.ip_configurations - - content { - name = ip_configuration.value.name - private_ip_address = ip_configuration.value.private_ip_address - member_name = "TODO subresource name" - subresource_name = "TODO subresource name" - } - } - dynamic "private_dns_zone_group" { - for_each = length(each.value.private_dns_zone_resource_ids) > 0 ? ["this"] : [] - - content { - name = each.value.private_dns_zone_group_name - private_dns_zone_ids = each.value.private_dns_zone_resource_ids - } - } -} - -# The PE resource when we are managing **not** the private_dns_zone_group block -# An example use case is customers using Azure Policy to create private DNS zones -# e.g. -resource "azurerm_private_endpoint" "this_unmanaged_dns_zone_groups" { - for_each = { for k, v in var.private_endpoints : k => v if !var.private_endpoints_manage_dns_zone_group } - - location = each.value.location != null ? each.value.location : var.location - name = each.value.name != null ? each.value.name : "pe-${var.name}" - resource_group_name = each.value.resource_group_name != null ? each.value.resource_group_name : var.resource_group_name - subnet_id = each.value.subnet_resource_id - custom_network_interface_name = each.value.network_interface_name - tags = each.value.tags - - private_service_connection { - is_manual_connection = false - name = each.value.private_service_connection_name != null ? each.value.private_service_connection_name : "pse-${var.name}" - private_connection_resource_id = azurerm_resource_group.TODO.id # TODO: Replace this dummy resource azurerm_resource_group.TODO with your module resource - subresource_names = ["TODO subresource name, see https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-overview#private-link-resource"] - } - dynamic "ip_configuration" { - for_each = each.value.ip_configurations - - content { - name = ip_configuration.value.name - private_ip_address = ip_configuration.value.private_ip_address - member_name = "TODO subresource name" - subresource_name = "TODO subresource name" - } - } - - lifecycle { - ignore_changes = [private_dns_zone_group] - } -} - -resource "azurerm_private_endpoint_application_security_group_association" "this" { - for_each = local.private_endpoint_application_security_group_associations - - application_security_group_id = each.value.asg_resource_id - private_endpoint_id = var.private_endpoints_manage_dns_zone_group ? azurerm_private_endpoint.this_managed_dns_zone_groups[each.value.pe_key].id : azurerm_private_endpoint.this_unmanaged_dns_zone_groups[each.value.pe_key].id -} diff --git a/main.tf b/main.tf index 1e1dbb3..a1128a8 100644 --- a/main.tf +++ b/main.tf @@ -1,25 +1,51 @@ -# TODO: Replace this dummy resource azurerm_resource_group.TODO with your module resource -resource "azurerm_resource_group" "TODO" { +resource "azurerm_resource_group" "this" { + count = var.resoruce_group_creation_enabled ? 1 : 0 + location = var.location - name = var.name # calling code must supply the name + name = var.resource_group_name tags = var.tags } +data "azurerm_resource_group" "this" { + count = var.resoruce_group_creation_enabled ? 0 : 1 + + name = var.resource_group_name +} + +module "avm_res_network_privatednszone" { + for_each = local.combined_private_link_private_dns_zones_replaced_with_vnets_to_link + + source = "Azure/avm-res-network-privatednszone/azurerm" + version = "0.1.1" + + resource_group_name = var.resoruce_group_creation_enabled ? azurerm_resource_group.this[0].name : var.resource_group_name + domain_name = each.value.zone_value.zone_name + + virtual_network_links = each.value.has_vnet ? { for vnet in each.value.vnets : vnet.vnet_key => { + vnetlinkname = "vnet_link-${each.value.zone_key}-${vnet.vnet_key}" + vnetid = vnet.vnet_value.vnet_resource_id + autoregistration = false + } + } : {} + + enable_telemetry = var.enable_telemetry +} + # required AVM resources interfaces resource "azurerm_management_lock" "this" { count = var.lock != null ? 1 : 0 lock_level = var.lock.kind name = coalesce(var.lock.name, "lock-${var.lock.kind}") - scope = azurerm_MY_RESOURCE.this.id + scope = var.resoruce_group_creation_enabled ? azurerm_resource_group.this[0].id : data.azurerm_resource_group.this[0].id notes = var.lock.kind == "CanNotDelete" ? "Cannot delete the resource or its child resources." : "Cannot delete or modify the resource or its child resources." } resource "azurerm_role_assignment" "this" { - for_each = var.role_assignments + for_each = var.resource_group_role_assignments principal_id = each.value.principal_id - scope = azurerm_resource_group.TODO.id # TODO: Replace this dummy resource azurerm_resource_group.TODO with your module resource + scope = var.resoruce_group_creation_enabled ? azurerm_resource_group.this[0].id : data.azurerm_resource_group.this[0].id condition = each.value.condition condition_version = each.value.condition_version delegated_managed_identity_resource_id = each.value.delegated_managed_identity_resource_id diff --git a/outputs.tf b/outputs.tf index 5e93e10..c0676a6 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,13 +1,9 @@ -output "private_endpoints" { - description = <