### Example Resource Lock Configuration Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/types.md An example of how to configure a resource lock. This specific example sets a 'CanNotDelete' lock with a custom name, intended to prevent accidental deletion of a public IP address resource. ```hcl lock = { kind = "CanNotDelete" name = "pip-production-lock" } ``` -------------------------------- ### Multi-Instance Diagnostic Setting Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/resources.md Demonstrates creating multiple diagnostic settings for different destinations (Log Analytics and Storage Account) using a map variable. ```hcl diagnostic_settings = { to_law = { name = "pip-to-law" workspace_resource_id = azurerm_log_analytics_workspace.example.id log_analytics_destination_type = "Dedicated" log_groups = ["allLogs"] metric_categories = ["AllMetrics"] } to_storage = { name = "pip-to-storage" storage_account_resource_id = azurerm_storage_account.example.id log_categories = ["PublicIPAddressEvents"] } } # Creates: # azurerm_monitor_diagnostic_setting.this["to_law"] # azurerm_monitor_diagnostic_setting.this["to_storage"] ``` -------------------------------- ### Example of domain_name_label Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/validation-and-constraints.md Demonstrates setting a domain name label for a public IP address, which results in a fully qualified domain name. ```hcl domain_name_label = "my-app-service" # Results in: my-app-service.eastus.cloudapp.azure.com ``` -------------------------------- ### Configure Diagnostic Settings for Public IP Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/module-reference.md Example of setting up diagnostic logging and metrics for a public IP address, sending data to Log Analytics and a Storage Account. ```hcl module "public_ip" { # ... other variables # diagnostic_settings = { send_to_log_analytics = { name = "diag-to-la" log_groups = ["allLogs"] metric_categories = ["AllMetrics"] workspace_resource_id = azurerm_log_analytics_workspace.example.id log_analytics_destination_type = "Dedicated" } send_to_storage = { name = "diag-to-storage" log_categories = ["PublicIPAddressEvents"] metric_categories = ["AllMetrics"] storage_account_resource_id = azurerm_storage_account.example.id } } } ``` -------------------------------- ### Minimal Static Public IP Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/INDEX.md A basic example demonstrating the creation of a static public IP address. This is useful for simple deployments requiring a predictable IP. ```terraform module "public_ip_address" { source = "git::https://github.com/Azure/avm-res-network-publicipaddress.git" # Minimal configuration name = "minimal-static-pip" resource_group_name = "rg-minimal-static-pip" location = "eastus" allocation_method = "Static" sku = "Standard" sku_tier = "Regional" tags = { environment = "minimal" } } ``` -------------------------------- ### Complete Production Configuration (Full-Featured) Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/INDEX.md A comprehensive example showcasing a fully-featured public IP address configuration for production environments. It includes static allocation, DNS, diagnostics, and RBAC. ```terraform module "public_ip_address" { source = "git::https://github.com/Azure/avm-res-network-publicipaddress.git" # Complete Production Configuration name = "pip-prod-full" resource_group_name = "rg-pip-prod-full" location = "eastus" allocation_method = "Static" sku = "Standard" sku_tier = "Regional" domain_name_label = "pip-prod-label" idle_timeout_in_minutes = 4 diagnostic_settings = [ { name = "diag-settings-prod" log_analytics_workspace_id = "" metric_categories = ["AllMetrics"] } ] role_assignments = [ { principal_id = "" role_definition_id = "" } ] tags = { environment = "production" managedBy = "terraform" } } ``` -------------------------------- ### Dynamic IP for Cost Optimization in Development Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/examples.md This example shows how to configure a public IP address with dynamic allocation and a Basic SKU for cost savings in development or testing environments. It includes a shorter idle timeout. ```hcl resource "azurerm_resource_group" "example" { name = "rg-dev-network" location = "South Central US" } module "dev_public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-dev-vm" resource_group_name = azurerm_resource_group.example.name # Dynamic allocation for dev/test environments allocation_method = "Dynamic" sku = "Basic" # Basic SKU typically used with Dynamic sku_tier = "Regional" # Shorter timeout for dev environments idle_timeout_in_minutes = 4 tags = { Environment = "Development" CostOptimized = "true" } } ``` -------------------------------- ### Example Management Lock Configuration Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/resources.md This configuration demonstrates how to set up a management lock. It specifies the lock kind, which then influences the auto-generated name and the lock level applied to the resource. ```hcl # This lock configuration lock = { kind = "CanNotDelete" } # Creates a management lock with: # - name: "lock-CanNotDelete" # - lock_level: "CanNotDelete" # - scope: ``` -------------------------------- ### Multi-Instance Role Assignment Creation Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/resources.md This example shows how to define multiple role assignments using a map. Each key-value pair in the `role_assignments` map results in a separate `azurerm_role_assignment` resource. ```hcl role_assignments = { admin = { principal_id = "00000000-0000-0000-0000-000000000000" role_definition_id_or_name = "Contributor" } reader = { principal_id = "11111111-1111-1111-1111-111111111111" role_definition_id_or_name = "Reader" } } # Creates: # azurerm_role_assignment.this["admin"] # azurerm_role_assignment.this["reader"] ``` -------------------------------- ### Role Assignments Map Usage Example Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/types.md Demonstrates how to configure multiple role assignments using a map, including different role definition formats, descriptions, principal types, and conditional access. ```hcl role_assignments = { network_admin = { principal_id = "00000000-0000-0000-0000-000000000000" role_definition_id_or_name = "Network Contributor" description = "Network team managing the public IP" principal_type = "Group" } ip_reader = { principal_id = "11111111-1111-1111-1111-111111111111" role_definition_id_or_name = "/subscriptions/12345678-1234-1234-1234-123456789012/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7" description = "Audit system with read-only access" skip_service_principal_aad_check = true principal_type = "ServicePrincipal" } conditional_contributor = { principal_id = "22222222-2222-2222-2222-222222222222" role_definition_id_or_name = "Contributor" condition = "(!(ActionMatches{'Microsoft.Network/publicIPAddresses/delete'}))" condition_version = "2.0" principal_type = "ServicePrincipal" } } ``` -------------------------------- ### Dynamic IP for Cost Optimization Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/INDEX.md This example uses a dynamic IP allocation method for cost savings. Dynamic IPs are suitable for scenarios where a predictable IP address is not required. ```terraform module "public_ip_address" { source = "git::https://github.com/Azure/avm-res-network-publicipaddress.git" # Dynamic IP for cost optimization name = "pip-dynamic-cost" resource_group_name = "rg-pip-dynamic-cost" location = "eastus" allocation_method = "Dynamic" sku = "Basic" sku_tier = "Regional" tags = { environment = "dynamic-cost" } } ``` -------------------------------- ### Minimal Static Public IP Configuration Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/examples.md This snippet shows the most basic setup for a static, standard SKU public IP address using only required variables. It's suitable for simple deployments where advanced features are not needed. ```hcl terraform { required_version = ">= 1.0.0" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 4.0" } } } provider "azurerm" { features {} } resource "azurerm_resource_group" "example" { name = "rg-network" location = "East US" } module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-minimal" resource_group_name = azurerm_resource_group.example.name } output "public_ip_address" { value = module.public_ip.public_ip_address } ``` -------------------------------- ### Public IP with DNS Label and Custom Timeout Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/examples.md This example demonstrates how to create a public IP address with a DNS label for name resolution and configure a custom idle timeout. It also includes tags for better organization. ```hcl resource "azurerm_resource_group" "example" { name = "rg-web" location = "West Europe" } module "web_public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-web-app" resource_group_name = azurerm_resource_group.example.name # Enable DNS resolution domain_name_label = "myapp-service" # Configure allocation and timeout allocation_method = "Static" idle_timeout_in_minutes = 20 # Add tags for organization tags = { Environment = "Production" Application = "WebApp" Owner = "PlatformTeam" } } # Output the DNS FQDN output "dns_name" { value = "${module.web_public_ip.name}.westeurope.cloudapp.azure.com" description = "FQDN of the public IP" } ``` -------------------------------- ### Configure Role Assignments for Public IP Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/module-reference.md Example demonstrating how to configure role assignments for the Public IP Address. Supports assigning roles by name or ID, with optional ABAC conditions. ```hcl module "public_ip" { # ... other variables ... role_assignments = { reader = { principal_id = "00000000-0000-0000-0000-000000000000" role_definition_id_or_name = "Reader" description = "Grant Reader access" } contributor = { principal_id = "11111111-1111-1111-1111-111111111111" role_definition_id_or_name = "/subscriptions/{sub-id}/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c" condition = "(!(ActionMatches{'Microsoft.Network/publicIPAddresses/read'}))" condition_version = "2.0" } } } ``` -------------------------------- ### Conditional Resource Creation Based on Public IP Availability Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/outputs.md Use module outputs to conditionally create resources. This example creates a local file only if a public IP address has been successfully assigned. ```hcl module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" # ... configuration ... } locals { public_ip_available = module.public_ip.public_ip_address != "" } resource "local_file" "ip_config" { count = local.public_ip_available ? 1 : 0 filename = "${path.module}/ip_config.txt" content = "Public IP: ${module.public_ip.public_ip_address}" } ``` -------------------------------- ### Public IP with DNS Label Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/INDEX.md This example shows how to create a public IP address with a DNS label, enabling access via a fully qualified domain name (FQDN). Use this when you need a resolvable hostname for your IP. ```terraform module "public_ip_address" { source = "git::https://github.com/Azure/avm-res-network-publicipaddress.git" # Public IP with DNS label name = "pip-with-dns" resource_group_name = "rg-pip-with-dns" location = "eastus" allocation_method = "Static" sku = "Standard" sku_tier = "Regional" domain_name_label = "pip-with-dns-label" tags = { environment = "dns" } } ``` -------------------------------- ### Configure Resource Lock for Public IP Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/module-reference.md Example of how to apply a resource lock to the Public IP Address. The lock type can be 'CanNotDelete' or 'ReadOnly'. An optional custom name can be provided. ```hcl module "public_ip" { # ... other variables ... lock = { kind = "CanNotDelete" name = "my-custom-lock-name" # optional } } ``` -------------------------------- ### Public IP with RBAC Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/INDEX.md This example illustrates how to configure Role-Based Access Control (RBAC) for a public IP address. RBAC is essential for managing permissions and enforcing the principle of least privilege. ```terraform module "public_ip_address" { source = "git::https://github.com/Azure/avm-res-network-publicipaddress.git" # Public IP with RBAC name = "pip-with-rbac" resource_group_name = "rg-pip-with-rbac" location = "eastus" allocation_method = "Static" sku = "Standard" sku_tier = "Regional" # Example RBAC assignment (replace with your specific role and principal) role_assignments = [ { principal_id = "" role_definition_id = "" } ] tags = { environment = "rbac" } } ``` -------------------------------- ### Pinning AVM Module Version in Terraform Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/AGENTS.md When using AVM modules, it's crucial to pin to a specific version for predictable deployments. This example shows how to specify the version. ```terraform version = "1.2.3" ``` -------------------------------- ### Query Existing Public IP Resource Details Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/outputs.md Example of querying for existing public IP resource details using its name and resource group name. This is useful for retrieving information about a pre-existing public IP. ```hcl # Query resource details data "azurerm_public_ip" "existing" { name = module.public_ip.name resource_group_name = azurerm_resource_group.example.name } ``` -------------------------------- ### Public IP with RBAC Role Assignments Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/examples.md This example shows how to assign roles to a group and a service principal for managing a public IP address. It demonstrates granting 'Network Contributor' to a team and 'Reader' to an automation identity. ```hcl resource "azurerm_resource_group" "example" { name = "rg-shared-network" location = "Central US" } # Service principal for automation resource "azurerm_user_assigned_identity" "automation" { name = "id-network-automation" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location } # Azure AD group for network team data "azuread_group" "network_admins" { display_name = "Network Administrators" security_enabled = true } module "managed_public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-shared" resource_group_name = azurerm_resource_group.example.name # Assign roles to teams and automation role_assignments = { network_team = { principal_id = data.azuread_group.network_admins.object_id role_definition_id_or_name = "Network Contributor" description = "Network team manages public IP" principal_type = "Group" } automation_reader = { principal_id = azurerm_user_assigned_identity.automation.principal_id role_definition_id_or_name = "Reader" description = "Automation reads public IP details" principal_type = "ServicePrincipal" } } } ``` -------------------------------- ### Associate Public IP with Network Interface Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/outputs.md Example of associating a public IP address with a network interface using its resource ID. This is a common use case for connecting resources to the internet. ```hcl # Associate with a network interface resource "azurerm_network_interface_ip_configuration" "example" { name = "nic-config" network_interface_id = azurerm_network_interface.example.id public_ip_address_id = module.public_ip.public_ip_id private_ip_address_allocation = "Static" } ``` -------------------------------- ### Configure Role Assignment Scope with Public IP ID Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/outputs.md Example of configuring a role assignment scope using the public IP address resource ID. This allows granting specific permissions related to the public IP resource. ```hcl # Configure role assignment scope resource "azurerm_role_assignment" "example" { scope = module.public_ip.public_ip_id role_definition_name = "Network Contributor" principal_id = azurerm_user_assigned_identity.example.principal_id } ``` -------------------------------- ### Attach Public IP to Network Interface Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/resources.md Configures a network interface to use a specific public IP address by referencing its ID. This is a common setup for VMs needing external connectivity. ```hcl resource "azurerm_network_interface_ip_configuration" "example" { public_ip_address_id = azurerm_public_ip.this.id } ``` -------------------------------- ### Invalid SKU and Allocation Combination Scenario Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/validation-and-constraints.md Demonstrates a configuration where the 'Basic' SKU is used with 'Static' allocation, which is not supported. This scenario results in a deployment failure. ```hcl sku = "Basic" allocation_method = "Static" ``` -------------------------------- ### Basic Public IP Address Configuration Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/module-reference.md This snippet shows the minimal configuration required to deploy a public IP address using the module. It includes setting the location, name, and resource group. ```hcl terraform { required_version = ">= 1.0.0" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 4.0" } } } provider "azurerm" { features {} } resource "azurerm_resource_group" "example" { name = "rg-example" location = "East US" } module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" version = "~> 0.1" location = "East US" name = "pip-example" resource_group_name = azurerm_resource_group.example.name enable_telemetry = true } ``` -------------------------------- ### Migrate Public IP from Basic to Standard SKU Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/integration-patterns.md Demonstrates updating a Public IP resource configuration to migrate from a Basic SKU to a Standard SKU. This involves changing the SKU type and allocation method, and enabling advanced features like DDoS protection. ```hcl # During migration, update module configuration module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-upgraded" resource_group_name = azurerm_resource_group.example.name # Update SKU and related settings sku = "Standard" # Changed from Basic allocation_method = "Static" # Dynamic only works with Basic # Add advanced features available in Standard ddos_protection_mode = "Enabled" ddos_protection_plan_id = azurerm_ddos_protection_plan.example.id } ``` -------------------------------- ### Advanced Public IP Address Configuration with All Features Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/module-reference.md This snippet demonstrates the full range of options available for configuring a public IP address, including static allocation, DNS settings, SKU, availability zones, DDoS protection, and more. Ensure the SKU is 'Standard' for DDoS protection. ```hcl module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" version = "~> 0.1" # Required location = "East US" name = "pip-advanced" resource_group_name = azurerm_resource_group.example.name # Allocation and IP Configuration allocation_method = "Static" ip_version = "IPv4" idle_timeout_in_minutes = 15 # DNS Configuration domain_name_label = "my-domain-label" reverse_fqdn = "myreversedns.example.com" # SKU and Tier Configuration sku = "Standard" sku_tier = "Regional" # Availability Zones zones = [1, 2, 3] # IP Tags ip_tags = { tag1 = "value1" tag2 = "value2" } # DDoS Protection (requires Standard SKU) ddos_protection_mode = "Enabled" ddos_protection_plan_id = azurerm_ddos_protection_plan.example.id # Public IP Prefix (for static allocation from prefix) public_ip_prefix_id = azurerm_public_ip_prefix.example.id # Edge Zone (for Global SKU tier) edge_zone = "az-1" # Tags tags = { Environment = "Production" Owner = "NetworkTeam" } # Resource Lock lock = { kind = "CanNotDelete" name = "pip-lock" } # Role-Based Access Control role_assignments = { owner = { principal_id = azurerm_user_assigned_identity.example.principal_id role_definition_id_or_name = "Contributor" principal_type = "ServicePrincipal" } } # Diagnostic Settings diagnostic_settings = { to_log_analytics = { name = "pip-diagnostics-la" log_groups = ["allLogs"] metric_categories = ["AllMetrics"] workspace_resource_id = azurerm_log_analytics_workspace.example.id log_analytics_destination_type = "Dedicated" } } # Telemetry enable_telemetry = true } ``` -------------------------------- ### Public IP with DNS Name Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/README.md Creates a public IP address and assigns a DNS label, resulting in a fully qualified domain name. Ensure required variables and module source are configured. ```hcl module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" # ... required variables ... domain_name_label = "my-service" # Results in: my-service.{region}.cloudapp.azure.com } ``` -------------------------------- ### Dynamic Resource Creation with Public IP Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/outputs.md Reference the `public_ip_id` output when creating other resources, such as a load balancer. This pattern is useful when the public IP is a prerequisite for another resource's configuration. ```hcl module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" # ... configuration ... } resource "azurerm_lb" "example" { name = "lb-example" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location frontend_ip_configuration { name = "PublicIPAddress" public_ip_address_id = module.public_ip.public_ip_id } } ``` -------------------------------- ### Public IP Address Name Validation Regex Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/validation-and-constraints.md This regex defines the allowed characters and length for a public IP address name. It must start and end with an alphanumeric character or underscore, and can contain dots and hyphens in between. The total length is between 1 and 80 characters. ```regex ^[a-zA-Z0-9]([a-zA-Z0-9._-]{0,78}[a-zA-Z0-9_])?$ ``` -------------------------------- ### Optional Variable: allocation_method Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/configuration.md Determines how the IP address is allocated. Defaults to 'Static'. Accepts 'Static' or 'Dynamic'. ```hcl allocation_method = "Static" ``` -------------------------------- ### Full Configuration of a Production Public IP Address Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/examples.md This snippet demonstrates a comprehensive configuration for a production public IP address, including static allocation, DDoS protection, diagnostic settings, role assignments, and resource locks. ```hcl module "prod_public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" # Required location = azurerm_resource_group.prod.location name = "pip-prod-api-gateway" resource_group_name = azurerm_resource_group.prod.name # Allocation allocation_method = "Static" # DNS Configuration domain_name_label = "api-gateway-prod" # IP Configuration ip_version = "IPv4" idle_timeout_in_minutes = 30 ip_tags = { Tier = "Premium" Monitored = "true" } # SKU Configuration sku = "Standard" sku_tier = "Regional" zones = [1, 2, 3] # DDoS Protection ddos_protection_mode = "Enabled" ddos_protection_plan_id = azurerm_ddos_protection_plan.example.id # Resource Protection lock = { kind = "CanNotDelete" name = "pip-prod-lock" } # Access Control role_assignments = { network_team = { principal_id = data.azuread_group.network_team.object_id role_definition_id_or_name = "Network Contributor" description = "Network team manages prod IP" principal_type = "Group" } security_team_reader = { principal_id = data.azuread_group.security_team.object_id role_definition_id_or_name = "Reader" description = "Security team audits IP configuration" principal_type = "Group" } } # Diagnostics diagnostic_settings = { to_log_analytics = { name = "pip-diag-law" workspace_resource_id = azurerm_log_analytics_workspace.prod.id log_analytics_destination_type = "Dedicated" log_groups = ["allLogs"] metric_categories = ["AllMetrics"] } archive_to_storage = { name = "pip-diag-archive" storage_account_resource_id = azurerm_storage_account.diagnostics.id log_categories = ["PublicIPAddressEvents"] } } # Tags for organization and billing tags = { Environment = "Production" Application = "API-Gateway" Owner = "Platform-Team" CostCenter = "Engineering" Criticality = "High" BackupPolicy = "Daily" Compliance = "SOC2" } # Enable telemetry for module usage tracking enable_telemetry = true } # Outputs output "dns_name" { value = "api-gateway-prod.eastus.cloudapp.azure.com" description = "DNS FQDN of the public IP" } output "ip_address" { value = module.prod_public_ip.public_ip_address sensitive = false description = "Static public IP address" } output "resource_id" { value = module.prod_public_ip.resource_id description = "Azure resource ID for reference in other configurations" } output "configuration_summary" { value = { name = module.prod_public_ip.name region = azurerm_resource_group.prod.location sku = "Standard" sku_tier = "Regional" zones = [1, 2, 3] ddos_protection = "Enabled" dns_label = "api-gateway-prod" locks = "CanNotDelete" diagnostics = ["Log Analytics", "Storage Archive"] role_assignments = 2 } description = "Summary of public IP configuration" } ``` -------------------------------- ### Multi-Region Load Balancing with Global SKU Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/integration-patterns.md Sets up Public IP addresses for multi-region load balancing using the 'Global' SKU tier. This enables global distribution of traffic across different Azure regions. ```hcl locals { regions = { east = "East US" west = "West US" } } module "regional_public_ips" { for_each = local.regions source = "Azure/avm-res-network-publicipaddress/azurerm" location = each.value name = "pip-lb-${each.key}" resource_group_name = azurerm_resource_group.global.name sku = "Standard" sku_tier = "Global" # For global load distribution edge_zone = "az-${each.key}" } ``` -------------------------------- ### Minimal Public IP Deployment Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/README.md A basic configuration for deploying a public IP address. Ensure you have the necessary Azure provider and module source configured. ```hcl module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = "East US" name = "pip-example" resource_group_name = "rg-network" } ``` -------------------------------- ### Reference Nested Module Public IP Output Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/outputs.md Demonstrates how a root module can reference an output from a nested module, which in turn references an output from its own nested public IP module. This shows a multi-level output referencing pattern. ```hcl # modules/infrastructure/main.tf module "public_ip" { source = "../public_ip" # ... variables ... } # modules/infrastructure/outputs.tf output "public_ip_resource_id" { value = module.public_ip.resource_id } # root/main.tf references nested module outputs output "infrastructure_public_ip_id" { value = module.infrastructure.public_ip_resource_id } ``` -------------------------------- ### Public IP with Diagnostic Logging to Log Analytics Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/examples.md Configure diagnostic settings to send logs and metrics to a Log Analytics workspace for monitoring and troubleshooting. Ensure the Log Analytics workspace is created before configuring the diagnostic settings. ```hcl resource "azurerm_resource_group" "example" { name = "rg-monitoring" location = "North Europe" } # Create Log Analytics Workspace for diagnostics resource "azurerm_log_analytics_workspace" "monitoring" { name = "law-network-diagnostics" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name sku = "PerGB2018" } module "monitored_public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-monitored" resource_group_name = azurerm_resource_group.example.name # Configure diagnostic settings diagnostic_settings = { send_to_law = { name = "pip-diagnostics" workspace_resource_id = azurerm_log_analytics_workspace.monitoring.id log_analytics_destination_type = "Dedicated" log_groups = ["allLogs"] metric_categories = ["AllMetrics"] } } tags = { MonitoredBy = "ObservabilityTeam" } } # Query diagnostic logs output "law_query" { value = "Execute in Log Analytics: AzureActivity | where ResourceId contains 'pip-monitored'" } ``` -------------------------------- ### Global Tier Without Edge Zone Scenario Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/validation-and-constraints.md Illustrates a configuration where the 'Global' SKU tier is selected without specifying an 'edge_zone'. This is an invalid configuration and will cause deployment failure. ```hcl sku_tier = "Global" edge_zone = null # Not specified ``` -------------------------------- ### Public IP with Diagnostic Logging Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/INDEX.md Shows how to enable diagnostic logging for a public IP address, allowing you to monitor its activity and troubleshoot issues. Configure this for auditing and operational insights. ```terraform module "public_ip_address" { source = "git::https://github.com/Azure/avm-res-network-publicipaddress.git" # Public IP with diagnostic settings name = "pip-with-diagnostics" resource_group_name = "rg-pip-with-diagnostics" location = "eastus" allocation_method = "Static" sku = "Standard" sku_tier = "Regional" diagnostic_settings = [ { name = "diag-settings-pip" log_analytics_workspace_id = "" event_hub_name = "" storage_account_id = "" log_categories = ["ApplicationGatewayAccessLog"] metric_categories = ["AllMetrics"] } ] tags = { environment = "diagnostics" } } ``` -------------------------------- ### Set Public IP Address SKU Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/configuration.md Specify the SKU for the public IP address. Use 'Standard' for most cases, which supports static/dynamic allocation and DDoS protection. 'Basic' is an older SKU with limited features. ```hcl sku = "Standard" ``` -------------------------------- ### Dynamic Block for Metric Categories Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/resources.md Creates one 'metric' block per metric category. Specify 'AllMetrics' to collect all available metrics. ```hcl dynamic "metric" { for_each = each.value.metric_categories content { category = metric.value } } ``` -------------------------------- ### Documenting Cross-Variable Constraints Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/validation-and-constraints.md Use comments to document constraints between variables, such as requiring 'edge_zone' when the 'sku_tier' is 'Global'. ```hcl # Document in comments that Global tier requires edge_zone variable "sku_tier" { type = string default = "Regional" description = "Regional or Global. Global requires edge_zone to be set." } ``` -------------------------------- ### Correct SKU Value for Public IP Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/validation-and-constraints.md Ensure the SKU value for a Public IP Address is either 'Basic' or 'Standard' to avoid validation errors. ```hcl sku = "Standard" # Change to valid value ``` -------------------------------- ### Create Multiple Public IPs for Scalable Services Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/integration-patterns.md Dynamically create multiple public IP addresses for scalable services using a `for_each` loop. This pattern is useful for distributing load or providing unique IPs per instance. ```hcl variable "environment_count" { type = number default = 3 } module "scalable_public_ips" { for_each = { for i in range(var.environment_count) : "env-${i}" => { index = i location = azurerm_resource_group.example.location } } source = "Azure/avm-res-network-publicipaddress/azurerm" location = each.value.location name = "pip-service-${each.key}" resource_group_name = azurerm_resource_group.example.name tags = { Index = each.value.index Environment = each.key } } output "public_ips" { value = { for key, module in module.scalable_public_ips : key => module.public_ip_address } } ``` -------------------------------- ### Output Public IP Details to Consumer Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/outputs.md Define an output in your module to expose details of the created public IP address to the calling module. This allows consumers to access properties like name, IP address, and resource ID. ```hcl output "public_ip" { description = "The public IP address details" value = { name = module.public_ip.name ip_address = module.public_ip.public_ip_address resource_id = module.public_ip.resource_id } } ``` -------------------------------- ### Combine Public IP Output Values into a Reference Object Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/outputs.md Aggregate multiple outputs related to a public IP address into a single map for easier management and consumption. This is useful for passing comprehensive details to other resources or outputs. ```hcl locals { public_ip_reference = { name = module.public_ip.name address = module.public_ip.public_ip_address id = module.public_ip.public_ip_id resource_id = module.public_ip.resource_id } } output "public_ip_info" { value = local.public_ip_reference description = "Complete public IP information" } ``` -------------------------------- ### Export Public IP Configuration to JSON Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/integration-patterns.md Exports the configuration details of a Public IP address, including its name, IP address, and resource ID, to a JSON file. Includes a timestamp for tracking. ```hcl module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" # ... configuration ... } # Export public IP details to JSON file resource "local_file" "ip_config" { filename = "${path.module}/public_ip_config.json" content = jsonencode({ name = module.public_ip.name ip_address = module.public_ip.public_ip_address resource_id = module.public_ip.resource_id created_at = timestamp() }) } ``` -------------------------------- ### Telemetry Module Arguments Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/resources.md Configuration for the telemetry module, including tags for subscription, tenant, module source, version, and a random ID. It also includes the deployment location. ```hcl tags = merge({ subscription_id = one(data.azapi_client_config.telemetry).subscription_id tenant_id = one(data.azapi_client_config.telemetry).tenant_id module_source = one(data.modtm_module_source.telemetry).module_source module_version = one(data.modtm_module_source.telemetry).module_version random_id = one(random_uuid.telemetry).result }, { location = local.main_location }) ``` -------------------------------- ### Multiple NICs with Multiple Public IPs Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/integration-patterns.md Creates multiple Public IP addresses and associates them with different Network Interface IP configurations, useful for VMs with multiple network interfaces. ```hcl module "public_ips" { for_each = toset(["primary", "secondary"]) source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-app-${each.value}" resource_group_name = azurerm_resource_group.example.name } resource "azurerm_network_interface" "multi_nic" { for_each = { primary = azurerm_subnet.primary.id secondary = azurerm_subnet.secondary.id } name = "nic-${each.key}" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name ip_configuration { name = each.key subnet_id = each.value private_ip_address_allocation = "Static" public_ip_address_id = module.public_ips[each.key].public_ip_id } } ``` -------------------------------- ### Load Balancer Frontend IP Configuration Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/integration-patterns.md Configures a Public IP address for the frontend of a Standard Load Balancer. The SKU must be set to 'Standard' for the Public IP and Load Balancer. ```hcl module "lb_public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-load-balancer" resource_group_name = azurerm_resource_group.example.name sku = "Standard" # Required for Standard LB } resource "azurerm_lb" "example" { name = "lb-api" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name sku = "Standard" frontend_ip_configuration { name = "frontend" public_ip_address_id = module.lb_public_ip.public_ip_id } } resource "azurerm_lb_backend_address_pool" "example" { loadbalancer_id = azurerm_lb.example.id name = "backend-pool" } resource "azurerm_lb_rule" "example" { loadbalancer_id = azurerm_lb.example.id name = "http" protocol = "Tcp" frontend_port = 80 backend_port = 80 frontend_ip_configuration_name = "frontend" backend_address_pool_ids = [azurerm_lb_backend_address_pool.example.id] } ``` -------------------------------- ### Declare Public IP Module Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/module-reference.md Basic module declaration for deploying an Azure Public IP Address. Ensure the source path and version are correctly specified. ```hcl module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" version = "~> 0.1" location = "East US" name = "pip-example" resource_group_name = "rg-example" } ``` -------------------------------- ### Integrate Public IP with VPN Gateway Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/integration-patterns.md Assign a Standard SKU Public IP Address with Static allocation to a VPN Gateway for stable connectivity. The IP is configured within the gateway's IP configuration block. ```hcl module "vpn_public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-vpn-gateway" resource_group_name = azurerm_resource_group.example.name sku = "Standard" allocation_method = "Static" } resource "azurerm_vpn_gateway" "example" { name = "vpn-gateway" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name type = "Vpn" vpn_type = "RouteBased" ip_configuration { name = "vnetGatewayConfig" public_ip_address_id = module.vpn_public_ip.public_ip_id subnet_id = azurerm_subnet.gateway.id } } ``` -------------------------------- ### Production Public IP Deployment Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/README.md A comprehensive configuration for a production-ready public IP address, including SKU, allocation method, resource locks, role assignments, and diagnostic settings. Requires Azure provider, module source, and potentially data sources for principal IDs and Log Analytics workspace. ```hcl module "public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" # Required location = "East US" name = "pip-prod" resource_group_name = "rg-network" # Configuration sku = "Standard" allocation_method = "Static" # Advanced Features lock = { kind = "CanNotDelete" } role_assignments = { team = { principal_id = data.azuread_group.team.object_id role_definition_id_or_name = "Network Contributor" principal_type = "Group" } } diagnostic_settings = { logging = { workspace_resource_id = azurerm_log_analytics_workspace.example.id } } } ``` -------------------------------- ### Conditional Public IP Deployment Based on Environment Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/integration-patterns.md Configure public IP address settings (SKU, allocation method, diagnostics, locks) conditionally based on an environment variable. This allows for different configurations for development, staging, and production. ```hcl variable "environment" { type = string validation { condition = contains(["dev", "staging", "prod"], var.environment) error_message = "Environment must be dev, staging, or prod." } } locals { env_config = { dev = { sku = "Basic" allocation_method = "Dynamic" enable_diagnostics = false enable_lock = false } staging = { sku = "Standard" allocation_method = "Static" enable_diagnostics = true enable_lock = false } prod = { sku = "Standard" allocation_method = "Static" enable_diagnostics = true enable_lock = true } } config = local.env_config[var.environment] } module "environment_public_ip" { source = "Azure/avm-res-network-publicipaddress/azurerm" location = azurerm_resource_group.example.location name = "pip-${var.environment}" resource_group_name = azurerm_resource_group.example.name sku = local.config.sku allocation_method = local.config.allocation_method lock = local.config.enable_lock ? { kind = "CanNotDelete" } : null diagnostic_settings = local.config.enable_diagnostics ? { log_analytics = { workspace_resource_id = azurerm_log_analytics_workspace.example.id log_analytics_destination_type = "Dedicated" } } : {} } ``` -------------------------------- ### Associate Public IP Address with a Prefix Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/configuration.md Link a public IP address to a public IP prefix for allocation from the prefix. This requires a static allocation method and available addresses within the prefix. ```hcl public_ip_prefix_id = "/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/rg-network/providers/Microsoft.Network/publicIPPrefixes/pip-prefix" ``` -------------------------------- ### Public IP with Resource Lock Source: https://github.com/azure/terraform-azurerm-avm-res-network-publicipaddress/blob/main/_autodocs/INDEX.md Demonstrates applying a resource lock to a public IP address to prevent accidental deletion or modification. This is crucial for production environments to maintain stability. ```terraform module "public_ip_address" { source = "git::https://github.com/Azure/avm-res-network-publicipaddress.git" # Public IP with resource lock name = "pip-with-lock" resource_group_name = "rg-pip-with-lock" location = "eastus" allocation_method = "Static" sku = "Standard" sku_tier = "Regional" lock = { kind = "CanNotDelete" } tags = { environment = "locked" } } ```