Skip to content

Commit

Permalink
AVM-Review-PR (#6)
Browse files Browse the repository at this point in the history
* initial changes

* dns zone logic working

* update fmt

* fmt

* change to map of objects

* final check on zones and convert to map

* change to set local

* changes to local calcs for zones and vnets

* updates

* updates

* Fix known at apply time issue (#7)

* working with defaults and vnets

* change test to rg create

* update headers and adjust examples on 🚆

* pre-commit

* update gitignore

* grept-apply

* changes

* Refactor Terraform code for Private DNS Zones and Resource Group role assignments

* updates following pre-commit

* fix errors

* update

* update tests

* add overrides and remove diag settings var

* update readme

* updates

---------

Co-authored-by: Jared Holgate <[email protected]>
  • Loading branch information
jtracey93 and jaredfholgate authored Jun 28, 2024
1 parent f3a664f commit fb94a46
Show file tree
Hide file tree
Showing 17 changed files with 1,072 additions and 492 deletions.
11 changes: 11 additions & 0 deletions .tflint.override.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
rule "terraform_naming_convention" {
enabled = false
}

rule "required_output_rmfr7" {
enabled = false
}

rule "required_output_tffr2" {
enabled = false
}
445 changes: 297 additions & 148 deletions README.md

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions _header.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
37 changes: 12 additions & 25 deletions examples/default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

This deploys the module in its simplest form.

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

```hcl
terraform {
required_version = "~> 1.5"
Expand All @@ -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-<res/ptn>-<name>/azurerm"
# ...
location = azurerm_resource_group.this.location
name = "TODO" # TODO update with module.naming.<RESOURCE_TYPE>.name_unique
resource_group_name = azurerm_resource_group.this.name
# 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
}
```

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

The following providers are used by this module:

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

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

## Resources

The following resources are used by this module:

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

<!-- markdownlint-disable MD013 -->
Expand Down
2 changes: 2 additions & 0 deletions examples/default/_header.md
Original file line number Diff line number Diff line change
@@ -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.
32 changes: 10 additions & 22 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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-<res/ptn>-<name>/azurerm"
# ...
location = azurerm_resource_group.this.location
name = "TODO" # TODO update with module.naming.<RESOURCE_TYPE>.name_unique
resource_group_name = azurerm_resource_group.this.name
# 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
}
165 changes: 165 additions & 0 deletions examples/with-vnet-link-existing-rg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<!-- BEGIN_TF_DOCS -->
# 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
}
```

<!-- markdownlint-disable MD033 -->
## Requirements

The following requirements are needed by this module:

- <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) (~> 1.5)

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

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

## Providers

The following providers are used by this module:

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

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

## Resources

The following resources are used by this module:

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

<!-- markdownlint-disable MD013 -->
## Required Inputs

No required inputs.

## Optional Inputs

The following input variables are optional (have default values):

### <a name="input_enable_telemetry"></a> [enable\_telemetry](#input\_enable\_telemetry)

Description: This variable controls whether or not telemetry is enabled for the module.
For more information see <https://aka.ms/avm/telemetryinfo>.
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:

### <a name="module_naming"></a> [naming](#module\_naming)

Source: Azure/naming/azurerm

Version: ~> 0.3

### <a name="module_regions"></a> [regions](#module\_regions)

Source: Azure/regions/azurerm

Version: ~> 0.3

### <a name="module_test"></a> [test](#module\_test)

Source: ../../

Version:

<!-- markdownlint-disable-next-line MD041 -->
## 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 <https://go.microsoft.com/fwlink/?LinkID=824704>. 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.
<!-- END_TF_DOCS -->
4 changes: 4 additions & 0 deletions examples/with-vnet-link-existing-rg/_footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- markdownlint-disable-next-line MD041 -->
## 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 <https://go.microsoft.com/fwlink/?LinkID=824704>. 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.
5 changes: 5 additions & 0 deletions examples/with-vnet-link-existing-rg/_header.md
Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit fb94a46

Please sign in to comment.