### Module Instantiation Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/main-module.md Example of how to instantiate the route table module with required parameters. ```hcl module "example" { source = "Azure/avm-res-network-routetable/azurerm" location = string name = string resource_group_name = string bgp_route_propagation_enabled = optional(bool) enable_telemetry = optional(bool) lock = optional(object) role_assignments = optional(map(object)) routes = optional(map(object)) routes_legacy_mode = optional(bool) subnet_resource_ids = optional(map(string)) tags = optional(map(string)) } ``` -------------------------------- ### Resource Group Module Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/AGENTS.md Example of using the Azure resource group module from AVM. Ensure to use the latest version. ```hcl module "resource_group" { source = "Azure/avm-res-resources-resourcegroup/azurerm" version = "0.1.0" # use latest enable_telemetry = true location = var.location name = var.resource_group_name } ``` -------------------------------- ### Virtual Network Module Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/AGENTS.md Example of using the Azure virtual network module from AVM. It depends on a resource group and requires specific network configurations. ```hcl module "virtual_network" { source = "Azure/avm-res-network-virtualnetwork/azurerm" version = "0.1.0" # use latest enable_telemetry = true location = module.resource_group.location name = var.vnet_name resource_group_name = module.resource_group.name address_space = ["10.0.0.0/16"] } ``` -------------------------------- ### Route Table Output Value Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md An example of a route table resource ID, showing the expected format for a subscription, resource group, and route table name. ```text /subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/rg-network/providers/Microsoft.Network/routeTables/udr-prod-eastus-001 ``` -------------------------------- ### Example Route Monitoring Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md This snippet shows how to use a null_resource with a local-exec provisioner to log route creation events. It iterates over the routes defined in the module. ```hcl resource "null_resource" "route_monitoring" { for_each = module.route_table.routes provisioner "local-exec" { command = "echo 'Route ${each.value.name} (ID: ${each.value.id}) created'" } } ``` -------------------------------- ### Basic Role Assignment Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/types.md Example of assigning a role to a user or group. Specify the role definition name and the principal's ID. ```hcl role_assignments = { network_team = { role_definition_name = "Network Contributor" principal_id = "00000000-0000-0000-0000-000000000001" description = "Network team management access" } } ``` -------------------------------- ### Legacy Mode Output Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md This JSON structure represents the output for routes when the module is configured in legacy mode. ```json { "default_route": { "id": "/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/rg-network/providers/Microsoft.Network/routeTables/udr-prod-eastus-001/routes/default-route", "name": "default-route", "address_prefix": "0.0.0.0/0", "next_hop_type": "VirtualAppliance", "next_hop_in_ip_address": "10.0.0.1", "resource_group_name": "rg-network", "route_table_name": "udr-prod-eastus-001" } } ``` -------------------------------- ### Full Route Table Module Invocation Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/configuration.md A comprehensive example demonstrating how to invoke the route table module with all required and optional configuration parameters. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" version = "~> 1.0" # Required inputs location = "eastus" name = "udr-prod-eastus-001" resource_group_name = "rg-network-prod" # Optional inputs bgp_route_propagation_enabled = true enable_telemetry = true lock = { kind = "ReadOnly" name = "prevent-modification" } role_assignments = { netops = { role_definition_name = "Network Contributor" principal_id = azuread_group.netops.object_id } } routes = { default = { name = "default-route" address_prefix = "0.0.0.0/0" next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "10.0.0.1" } } routes_legacy_mode = false subnet_resource_ids = { subnet1 = azurerm_subnet.app.id subnet2 = azurerm_subnet.data.id } tags = { Environment = "Production" Owner = "NetworkTeam" } } ``` -------------------------------- ### Modern Mode Output Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md This JSON structure represents the output for routes when the module is configured in modern mode. ```json { "default_route": { "id": "/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/rg-network/providers/Microsoft.Network/routeTables/udr-prod-eastus-001/routes/default-route", "name": "default-route", "resource_id": "/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/rg-network/providers/Microsoft.Network/routeTables/udr-prod-eastus-001/routes/default-route" }, "local_vnet": { "id": "/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/rg-network/providers/Microsoft.Network/routeTables/udr-prod-eastus-001/routes/local-vnet", "name": "local-vnet", "resource_id": "/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/rg-network/providers/Microsoft.Network/routeTables/udr-prod-eastus-001/routes/local-vnet" } } ``` -------------------------------- ### Terraform Storage Account Module Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/AGENTS.md Example of how to use the AVM storage account resource module in Terraform. Ensure telemetry is enabled and configure essential parameters like location, name, and resource group. ```hcl module "storage_account" { source = "Azure/avm-res-storage-storageaccount/azurerm" version = "0.1.0" enable_telemetry = true location = "East US" name = "mystorageaccount" resource_group_name = "my-rg" # Additional configuration... } ``` -------------------------------- ### Route Map Value Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/main-module.md Example structure for a single route within the 'routes' map. ```hcl routes = { example = { name = string address_prefix = string next_hop_type = string next_hop_in_ip_address = optional(string) } } ``` -------------------------------- ### Minimal Route Table Deployment Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/README.md This example demonstrates the minimal configuration required to deploy an Azure Route Table with a single default route to the internet and associate it with an application subnet. It also shows how to output the resource ID of the created route table. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" version = "~> 1.0" location = "eastus" name = "udr-prod-001" resource_group_name = "rg-network" routes = { default = { name = "default-to-internet" address_prefix = "0.0.0.0/0" next_hop_type = "Internet" } } subnet_resource_ids = { app_subnet = azurerm_subnet.app.id } tags = { Environment = "Production" } } output "route_table_id" { value = module.route_table.resource_id } ``` -------------------------------- ### Role Assignment Map Value Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/main-module.md Example structure for a single role assignment within the 'role_assignments' map. ```hcl role_assignments = { example = { role_definition_id_or_name = string principal_id = string description = optional(string) skip_service_principal_aad_check = optional(bool) condition = optional(string) condition_version = optional(string) delegated_managed_identity_resource_id = optional(string) principal_type = optional(string) } } ``` -------------------------------- ### Address Prefix Examples for Route Tables Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/types.md Illustrates various formats for 'address_prefix' in route table configurations, including CIDR notation for subnets and hosts, default routes, and Azure Service Tags. ```hcl address_prefix = "10.0.0.0/24" # Single subnet address_prefix = "10.0.0.0/16" # Larger range address_prefix = "0.0.0.0/0" # Default route (all traffic) address_prefix = "192.168.1.1/32" # Single host address_prefix = "AzureMonitor" # Service Tag address_prefix = "ApiManagement" # Service Tag ``` -------------------------------- ### Get Route Table Resource ID Output Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md This example shows how to access the 'resource_id' output, which provides the fully qualified Azure resource ID of the created Route Table. ```hcl output "route_table_resource_id" { description = "The fully qualified Azure resource ID of the route table." value = module.route_table.resource_id } ``` -------------------------------- ### Basic Usage of the Route Table Route Module Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/modules/route/README.md This example demonstrates the fundamental usage of the route table route module. It requires specifying resource group, route table, and route details, along with the address prefix, next hop type, and optionally the next hop IP address. ```terraform module "avm-res-network-routetable-route" { source = "Azure/avm-res-network-routetable/azurerm//modules/route" resource_group_name = "example-resource-group" route_table_name = "example-route-table" route_name = "example-route" address_prefix = "10.0.0.0/24" next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "10.0.0.5" } ``` -------------------------------- ### Example Resource Group Creation Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This snippet demonstrates how to create an Azure resource group using Terraform. This is useful for resolving 'Resource Group Not Found' errors. ```hcl resource "azurerm_resource_group" "this" { name = "rg-network-prod" location = "eastus" } ``` -------------------------------- ### Route Definition Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/README.md Defines a route for a route table with a specific address prefix and next hop type. ```terraform routes = { route1 = { name = "test-route-vnetlocal" address_prefix = "10.2.0.0/32" next_hop_type = "VnetLocal" } } ``` -------------------------------- ### Lock Object Usage Examples Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/types.md Illustrates how to configure management locks for route tables. Choose 'CanNotDelete' or 'ReadOnly' for the kind, and optionally provide a custom name. ```hcl # CanNotDelete lock with custom name lock = { kind = "CanNotDelete" name = "prevent-accidental-deletion" } # ReadOnly lock with auto-generated name lock = { kind = "ReadOnly" } # No lock (null) lock = null ``` -------------------------------- ### Subnet Association Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/README.md Associates subnets with the route table using their resource IDs. Includes an example using a dynamic subnet ID and a hardcoded resource ID format. ```terraform subnet_resource_ids = { subnet1 = azurerm_subnet.this.id, subnet2 = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{vnetName}/subnets/{subnetName}" } ``` -------------------------------- ### Chain Route Table Outputs to Another Module Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md This example demonstrates how to pass outputs like `resource_id`, `name`, and `routes` from a route table module to another module for further processing or integration. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" # ... configuration ... } module "route_table_monitoring" { source = "..." route_table_id = module.route_table.resource_id route_table_name = module.route_table.name routes = module.route_table.routes # ... other configuration ... } ``` -------------------------------- ### Get Route Table Name Output Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md Demonstrates how to access the 'name' output of the route table module and use it in a local variable and an output value. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" # ... configuration ... } locals { route_table_name = module.route_table.name } output "route_table_name" { value = module.route_table.name } ``` -------------------------------- ### Get Route Table Tags Output Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md Demonstrates how to access the 'tags' output of the route table module, which contains the tags assigned to the resource. ```hcl output "route_table_tags" { description = "The tags assigned to the route table." value = module.route_table.tags } ``` -------------------------------- ### Route Table with Multiple Routes and BGP Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/examples.md Configures a route table with multiple specific routes (default, local vnet, on-premises, blocked) and enables BGP route propagation. This setup is suitable for production environments requiring complex traffic management and hybrid connectivity. Ensure required Terraform and Azurerm provider versions are met. ```hcl terraform { required_version = ">= 1.9" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 4.0" } } } provider "azurerm" { features {} } resource "azurerm_resource_group" "this" { name = "rg-network-app" location = "eastus" } module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" version = "~> 1.0" location = azurerm_resource_group.this.location name = "udr-app-prod" resource_group_name = azurerm_resource_group.this.name # Enable BGP route propagation for hybrid scenarios bgp_route_propagation_enabled = true routes = { default = { name = "default-to-internet" address_prefix = "0.0.0.0/0" next_hop_type = "Internet" } local_vnet = { name = "local-vnet-traffic" address_prefix = "10.0.0.0/8" next_hop_type = "VnetLocal" } on_premises = { name = "to-on-premises" address_prefix = "192.168.0.0/16" next_hop_type = "VirtualNetworkGateway" } blocked = { name = "block-internal-range" address_prefix = "172.16.0.0/12" next_hop_type = "None" } } tags = { Environment = "Production" Application = "WebApp" Owner = "NetworkTeam" } } output "routes_summary" { value = { for key, route in module.route_table.routes : key => { name = route.name address_prefix = try(route.address_prefix, "N/A") # Legacy mode only next_hop_type = try(route.next_hop_type, "N/A") # Legacy mode only resource_id = route.id } } description = "Summary of all routes created" } ``` -------------------------------- ### Using with Azure Service Tags Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/route-module.md Create a route using an Azure Service Tag instead of a CIDR notation for the address prefix. This example routes traffic to Azure Monitor. ```hcl module "service_tag_route" { source = "./modules/route" name = "to-azure-services" address_prefix = "AzureMonitor" # Service Tag next_hop_type = "Internet" parent_id = azurerm_route_table.this.id next_hop_ip_address = null } ``` -------------------------------- ### Create Multiple Routes with for_each Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/route-module.md Use `for_each` to define and create multiple routes within a parent route table module. This example demonstrates defining two distinct routes with their respective properties. ```hcl module "routes" { for_each = { route1 = { name = "local-traffic" address_prefix = "10.0.0.0/8" next_hop_type = "VnetLocal" next_hop_ip = null } route2 = { name = "to-nva" address_prefix = "192.168.0.0/16" next_hop_type = "VirtualAppliance" next_hop_ip = "10.0.0.1" } } source = "./modules/route" name = each.value.name address_prefix = each.value.address_prefix next_hop_type = each.value.next_hop_type parent_id = azurerm_route_table.this.id next_hop_ip_address = each.value.next_hop_ip } ``` -------------------------------- ### Pass Route Table Resource to Another Module Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md Illustrates passing the entire route table resource object to another module, for example, for network monitoring. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" # ... configuration ... } module "network_monitoring" { source = "..." monitored_resources = [ module.route_table.resource ] } ``` -------------------------------- ### NVA Pattern: Virtual Network Setup Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/examples.md Defines the virtual network and subnets required for the NVA pattern, including a DMZ subnet for the NVA and an application subnet for workloads. ```hcl resource "azurerm_virtual_network" "this" { name = "vnet-with-nva" location = azurerm_resource_group.this.location resource_group_name = azurerm_resource_group.this.name address_space = ["10.0.0.0/16"] } ``` ```hcl # DMZ subnet where NVA is deployed resource "azurerm_subnet" "dmz" { name = "subnet-dmz" resource_group_name = azurerm_resource_group.this.name virtual_network_name = azurerm_virtual_network.this.name address_prefixes = ["10.0.0.0/24"] } ``` ```hcl # Application subnet with NVA-based routing resource "azurerm_subnet" "app" { name = "subnet-app" resource_group_name = azurerm_resource_group.this.name virtual_network_name = azurerm_virtual_network.this.name address_prefixes = ["10.0.1.0/24"] } ``` -------------------------------- ### Hub-and-Spoke Network Topology Setup Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/examples.md This Terraform configuration sets up a hub-and-spoke network topology. It defines the necessary providers, resource group, hub virtual network with a DMZ subnet, and spoke virtual networks with their respective subnets. Ensure Terraform version 1.9+ and AzureRM provider version 4.0+ are used. ```hcl terraform { required_version = ">= 1.9" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 4.0" } } } provider "azurerm" { features {} } locals { environment = "prod" location = "eastus" nva_ip = "10.0.0.1" # IP of NVA in hub } resource "azurerm_resource_group" "network" { name = "rg-hub-spoke-${local.environment}" location = local.location } # Hub VNet resource "azurerm_virtual_network" "hub" { name = "vnet-hub-${local.environment}" location = azurerm_resource_group.network.location resource_group_name = azurerm_resource_group.network.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "hub_dmz" { name = "subnet-dmz" resource_group_name = azurerm_resource_group.network.name virtual_network_name = azurerm_virtual_network.hub.name address_prefixes = ["10.0.1.0/24"] } # Spoke VNets resource "azurerm_virtual_network" "spoke" { for_each = toset(["app", "database"]) name = "vnet-spoke-${each.value}-${local.environment}" location = azurerm_resource_group.network.location resource_group_name = azurerm_resource_group.network.name address_space = ["10.${index(toset(["app", "database"]), each.value) + 1}.0.0/16"] } resource "azurerm_subnet" "spoke" { for_each = azurerm_virtual_network.spoke name = "subnet-${each.value.name}" resource_group_name = azurerm_resource_group.network.name virtual_network_name = each.value.name address_prefixes = ["10.${index(toset(["app", "database"]), each.key) + 1}.0.0/24"] } ``` -------------------------------- ### Check Terraform Plan Output Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md Create a Terraform plan file and then inspect its contents to review the changes that will be applied. This helps in understanding the impact of your configuration. ```bash terraform plan -out=tfplan terraform show tfplan ``` -------------------------------- ### Disable Telemetry in Route Table Module Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Example of how to disable telemetry collection by setting 'enable_telemetry' to false when defining the route table module. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" enable_telemetry = false # ... other configuration ... } ``` -------------------------------- ### Show Azure Route Table Details Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md Display detailed information about a specific Azure network route table, including its configuration and associated routes. Requires resource group and route table names. ```bash az network route-table show \ --resource-group {rg-name} \ --name {route-table-name} ``` -------------------------------- ### Output Complete Route Table Resource Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md Demonstrates how to output the entire route table resource object, providing access to all its properties. ```hcl output "route_table_resource" { description = "The complete route table resource" value = module.route_table.resource } ``` -------------------------------- ### Azure CLI: List All Role Definitions Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Lists all available role definitions within Azure, outputting their names in a table format. This is useful for identifying the correct role name to use in assignments. ```bash # List all role definitions az role definition list --query "[].name" --output table ``` -------------------------------- ### Get All Route Names Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md Extracts all route names from the `routes` output by using the `keys()` function. This is useful for iterating or referencing all defined routes. ```hcl # Get all route names locals { route_names = keys(module.route_table.routes) } ``` -------------------------------- ### Show route table details Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Use this Azure CLI command to display the details of a specific route table within a resource group. ```bash # Show route table details az network route-table show \ --resource-group {rg-name} \ --name {route-table-name} ``` -------------------------------- ### Output Route Summary (Legacy Mode) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/outputs.md Creates a summary map of route names, address prefixes, and next hop types for all routes when using legacy mode. This provides a concise overview of route configurations. ```hcl # Output all route names and destination prefixes (legacy mode) output "route_summary" { value = { for key, route in module.route_table.routes : key => { name = route.name address_prefix = route.address_prefix next_hop_type = route.next_hop_type } } } ``` -------------------------------- ### Run AVM Pre-commit and PR Check Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/AGENTS.md Execute local unit tests and pre-commit hooks required for AVM repository compliance. These commands must be run before creating or updating pull requests to ensure PR validation success. ```bash PORCH_NO_TUI=1 ./avm pre-commit git add . && git commit -m "chore: avm pre-commit" PORCH_NO_TUI=1 ./avm pr-check ``` -------------------------------- ### Format Terraform Code Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/AGENTS.md Use 'terraform fmt' to recursively format your Terraform code. ```bash terraform fmt -recursive ``` -------------------------------- ### Create an Azure Route Table Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md This snippet shows how to create a basic Azure route table with specified location, name, resource group, BGP route propagation enabled, and tags. ```hcl resource "azurerm_route_table" "this" { location = "eastus" name = "udr-prod-eastus-001" resource_group_name = "rg-network" bgp_route_propagation_enabled = true tags = { Environment = "Production" } } ``` -------------------------------- ### Get Group Object ID (Azure CLI) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md Retrieve the object ID for a group by providing its name. This is useful for obtaining the correct principal ID for role assignments. ```bash # Get group ID az ad group show --group {group-name} --query objectId ``` -------------------------------- ### Route Table with Multiple Routes Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/types.md Configures a route table with multiple routes, demonstrating various 'next_hop_type' values including 'VnetLocal', 'Internet', 'VirtualNetworkGateway', 'VirtualAppliance', and 'None'. ```hcl routes = { local_vnet = { name = "local-traffic" address_prefix = "10.0.0.0/8" next_hop_type = "VnetLocal" } internet = { name = "internet" address_prefix = "0.0.0.0/0" next_hop_type = "Internet" } on_premises = { name = "to-on-premises" address_prefix = "192.168.0.0/16" next_hop_type = "VirtualNetworkGateway" } nva = { name = "through-nva" address_prefix = "172.16.0.0/16" next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "10.0.0.1" } blocked = { name = "blocked-range" address_prefix = "240.0.0.0/8" next_hop_type = "None" } } ``` -------------------------------- ### List routes in a route table (Azure CLI) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Lists all routes configured within a specified Azure route table. Requires resource group and route table names. ```bash # List routes in a route table az network route-table route list \ --resource-group {rg-name} \ --route-table-name {route-table-name} ``` -------------------------------- ### List Routes in Azure Route Table Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md Fetch a list of all routes configured within a specific Azure network route table. This command is useful for verifying route configurations and troubleshooting routing issues. ```bash az network route-table route list \ --resource-group {rg-name} \ --route-table-name {route-table-name} ``` -------------------------------- ### Update a route (Azure CLI) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Updates an existing route in an Azure route table, for example, to change the next hop type. Requires resource group, route table, and route names. ```bash # Update a route az network route-table route update \ --resource-group {rg-name} \ --route-table-name {route-table-name} \ --name {route-name} \ --next-hop-type Internet ``` -------------------------------- ### Configure Route Table with Legacy Mode Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This HCL snippet shows how to configure the route table module using the legacy mode, which might be necessary for backward compatibility. Routes are defined within the 'routes' argument. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" routes_legacy_mode = true routes = { # Define routes here } } ``` -------------------------------- ### Get Service Principal Object ID (Azure CLI) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md Retrieve the object ID for a service principal by providing its application ID. This is useful for obtaining the correct principal ID for role assignments. ```bash # Get service principal ID az ad sp show --id {app-id} --query objectId ``` -------------------------------- ### Get User Object ID (Azure CLI) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md Retrieve the object ID for a user by providing their User Principal Name (UPN). This is useful for obtaining the correct principal ID for role assignments. ```bash # Get user ID az ad user show --upn {user@domain.com} --query objectId ``` -------------------------------- ### Azure CLI Command to List Resource Groups Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This bash command lists all resource group names in the current Azure subscription, useful for verifying resource group existence. ```bash # List all resource groups in the current subscription az group list --query "[].name" -o table ``` -------------------------------- ### Azure Resources Created Table Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/README.md Lists the Azure resources created by the module, their counts, conditions, and purposes. ```markdown | Resource Type | Count | Condition | Purpose | |---------------|-------|-----------|---------| | Route Table | 1 | Always | Main route table resource | | Routes (via AzAPI) | N | Modern mode | Route definitions using Azure API | | Routes (via AzRM) | N | Legacy mode | Route definitions using native provider | | Subnet Associations | N | When specified | Associates route table with subnets | | Management Lock | 0-1 | When lock is specified | Prevents deletion or modification | | Role Assignments | N | When specified | RBAC access control | | Telemetry Resources | 4 | When enabled | Usage tracking and monitoring | ``` -------------------------------- ### Problematic Configuration: Nonexistent Resource Group Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This configuration attempts to create a resource using a 'resource_group_name' that does not exist in the current Azure subscription. Ensure the resource group exists before applying the configuration. ```hcl resource_group_name = "nonexistent-rg" # This RG doesn't exist ``` -------------------------------- ### Configure Multiple Role Assignments for Route Table Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/configuration.md This snippet demonstrates how to assign multiple Azure RBAC roles to different principals for a route table resource. It includes examples for a team, an audit group, and a service principal, showcasing various configuration options like role name, principal ID, description, and skipping service principal validation. ```hcl role_assignments = { netops_team = { role_definition_name = "Network Contributor" principal_id = azuread_group.netops.object_id description = "Network operations team full access" } audit_team = { role_definition_name = "Reader" principal_id = azuread_group.audit.object_id description = "Audit team read-only access" } service_principal = { role_definition_id_or_name = "Network Contributor" principal_id = azuread_service_principal.automation.object_id skip_service_principal_aad_check = true description = "Automation service principal" } } ``` -------------------------------- ### Define Multiple Routes for a Route Table Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/configuration.md Configure various routes including default, local VNet, internet, on-premises, and blocked traffic. Each route specifies an address prefix and the next hop type. ```hcl routes = { default = { name = "default-to-nva" address_prefix = "0.0.0.0/0" next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "10.0.0.1" } local_vnet = { name = "local-traffic" address_prefix = "10.0.0.0/8" next_hop_type = "VnetLocal" } internet = { name = "internet-via-gateway" address_prefix = "8.8.8.8/32" next_hop_type = "Internet" } on_prem = { name = "to-on-premises" address_prefix = "192.168.0.0/16" next_hop_type = "VirtualNetworkGateway" } blocked = { name = "block-internal" address_prefix = "172.16.0.0/12" next_hop_type = "None" } } ``` -------------------------------- ### List route tables in resource group Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Use this Azure CLI command to list all route tables within a specified resource group. ```bash # List route tables in resource group az network route-table list --resource-group {rg-name} ``` -------------------------------- ### Minimal Route Table Configuration Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/examples.md Creates a basic route table without any predefined routes. This is useful for scenarios where routes will be added later or managed dynamically. Ensure Terraform version 1.9+ and Azurerm provider version 4.0+ are configured. ```hcl terraform { required_version = ">= 1.9" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 4.0" } } } provider "azurerm" { features {} } resource "azurerm_resource_group" "this" { name = "rg-network-minimal" location = "eastus" } module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" version = "~> 1.0" location = azurerm_resource_group.this.location name = "udr-minimal" resource_group_name = azurerm_resource_group.this.name } output "route_table_id" { value = module.route_table.resource_id description = "The ID of the created route table" } ``` -------------------------------- ### Configure Azure Provider for Service Principals Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This configuration snippet ensures the Azure provider is correctly set up, which can be relevant when dealing with service principals and their permissions. ```hcl provider "azurerm" { skip_provider_registration = false } ``` -------------------------------- ### Show specific route (Azure CLI) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Retrieves details for a specific route within an Azure route table. Requires resource group, route table, and route names. ```bash # Show specific route az network route-table route show \ --resource-group {rg-name} \ --route-table-name {route-table-name} \ --name {route-name} ``` -------------------------------- ### Azure CLI Command to List Locations Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This bash command lists all available Azure region names for the current subscription. Use this to find valid values for the 'location' variable. ```bash # Using Azure CLI az account list-locations --query "[].name" -o table ``` -------------------------------- ### Minimal Route Table Deployment Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/main-module.md Deploy a route table with default settings in a specified resource group. This is useful for basic network routing needs. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" version = "~> 1.0" location = "eastus" name = "udr-prod-eastus-001" resource_group_name = "rg-network-prod" } ``` -------------------------------- ### Valid Route: IP Address for Virtual Appliance Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This is a valid configuration where 'next_hop_in_ip_address' is correctly provided for a route with 'next_hop_type' set to 'VirtualAppliance'. ```hcl routes = { route1 = { name = "nva-route" address_prefix = "192.168.0.0/16" next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "10.0.0.1" # Correct } } ``` -------------------------------- ### Configure Route Table with Modern Mode Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This HCL snippet demonstrates how to configure the route table module using the recommended modern mode, where routes are defined within the 'routes' argument. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" routes_legacy_mode = false routes = { # Define routes here } } ``` -------------------------------- ### Secure Route Table with Lock and RBAC Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/examples.md This snippet illustrates creating a production-ready route table with added security layers, including a management lock and role-based access control. ```hcl terraform { required_version = ">= 1.9" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 4.0" } azuread = { source = "hashicorp/azuread" version = "~> 3.0" } } } provider "azurerm" { features {} } provider "azuread" {} resource "azurerm_resource_group" "this" { name = "rg-network-prod" location = "eastus" } ``` -------------------------------- ### Azure CLI: List Locks on a Resource Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Lists all management locks applied to a specific Azure resource. Replace placeholders with your resource group, route table name, and namespace. ```bash # List locks on a resource az lock list \ --resource-group {rg-name} \ --resource-name {route-table-name} \ --resource-type routeTables \ --namespace Microsoft.Network ``` -------------------------------- ### Verify Principal ID Existence (Azure CLI - User/Group) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md Use the 'az ad user show' command to verify if a given principal ID corresponds to an existing user or group in Azure Active Directory. ```bash # For users/groups az ad user show --id {principal-id} ``` -------------------------------- ### Resource Dependencies Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/README.md Defines the dependencies between the main route table resource and its associated components. ```text Route Table (main resource) ├── Routes (depend on route table) ├── Subnet Associations (depend on route table) ├── Management Lock (depends on routes) ├── Role Assignments (independent) └── Telemetry (depends on configuration) ``` -------------------------------- ### Route Table with Single Route to Network Virtual Appliance Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/types.md Defines a single route directing traffic to a Network Virtual Appliance. Ensure the 'next_hop_type' is 'VirtualAppliance' and 'next_hop_in_ip_address' is provided. ```hcl routes = { default = { name = "default-route" address_prefix = "0.0.0.0/0" next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "10.0.0.1" } } ``` -------------------------------- ### Route Table with Routes and Subnet Association Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/main-module.md Deploy a route table with multiple routes and associate it to subnets. This configuration allows for custom routing policies within your virtual network. ```hcl module "route_table" { source = "Azure/avm-res-network-routetable/azurerm" version = "~> 1.0" location = azurerm_resource_group.this.location name = "udr-app-prod-001" resource_group_name = azurerm_resource_group.this.name bgp_route_propagation_enabled = true enable_telemetry = true routes = { default_route = { name = "default-to-nva" address_prefix = "0.0.0.0/0" next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "10.0.0.1" } vnetlocal = { name = "local-vnet" address_prefix = "10.0.0.0/8" next_hop_type = "VnetLocal" } internet = { name = "internet" address_prefix = "8.8.8.8/32" next_hop_type = "Internet" } } subnet_resource_ids = { app_subnet = azurerm_subnet.app.id data_subnet = azurerm_subnet.data.id } tags = { Environment = "Production" Application = "WebApp" CostCenter = "12345" } } ``` -------------------------------- ### Module Structure Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/README.md The directory structure of the terraform-azurerm-avm-res-network-routetable module. ```terraform terraform-azurerm-avm-res-network-routetable/ ├── main.tf # Route table, routes, associations ├── variables.tf # Input variable definitions ├── outputs.tf # Output value definitions ├── locals.tf # Local values ├── terraform.tf # Provider requirements ├── main.telemetry.tf # Telemetry configuration └── modules/ └── route/ # Submodule for individual routes (modern mode) ├── main.tf # azapi_resource for route creation ├── variables.tf # Route parameters ├── outputs.tf # Route outputs └── terraform.tf # Provider version constraints ``` -------------------------------- ### Verify Principal ID Existence (Azure CLI - Service Principal) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md Use the 'az ad sp show' command to verify if a given principal ID corresponds to an existing service principal in Azure Active Directory. ```bash # For service principals az ad sp show --id {principal-id} ``` -------------------------------- ### Create an Azure API Route Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md This snippet shows how to create a route within an Azure route table using the `azapi_resource` resource. It specifies the route name, address prefix, next hop type, and parent route table ID. ```hcl module "route" { source = "./modules/route" name = "default-route" address_prefix = "0.0.0.0/0" next_hop_type = "VirtualAppliance" parent_id = azurerm_route_table.this.id next_hop_ip_address = "10.0.0.1" } ``` -------------------------------- ### Azure CLI: List Role Assignments on Route Table Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Lists all role assignments associated with a specific Azure route table resource. Replace the placeholder with the actual route table resource ID. ```bash # List role assignments on the route table az role assignment list \ --scope {route-table-resource-id} ``` -------------------------------- ### Terraform Configuration for Hybrid Connectivity Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/examples.md This snippet sets up the basic Terraform and AzureRM provider configuration, along with a resource group and virtual network for hybrid connectivity. It includes subnets for applications and the required GatewaySubnet for ExpressRoute or VPN gateways. ```hcl terraform { required_version = ">= 1.9" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 4.0" } } } provider "azurerm" { features {} } resource "azurerm_resource_group" "this" { name = "rg-hybrid-network" location = "eastus" } resource "azurerm_virtual_network" "azure" { name = "vnet-azure-prod" location = azurerm_resource_group.this.location resource_group_name = azurerm_resource_group.this.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "azure_application" { name = "subnet-app" resource_group_name = azurerm_resource_group.this.name virtual_network_name = azurerm_virtual_network.azure.name address_prefixes = ["10.0.1.0/24"] } # Virtual Network Gateway for ExpressRoute/VPN resource "azurerm_subnet" "gateway" { name = "GatewaySubnet" # Required name for gateway subnet resource_group_name = azurerm_resource_group.this.name virtual_network_name = azurerm_virtual_network.azure.name address_prefixes = ["10.0.0.0/24"] } ``` -------------------------------- ### Valid Next Hop Type Configuration Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This snippet shows a valid configuration for 'next_hop_type'. Ensure the value is one of the allowed types: 'VirtualNetworkGateway', 'VnetLocal', 'Internet', 'VirtualAppliance', or 'None'. ```hcl routes = { route1 = { name = "test-route" address_prefix = "10.0.0.0/16" next_hop_type = "VirtualAppliance" } } ``` -------------------------------- ### Route Properties for AzAPI Resource Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/route-module.md This JSON structure outlines the properties required for creating a route using the `azapi_resource` provider. It includes address prefix, next hop type, and next hop IP address. ```json { "properties": { "addressPrefix": "{address_prefix}", "nextHopType": "{next_hop_type}", "nextHopIpAddress": "{next_hop_ip_address}" } } ``` -------------------------------- ### Invalid Route: IP Address for Non-Virtual Appliance Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/errors.md This configuration is invalid because 'next_hop_in_ip_address' is provided for a route with 'next_hop_type' set to 'Internet'. The IP address must be null for non-Virtual Appliance route types. ```hcl routes = { route1 = { name = "internet-route" address_prefix = "0.0.0.0/0" next_hop_type = "Internet" next_hop_in_ip_address = "1.2.3.4" # Invalid! Should be null } } ``` -------------------------------- ### Azure CLI: Create a Management Lock Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Creates a new management lock on an Azure resource. Specify the lock name, type, resource group, resource name, type, and namespace. ```bash # Create a lock az lock create \ --name {lock-name} \ --lock-type CanNotDelete \ --resource-group {rg-name} \ --resource-name {route-table-name} \ --resource-type routeTables \ --namespace Microsoft.Network ``` -------------------------------- ### Show subnet's route table association (Azure CLI) Source: https://github.com/azure/terraform-azurerm-avm-res-network-routetable/blob/main/_autodocs/api-reference/azure-resources.md Retrieves the currently associated route table for a given Azure subnet. This helps in verifying the association. ```bash # Show subnet's route table association az network vnet subnet show \ --resource-group {rg-name} \ --vnet-name {vnet-name} \ --name {subnet-name} \ --query "routeTable" ```