Skip to content

azurermFirewallNatRuleCollection

Manages a NAT Rule Collection within an Azure Firewall.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermVirtualNetworkExample = new azurerm.virtualNetwork.VirtualNetwork(
  this,
  "example_1",
  {
    address_space: ["10.0.0.0/16"],
    location: azurermResourceGroupExample.location,
    name: "testvnet",
    resource_group_name: azurermResourceGroupExample.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermVirtualNetworkExample.overrideLogicalId("example");
const azurermPublicIpExample = new azurerm.publicIp.PublicIp(
  this,
  "example_2",
  {
    allocation_method: "Static",
    location: azurermResourceGroupExample.location,
    name: "testpip",
    resource_group_name: azurermResourceGroupExample.name,
    sku: "Standard",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermPublicIpExample.overrideLogicalId("example");
const azurermSubnetExample = new azurerm.subnet.Subnet(this, "example_3", {
  address_prefixes: ["10.0.1.0/24"],
  name: "AzureFirewallSubnet",
  resource_group_name: azurermResourceGroupExample.name,
  virtual_network_name: azurermVirtualNetworkExample.name,
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubnetExample.overrideLogicalId("example");
const azurermFirewallExample = new azurerm.firewall.Firewall(
  this,
  "example_4",
  {
    ip_configuration: [
      {
        name: "configuration",
        public_ip_address_id: azurermPublicIpExample.id,
        subnet_id: azurermSubnetExample.id,
      },
    ],
    location: azurermResourceGroupExample.location,
    name: "testfirewall",
    resource_group_name: azurermResourceGroupExample.name,
    sku_name: "AZFW_VNet",
    sku_tier: "Standard",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermFirewallExample.overrideLogicalId("example");
const azurermFirewallNatRuleCollectionExample =
  new azurerm.firewallNatRuleCollection.FirewallNatRuleCollection(
    this,
    "example_5",
    {
      action: "Dnat",
      azure_firewall_name: azurermFirewallExample.name,
      name: "testcollection",
      priority: 100,
      resource_group_name: azurermResourceGroupExample.name,
      rule: [
        {
          destination_addresses: [azurermPublicIpExample.ipAddress],
          destination_ports: ["53"],
          name: "testrule",
          protocols: ["TCP", "UDP"],
          source_addresses: ["10.0.0.0/16"],
          translated_address: "8.8.8.8",
          translated_port: 53,
        },
      ],
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermFirewallNatRuleCollectionExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • name - (Required) Specifies the name of the NAT Rule Collection which must be unique within the Firewall. Changing this forces a new resource to be created.

  • azureFirewallName - (Required) Specifies the name of the Firewall in which the NAT Rule Collection should be created. Changing this forces a new resource to be created.

  • resourceGroupName - (Required) Specifies the name of the Resource Group in which the Firewall exists. Changing this forces a new resource to be created.

  • priority - (Required) Specifies the priority of the rule collection. Possible values are between 100 - 65000.

  • action - (Required) Specifies the action the rule will apply to matching traffic. Possible values are dnat and snat.

  • rule - (Required) One or more rule blocks as defined below.


A rule block supports the following:

  • name - (Required) Specifies the name of the rule.

  • description - (Optional) Specifies a description for the rule.

  • destinationAddresses - (Required) A list of destination IP addresses and/or IP ranges.

  • destinationPorts - (Required) A list of destination ports.

  • protocols - (Required) A list of protocols. Possible values are any, icmp, tcp and udp. If action is dnat, protocols can only be tcp and udp.

  • sourceAddresses - (Optional) A list of source IP addresses and/or IP ranges.

  • sourceIpGroups - (Optional) A list of source IP Group IDs for the rule.

-> NOTE At least one of sourceAddresses and sourceIpGroups must be specified for a rule.

  • translatedAddress - (Required) The address of the service behind the Firewall.

  • translatedPort - (Required) The port of the service behind the Firewall.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Firewall NAT Rule Collection.
  • update - (Defaults to 30 minutes) Used when updating the Firewall NAT Rule Collection.
  • read - (Defaults to 5 minutes) Used when retrieving the Firewall NAT Rule Collection.
  • delete - (Defaults to 30 minutes) Used when deleting the Firewall NAT Rule Collection.

Import

Azure Firewall NAT Rule Collections can be imported using the resourceId, e.g.

terraform import azurerm_firewall_nat_rule_collection.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/azureFirewalls/myfirewall/natRuleCollections/mycollection