Azure Load Balancer NAT Rule
This page shows how to write Terraform and Azure Resource Manager for Load Balancer NAT Rule and write them securely.
azurerm_lb_nat_rule (Terraform)
The NAT Rule in Load Balancer can be configured in Terraform with the resource name azurerm_lb_nat_rule
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_lb_nat_rule" "SSH1" {
resource_group_name = var.resource_group_name
loadbalancer_id = azurerm_lb.lb_f5.id
name = "SSH1"
protocol = "Tcp"
frontend_port = 22
resource "azurerm_lb_nat_rule" "LB1natrule11356" {
resource_group_name = azurerm_resource_group.TESTlab.name
loadbalancer_id = azurerm_lb.LB1.id
name = "RDPnatrule1VM1356"
protocol = "Tcp"
frontend_port = 3389
resource "azurerm_lb_nat_rule" "ssh-nat-rule" {
resource_group_name = azurerm_resource_group.my-group.name
loadbalancer_id = azurerm_lb.my-lb.id
name = "ssh-nat-rule"
protocol = "Tcp"
frontend_port = 22
resource "azurerm_lb_nat_rule" "lb_nat_rule" {
backend_port = 80
frontend_ip_configuration_name = var.pip_name
frontend_port = 80
loadbalancer_id = azurerm_lb.lb.id
name = "inbound"
resource "azurerm_lb_nat_rule" "natrule2" {
resource_group_name = azurerm_resource_group.david-rg.name
loadbalancer_id = azurerm_lb.david-lb.id
name = "web2SSH"
protocol = "Tcp"
frontend_port = 50002
resource "azurerm_lb_nat_rule" "natrule1" {
resource_group_name = azurerm_resource_group.david-rg.name
loadbalancer_id = azurerm_lb.david-lb.id
name = "web1SSH"
protocol = "Tcp"
frontend_port = 50001
resource "azurerm_lb_nat_rule" "natrule2" {
resource_group_name = azurerm_resource_group.user12rg.name
loadbalancer_id = azurerm_lb.user12-lb.id
name = "web2SSH"
protocol = "Tcp"
frontend_port = 50002
resource "azurerm_lb_nat_rule" "natrule1" {
resource_group_name = azurerm_resource_group.user12rg.name
loadbalancer_id = azurerm_lb.user12-lb.id
name = "web1SSH"
protocol = "Tcp"
frontend_port = 50001
resource "azurerm_lb_nat_rule" "natrule2" {
resource_group_name = azurerm_resource_group.user24-rg1.name
loadbalancer_id = azurerm_lb.user24-lb.id
name = "web2SSH"
protocol = "Tcp"
frontend_port = 50002
resource "azurerm_lb_nat_rule" "natrule2" {
resource_group_name = azurerm_resource_group.user12rg.name
loadbalancer_id = azurerm_lb.user12-lb.id
name = "web2SSH"
protocol = "Tcp"
frontend_port = 50002
Parameters
-
backend_ip_configuration_id
optional computed - string -
backend_port
required - number -
enable_floating_ip
optional computed - bool -
enable_tcp_reset
optional - bool -
frontend_ip_configuration_id
optional computed - string -
frontend_ip_configuration_name
required - string -
frontend_port
required - number -
id
optional computed - string -
idle_timeout_in_minutes
optional computed - number -
loadbalancer_id
required - string -
name
required - string -
protocol
required - string -
resource_group_name
required - string -
timeouts
single block
Explanation in Terraform Registry
Manages a Load Balancer NAT Rule. -> NOTE: This resource cannot be used with with virtual machine scale sets, instead use the
azurerm_lb_nat_pool
resource.NOTE When using this resource, the Load Balancer needs to have a FrontEnd IP Configuration Attached
Microsoft.Network/loadBalancers/inboundNatRules (Azure Resource Manager)
The loadBalancers/inboundNatRules in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/loadBalancers/inboundNatRules
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
name
required - stringtype
required - stringapiVersion
required - stringproperties
requiredfrontendIPConfiguration
requiredid
required - stringResource ID.
protocol
required - stringThe reference to the transport protocol used by the load balancing rule.
frontendPort
required - integerThe port for the external endpoint. Port numbers for each rule must be unique within the Load Balancer. Acceptable values range from 1 to 65534.
backendPort
required - integerThe port used for the internal endpoint. Acceptable values range from 1 to 65535.
idleTimeoutInMinutes
optional - integerThe timeout for the TCP idle connection. The value can be set between 4 and 30 minutes. The default value is 4 minutes. This element is only used when the protocol is set to TCP.
enableFloatingIP
optional - booleanConfigures a virtual machine's endpoint for the floating IP capability required to configure a SQL AlwaysOn Availability Group. This setting is required when using the SQL AlwaysOn Availability Groups in SQL server. This setting can't be changed after you create the endpoint.
enableTcpReset
optional - booleanReceive bidirectional TCP Reset on TCP flow idle timeout or unexpected connection termination. This element is only used when the protocol is set to TCP.
Frequently asked questions
What is Azure Load Balancer NAT Rule?
Azure Load Balancer NAT Rule is a resource for Load Balancer of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Load Balancer NAT Rule?
For Terraform, the jungcheolkwon/blueprint, nzebar/Terraform and tkaburagi/tfe-on-azure source code examples are useful. See the Terraform Example section for further details.