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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade load balancer API to 2020-05-01 #10263

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
10 changes: 5 additions & 5 deletions azurerm/internal/services/loadbalancer/client/client.go
@@ -1,20 +1,20 @@
package client

import (
networkLegacy "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
LoadBalancersClient *networkLegacy.LoadBalancersClient
LoadBalancingRulesClient *networkLegacy.LoadBalancerLoadBalancingRulesClient
LoadBalancersClient *network.LoadBalancersClient
LoadBalancingRulesClient *network.LoadBalancerLoadBalancingRulesClient
}

func NewClient(o *common.ClientOptions) *Client {
loadBalancersClient := networkLegacy.NewLoadBalancersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
loadBalancersClient := network.NewLoadBalancersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&loadBalancersClient.Client, o.ResourceManagerAuthorizer)

loadBalancingRulesClient := networkLegacy.NewLoadBalancerLoadBalancingRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
loadBalancingRulesClient := network.NewLoadBalancerLoadBalancingRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&loadBalancingRulesClient.Client, o.ResourceManagerAuthorizer)

return &Client{
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/loadbalancer/loadbalancer.go
@@ -1,7 +1,7 @@
package loadbalancer

import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loadbalancer/parse"
)
Expand Down
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
Expand Down
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
Expand Down
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
Expand Down
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
Expand Up @@ -5,7 +5,9 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
Expand Down Expand Up @@ -155,6 +157,32 @@ func TestAccAzureRMLoadBalancerRule_updateMultipleRules(t *testing.T) {
})
}

func TestAccAzureRMLoadBalancerRule_vmssBackendPoolUpdateRemoveLBRule(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_lb_rule", "test")
lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha))
r := LoadBalancerRule{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.vmssBackendPool(data, lbRuleName, "Standard"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.vmssBackendPoolUpdate(data, lbRuleName, "Standard"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.vmssBackendPoolWithoutLBRule(data, "Standard"),
},
})
}

func (r LoadBalancerRule) Exists(ctx context.Context, client *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.LoadBalancingRuleID(state.ID)
if err != nil {
Expand Down Expand Up @@ -387,3 +415,112 @@ resource "azurerm_lb_rule" "test2" {
}
`, template, data.RandomStringOfLength(8), data2.RandomStringOfLength(8))
}

func (r LoadBalancerRule) vmssBackendPoolWithoutLBRule(data acceptance.TestData, sku string) string {
template := r.template(data, sku)
return fmt.Sprintf(`
%[1]s

resource "azurerm_lb_backend_address_pool" "test" {
name = "acctest-lb-BAP-%[2]d"
resource_group_name = azurerm_resource_group.test.name
loadbalancer_id = azurerm_lb.test.id
}

resource "azurerm_virtual_network" "test" {
name = "acctest-lb-vnet-%[2]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 = "acctest-lb-subnet-%[2]d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.1.0/24"]
}

resource "azurerm_virtual_machine_scale_set" "hbtest" {
magodo marked this conversation as resolved.
Show resolved Hide resolved
name = "acctest-lb-vmss-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
upgrade_policy_mode = "Automatic"
overprovision = false
single_placement_group = true
sku {
name = "Standard_B2ms"
tier = "Standard"
capacity = 3
}
storage_profile_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-datacenter-core-smalldisk-g2"
version = "latest"
}
storage_profile_os_disk {
create_option = "FromImage"
caching = "ReadWrite"
managed_disk_type = "Premium_LRS"
}
os_profile {
computer_name_prefix = "testvm"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
os_profile_windows_config {
provision_vm_agent = true
enable_automatic_upgrades = false
}
network_profile {
name = "primary"
primary = true
ip_configuration {
name = "primary"
primary = true
subnet_id = azurerm_subnet.test.id
load_balancer_backend_address_pool_ids = [
azurerm_lb_backend_address_pool.test.id
]
}
}
}
`, template, data.RandomInteger)
}

func (r LoadBalancerRule) vmssBackendPool(data acceptance.TestData, lbRuleName, sku string) string {
template := r.vmssBackendPoolWithoutLBRule(data, sku)
return fmt.Sprintf(`
%s

resource "azurerm_lb_rule" "test" {
resource_group_name = azurerm_resource_group.test.name
loadbalancer_id = azurerm_lb.test.id
name = "%s"
protocol = "Tcp"
frontend_port = 3389
backend_port = 3389
backend_address_pool_id = azurerm_lb_backend_address_pool.test.id
frontend_ip_configuration_name = azurerm_lb.test.frontend_ip_configuration.0.name
}
`, template, lbRuleName)
}

func (r LoadBalancerRule) vmssBackendPoolUpdate(data acceptance.TestData, lbRuleName, sku string) string {
template := r.vmssBackendPoolWithoutLBRule(data, sku)
return fmt.Sprintf(`
%s
resource "azurerm_lb_rule" "test" {
resource_group_name = azurerm_resource_group.test.name
loadbalancer_id = azurerm_lb.test.id
name = "%s"
protocol = "Tcp"
frontend_port = 3389
backend_port = 3389
backend_address_pool_id = azurerm_lb_backend_address_pool.test.id
frontend_ip_configuration_name = azurerm_lb.test.frontend_ip_configuration.0.name
disable_outbound_snat = false
}
`, template, lbRuleName)
}
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/loadbalancer/probe_resource.go
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/loadbalancer/rule_resource.go
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-03-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down