I'm quite new to terraform, and i've been trying to deploy 2 VMs behind a LB. I keep receiving the following error when deploying the resources (mind you, everything else gets deployed as expected, just the rule does not):
╷
│ Error: Unsupported argument
│
│ on main.tf line 119, in resource "azurerm_lb_nat_rule" "example1":
│ 119: frontend_port_start = 5000
│
│ An argument named "frontend_port_start" is not expected here.
╵
╷
│ Error: Unsupported argument
│
│ on main.tf line 120, in resource "azurerm_lb_nat_rule" "example1":
│ 120: frontend_port_end = 5100
│
│ An argument named "frontend_port_end" is not expected here.
╵
╷
│ Error: Unsupported argument
│
│ on main.tf line 122, in resource "azurerm_lb_nat_rule" "example1":
│ 122: backend_address_pool_id = azurerm_lb_backend_address_pool.example.id
│
│ An argument named "backend_address_pool_id" is not expected here.
╵
This is the resource in question:
resource "azurerm_lb_nat_rule" "example1" {
resource_group_name = azurerm_resource_group.example.name
loadbalancer_id = azurerm_lb.example.id
name = "SSHAccess"
protocol = "Tcp"
frontend_port_start = 5000
frontend_port_end = 5100
backend_port = 1234
backend_address_pool_id = azurerm_lb_backend_address_pool.example.id
frontend_ip_configuration_name = "PublicIPAddress"
}
LB SKU is Standard:
resource "azurerm_lb" "example" {
name = "TestLoadBalancer"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku = "Standard"
frontend_ip_configuration {
name = "PublicIPAddress"
public_ip_address_id = azurerm_public_ip.example.id
}
}
According to the documentation they are supported arguments: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb_nat_rule#backend_address_pool_id
In the meanwhile i've found a better method of doing what i needed, but still could not figure out why the error above is happening.
I searched a bit, and could not find why this happens.
Any idea?
This will deploy the rule, but will not be attached to anything the the backend pool/individual VM
resource "azurerm_lb_nat_rule" "example1" {
resource_group_name = azurerm_resource_group.example.name
loadbalancer_id = azurerm_lb.example.id
name = "SSHAccess"
protocol = "Tcp"
frontend_port = 5000
backend_port = 22
# backend_address_pool_ids = azurerm_lb_backend_address_pool.example.id
frontend_ip_configuration_name = "PublicIPAddress"
}
I tried to Provision the backend_address_pool_id argument or frontend port range it supported in azurerm_lb_nat_rule in terraform successfully.
Looking at your code and comparing it with the documentation, it seems that the frontend_port_start
, frontend_port_end
, and backend_address_pool_id
arguments are indeed supported in the current version of the AzureRM Terraform provider.
Since the provider information was provided as 3.0.0. I suggest you update to the latest one as it seems to be working fine as far as I am concerned.
To resolve this issue, please use a version of the AzureRM Terraform provider that supports these arguments. You can specify the provider version in your configuration to ensure you use a compatible version.
Here to have a smooth transition I was using the latest version of the provider to avoid unnecessary errors.
My terraform Configuration:
provider "azurerm" {
features {}
} # Here I used provider module configuration with the latest version i.e..,v3.71.0
data "azurerm_resource_group" "example" {
name = "v-bolliv"
}
resource "azurerm_public_ip" "example" {
name = "example-public-ipvk"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_lb" "example" {
name = "TestLoadBalancervk"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
sku = "Standard"
frontend_ip_configuration {
name = "PublicIPAddressvk"
public_ip_address_id = azurerm_public_ip.example.id
}
}
resource "azurerm_lb_backend_address_pool" "example" {
loadbalancer_id = azurerm_lb.example.id
name = "example-backend-poolvk"
}
resource "azurerm_lb_nat_rule" "example1" {
resource_group_name = data.azurerm_resource_group.example.name
loadbalancer_id = azurerm_lb.example.id
name = "SSHAccessvk"
protocol = "Tcp"
frontend_port_start = 5000
frontend_port_end = 5100
backend_port = 1234
backend_address_pool_id = azurerm_lb_backend_address_pool.example.id
frontend_ip_configuration_name = "PublicIPAddressvk"
}
resource "azurerm_virtual_network" "example" {
name = "example-vnetvk"
address_space = ["10.0.0.0/16"]
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
name = "example-subnetvk"
resource_group_name = data.azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.1.0/24"]
}
resource "azurerm_network_interface" "example" {
name = "example-nicvk"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
ip_configuration {
name = "example-ipconfigvk"
subnet_id = azurerm_subnet.example.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_virtual_machine" "example" {
name = "example-vmvk"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
network_interface_ids = [azurerm_network_interface.example.id]
vm_size = "Standard_DS1_v2"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
storage_os_disk {
name = "example-osdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "example-vm"
admin_username = "adminuser"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
}
Output: