0

I'm deploying infrastructure on Azure using Terraform, I'm using modules for a linux scale set an a load balancer and using azurerm_lb_nat_pool in order to have SSH access to the VMs, I have a need now to retrieve the ports of the NAT rules for other purposes.

For the life of me I cannot find a way to retrieve them, went through all the terraform documentation and cannot find it under any data source or attribute reference.

Here is my LB code:

resource "azurerm_lb" "front-load-balancer" {
  name                = "front-load-balancer"
  location            = var.def-location
  resource_group_name = var.rg-name
  sku                 = "Standard"

  
  frontend_ip_configuration {
    name                 = "frontend-IP-configuration"
    public_ip_address_id = var.public-ip-id
  }
}

resource "azurerm_lb_nat_pool" "lb-nat-pool" {
  resource_group_name            = var.rg-name
  loadbalancer_id                = azurerm_lb.front-load-balancer.id
  name                           = "lb-nat-pool"
  protocol                       = "Tcp"
  frontend_port_start            = var.frontend-port-start
  frontend_port_end              = var.frontend-port-end
  backend_port                   = 22
  frontend_ip_configuration_name = "frontend-IP-configuration"
}

Any assistance would be very appreciated.

EDIT: I tried exporting the inbound_nat_rules export on the azurerm_lb frontend IP configuration, it gives a list of the resources which I do not currently know how to extract the ports from::

output "frontend-ip-confguration-inbound-nat-rules" {
  value = azurerm_lb.front-load-balancer.frontend_ip_configuration[*].inbound_nat_rules
}

Which results in this:

Changes to Outputs:
  + LB-frontend-IP-confguration-Inbound-nat-rules = [
      + [
          + "/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/weight-tracker-stage-rg/providers/Microsoft.Network/loadBalancers/front-load-balancer/inboundNatRules/lb-nat-pool.3",
          + "/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/weight-tracker-stage-rg/providers/Microsoft.Network/loadBalancers/front-load-balancer/inboundNatRules/lb-nat-pool.4",
          + "/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/weight-tracker-stage-rg/providers/Microsoft.Network/loadBalancers/front-load-balancer/inboundNatRules/lb-nat-pool.6",
        ],
    ]
stas L
  • 3
  • 2
  • 1
    Your question is not clear. What exactly do you want to do? Any example of your " data source or attribute reference"? – Marcin Mar 29 '22 at 00:17
  • I want to export/output the inbound NAT ports of the load balancer, The ones that are used with the load balancers public IP to for example SSH into scale set machines in the backend pool. – stas L Mar 29 '22 at 14:54

0 Answers0