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

azurerm_lb - fix zone behaviour bug introduced in recent API upgrade #12208

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -165,6 +165,36 @@ func TestAccAzureRMLoadBalancer_privateIP(t *testing.T) {
})
}

func TestAccAzureRMLoadBalancer_ZoneRedundant(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add one more test that takes a "1", "2" or "3"?

data := acceptance.BuildTestData(t, "azurerm_lb", "test")
r := LoadBalancer{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.availability_zone(data, "Zone-Redundant"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccAzureRMLoadBalancer_NoZone(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_lb", "test")
r := LoadBalancer{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.availability_zone(data, "No-Zone"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (r LoadBalancer) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
loadBalancerName := state.Attributes["name"]
resourceGroup := state.Attributes["resource_group_name"]
Expand Down Expand Up @@ -497,3 +527,46 @@ resource "azurerm_lb" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (r LoadBalancer) availability_zone(data acceptance.TestData, zone string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-lb-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefix = "10.0.2.0/24"
}

resource "azurerm_lb" "test" {
name = "acctestlb-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "Standard"

frontend_ip_configuration {
name = "Internal"
private_ip_address_allocation = "Static"
private_ip_address_version = "IPv4"
private_ip_address = "10.0.2.7"
subnet_id = azurerm_subnet.test.id
availability_zone = "%s"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, zone)
}
3 changes: 2 additions & 1 deletion website/docs/r/lb.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ The following arguments are supported:

* `name` - (Required) Specifies the name of the frontend ip configuration.
* `availability_zone` - (Optional) A list of Availability Zones which the Load Balancer's IP Addresses should be created in. Possible values are `Zone-Redundant`, `1`, `2`, `3`, and `No-Zone`. Defaults to `Zone-Redundant`.

`Zone-Redundant` will specify multiple zones in a region with Availability Zones and create a zone-redundant resource.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

-> **Please Note**: Availability Zones are only supported with a [Standard SKU](https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-standard-availability-zones) and [in select regions](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview) at this time. Standard SKU Load Balancer that do not specify a zone are zone redundant by default.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

* `subnet_id` - The ID of the Subnet which should be associated with the IP Configuration.
Expand Down