Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r\lb_outbound_rule Allow 0 for allocated_outbound_ports #16369

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ func TestAccAzureRMLoadBalancerOutboundRule_withPublicIPPrefix(t *testing.T) {
})
}

func TestAccAzureRMLoadBalancerOutboundRule_allocatedOutboundPorts(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_lb_outbound_rule", "test")
r := LoadBalancerOutboundRule{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.allocatedOutboundPortsDefault(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.allocatedOutboundPortsUpdated(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (r LoadBalancerOutboundRule) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.LoadBalancerOutboundRuleID(state.ID)
if err != nil {
Expand Down Expand Up @@ -450,3 +472,103 @@ resource "azurerm_lb_outbound_rule" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, rg, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (r LoadBalancerOutboundRule) allocatedOutboundPortsDefault(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_public_ip" "test" {
name = "test-ip-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_lb" "test" {
name = "arm-test-loadbalancer-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Standard"
frontend_ip_configuration {
name = "one-%d"
public_ip_address_id = azurerm_public_ip.test.id
}
}
resource "azurerm_lb_backend_address_pool" "test" {
loadbalancer_id = azurerm_lb.test.id
name = "be-%d"
}
resource "azurerm_lb_outbound_rule" "test" {
loadbalancer_id = azurerm_lb.test.id
name = "OutboundRule-%d"
backend_address_pool_id = azurerm_lb_backend_address_pool.test.id
protocol = "All"
frontend_ip_configuration {
name = "one-%d"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (r LoadBalancerOutboundRule) allocatedOutboundPortsUpdated(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_public_ip" "test" {
name = "test-ip-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_lb" "test" {
name = "arm-test-loadbalancer-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Standard"
frontend_ip_configuration {
name = "one-%d"
public_ip_address_id = azurerm_public_ip.test.id
}
}
resource "azurerm_lb_backend_address_pool" "test" {
loadbalancer_id = azurerm_lb.test.id
name = "be-%d"
}
resource "azurerm_lb_outbound_rule" "test" {
loadbalancer_id = azurerm_lb.test.id
name = "OutboundRule-%d"
backend_address_pool_id = azurerm_lb_backend_address_pool.test.id
protocol = "All"
allocated_outbound_ports = 0
frontend_ip_configuration {
name = "one-%d"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
14 changes: 6 additions & 8 deletions internal/services/loadbalancer/outbound_rule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ func resourceArmLoadBalancerOutboundRule() *pluginsdk.Resource {
},

"allocated_outbound_ports": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 1024,
Type: pluginsdk.TypeInt,
Optional: true,
Default: 1024,
ValidateFunc: validation.IntAtLeast(0),
},

"idle_timeout_in_minutes": {
Expand Down Expand Up @@ -304,7 +305,8 @@ func resourceArmLoadBalancerOutboundRuleDelete(d *pluginsdk.ResourceData, meta i

func expandAzureRmLoadBalancerOutboundRule(d *pluginsdk.ResourceData, lb *network.LoadBalancer) (*network.OutboundRule, error) {
properties := network.OutboundRulePropertiesFormat{
Protocol: network.LoadBalancerOutboundRuleProtocol(d.Get("protocol").(string)),
Protocol: network.LoadBalancerOutboundRuleProtocol(d.Get("protocol").(string)),
AllocatedOutboundPorts: utils.Int32(int32(d.Get("allocated_outbound_ports").(int))),
}

feConfigs := d.Get("frontend_ip_configuration").([]interface{})
Expand Down Expand Up @@ -340,10 +342,6 @@ func expandAzureRmLoadBalancerOutboundRule(d *pluginsdk.ResourceData, lb *networ
properties.EnableTCPReset = utils.Bool(v.(bool))
}

if v, ok := d.GetOk("allocated_outbound_ports"); ok {
properties.AllocatedOutboundPorts = utils.Int32(int32(v.(int)))
}

return &network.OutboundRule{
Name: utils.String(d.Get("name").(string)),
OutboundRulePropertiesFormat: &properties,
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/lb_outbound_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The following arguments are supported:
* `backend_address_pool_id` - (Required) The ID of the Backend Address Pool. Outbound traffic is randomly load balanced across IPs in the backend IPs.
* `protocol` - (Required) The transport protocol for the external endpoint. Possible values are `Udp`, `Tcp` or `All`.
* `enable_tcp_reset` - (Optional) Receive bidirectional TCP Reset on TCP flow idle timeout or unexpected connection termination. This element is only used when the protocol is set to TCP.
* `allocated_outbound_ports` - (Optional) The number of outbound ports to be used for NAT.
* `allocated_outbound_ports` - (Optional) The number of outbound ports to be used for NAT. Defaults to `1024`.
* `idle_timeout_in_minutes` - (Optional) The timeout for the TCP idle connection

---
Expand Down