Azure Network Prefix

This page shows how to write Terraform and Azure Resource Manager for Network Prefix and write them securely.

azurerm_public_ip_prefix (Terraform)

The Prefix in Network can be configured in Terraform with the resource name azurerm_public_ip_prefix. The following sections describe 8 examples of how to use the resource and its parameters.

Example Usage from GitHub

public_ip_prefix.tf#L2
resource "azurerm_public_ip_prefix" "prefix" {
    name                = var.name
  location            = var.location
  resource_group_name = var.rg
  tags                = var.tags

main.tf#L1
resource "azurerm_public_ip_prefix" "hubipprefix" {
  name                = "nat-gateway-publicIPPrefix"
  location            = var.location
  resource_group_name = var.resource_group_name
  prefix_length       = 30
  zones               = ["1"]
main.tf#L1
resource "azurerm_public_ip_prefix" "main" {
  for_each            = var.public_ip_prefixes
  name                = each.key
  location            = var.location
  resource_group_name = var.resource_group_name
  prefix_length       = each.value.prefix_length
main.tf#L23
resource "azurerm_public_ip_prefix" "p-ip-px" {
  name                = "nat-gateway-publicIPPrefix"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  prefix_length       = 31
  #zones               = ["1"]
public_ip_prefix_test.tf#L10
resource "azurerm_public_ip_prefix" "example" {
  name                = "acceptanceTestPublicIpPrefix1"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  prefix_length = 31
main.tf#L7
resource "azurerm_public_ip_prefix" "this" {
  location            = var.location
  name                = var.name
  prefix_length       = var.prefix_length
  resource_group_name = var.resource_group_name
  sku                 = var.sku
main.tf#L23
resource "azurerm_public_ip_prefix" "pre001" {
  name                = ""
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  prefix_length       = 30
  zones               = ["1"]
main.tf#L8
resource "azurerm_public_ip_prefix" "public_ip_prefix" {
  name                = "ppp01"
  location            = var.loc
  resource_group_name = "terraform"
  prefix_length       = 28
}

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a Public IP Prefix.

Tips: Best Practices for The Other Azure Network Resources

In addition to the azurerm_network_security_group, Azure Network has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_network_security_group

Ensure to disable RDP port from the Internet

It is better to disable the RDP port from the Internet. RDP access should not be accepted from the Internet (*, 0.0.0.0, /0, internet, any), and consider using the Azure Bastion Service.

risk-label

azurerm_network_security_rule

Ensure to set a more restrictive CIDR range for ingress from the internet

It is better to set a more restrictive CIDR range not to use very broad subnets. If possible, segments should be divided into smaller subnets.

risk-label

azurerm_network_watcher_flow_log

Ensure to enable Retention policy for flow logs and set it to enough duration

It is better to enable a retention policy for flow logs. Flow logs show us all network activity in the cloud environment and support us when we face critical incidents.

Review your Azure Network settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Microsoft.Network/publicIPPrefixes (Azure Resource Manager)

The publicIPPrefixes in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/publicIPPrefixes. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

azure.com_network-publicIpPrefix_2018-08-01.json#L113
                      "type": "Microsoft.Network/publicIPPrefixes"
                    },
                    {
                      "id": "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/publicIPPrefixes/ipprefix01",
                      "location": "westus",
                      "name": "ipprefix01",
azure.comnetwork-publicIpPrefix.json#L401
              "type": "Microsoft.Network/publicIPPrefixes"
            },
            {
              "id": "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/publicIPPrefixes/ipprefix01",
              "location": "westus",
              "name": "ipprefix01",
PublicIpPrefixCreateDefaults.json#L23
          "type" : "Microsoft.Network/publicIPPrefixes"
        }
      },
      "201" : {
        "body" : {
          "name" : "test-ipprefix",
PublicIpPrefixCreateDefaults.json#L23
          "type" : "Microsoft.Network/publicIPPrefixes"
        }
      },
      "201" : {
        "body" : {
          "name" : "test-ipprefix",
PublicIpPrefixListAll.json#L25
              "type" : "Microsoft.Network/publicIPPrefixes"
            },
            {
              "name" : "ipprefix01",
              "id" : "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/publicIPPrefixes/ipprefix01",
              "location" : "westus",
PublicIpPrefixListAll.json#L25
              "type" : "Microsoft.Network/publicIPPrefixes"
            },
            {
              "name" : "ipprefix01",
              "id" : "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/publicIPPrefixes/ipprefix01",
              "location" : "westus",
PublicIpPrefixList.json#L27
              "type" : "Microsoft.Network/publicIPPrefixes"
            },
            {
              "name" : "ipprefix03",
              "id" : "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/publicIPPrefixes/ipprefix03",
              "location" : "westus",
PublicIpPrefixList.json#L27
              "type" : "Microsoft.Network/publicIPPrefixes"
            },
            {
              "name" : "ipprefix03",
              "id" : "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/publicIPPrefixes/ipprefix03",
              "location" : "westus",
PublicIpPrefixCreateCustomizedValues.json#L33
          "type" : "Microsoft.Network/publicIPPrefixes"
        }
      },
      "201" : {
        "body" : {
          "name" : "test-ipprefix",
PublicIpPrefixCreateCustomizedValues.json#L33
          "type" : "Microsoft.Network/publicIPPrefixes"
        }
      },
      "201" : {
        "body" : {
          "name" : "test-ipprefix",

Parameters

  • name required - string
  • type required - string
  • apiVersion required - string
  • location required - string

    Resource location.

  • tags optional - string

    Resource tags.

  • extendedLocation optional
      • name required - string

        The name of the extended location.

      • type required - string

        The type of the extended location.

  • sku optional
      • name optional - string

        Name of a public IP prefix SKU.

      • tier optional - string

        Tier of a public IP prefix SKU.

  • properties required
      • publicIPAddressVersion optional - string

        The public IP address version.

      • ipTags optional array
          • ipTagType optional - string

            The IP tag type. Example: FirstPartyUsage.

          • tag optional - string

            The value of the IP tag associated with the public IP. Example: SQL.

      • prefixLength optional - integer

        The Length of the Public IP Prefix.

      • customIPPrefix optional
          • id required - string

            Resource ID.

  • zones optional - array

    A list of availability zones denoting the IP allocated for the resource needs to come from.

Frequently asked questions

What is Azure Network Prefix?

Azure Network Prefix is a resource for Network of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Network Prefix?

For Terraform, the hyundonk/ebkr-landing-zones, pagyP/Terraform-Lab and guidalabs/terraform-azure-public-ip-prefix source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the Pudding124/SwaggerStructure, rwth-acis/apis-guru-statistics and sanjaypavan/OldAzure-Rest-API source code examples are useful. See the Azure Resource Manager Example section for further details.