diff --git a/azurestack/provider.go b/azurestack/provider.go index 22e7b8624..215b71c50 100644 --- a/azurestack/provider.go +++ b/azurestack/provider.go @@ -82,6 +82,7 @@ func Provider() terraform.ResourceProvider { "azurestack_network_security_rule": resourceArmNetworkSecurityRule(), "azurestack_local_network_gateway": resourceArmLocalNetworkGateway(), "azurestack_lb": resourceArmLoadBalancer(), + "azurestack_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), "azurestack_public_ip": resourceArmPublicIp(), "azurestack_resource_group": resourceArmResourceGroup(), "azurestack_storage_account": resourceArmStorageAccount(), diff --git a/azurestack/resource_arm_loadbalancer_backend_address_pool.go b/azurestack/resource_arm_loadbalancer_backend_address_pool.go new file mode 100644 index 000000000..0f168cf65 --- /dev/null +++ b/azurestack/resource_arm_loadbalancer_backend_address_pool.go @@ -0,0 +1,245 @@ +package azurestack + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2015-06-15/network" + "github.com/hashicorp/errwrap" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurestack/azurestack/utils" +) + +func resourceArmLoadBalancerBackendAddressPool() *schema.Resource { + return &schema.Resource{ + Create: resourceArmLoadBalancerBackendAddressPoolCreate, + Read: resourceArmLoadBalancerBackendAddressPoolRead, + Delete: resourceArmLoadBalancerBackendAddressPoolDelete, + Importer: &schema.ResourceImporter{ + State: loadBalancerSubResourceStateImporter, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "loadbalancer_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "backend_ip_configurations": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + }, + + "load_balancing_rules": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + }, + }, + } +} + +func resourceArmLoadBalancerBackendAddressPoolCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).loadBalancerClient + ctx := meta.(*ArmClient).StopContext + + loadBalancerID := d.Get("loadbalancer_id").(string) + armMutexKV.Lock(loadBalancerID) + defer armMutexKV.Unlock(loadBalancerID) + + loadBalancer, exists, err := retrieveLoadBalancerById(loadBalancerID, meta) + if err != nil { + return errwrap.Wrapf("Error Getting LoadBalancer By ID {{err}}", err) + } + if !exists { + d.SetId("") + log.Printf("[INFO] LoadBalancer %q not found. Removing from state", d.Get("name").(string)) + return nil + } + + backendAddressPools := append(*loadBalancer.LoadBalancerPropertiesFormat.BackendAddressPools, expandAzureRmLoadBalancerBackendAddressPools(d)) + existingPool, existingPoolIndex, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, d.Get("name").(string)) + if exists { + if d.Get("name").(string) == *existingPool.Name { + // this pool is being updated/reapplied remove old copy from the slice + backendAddressPools = append(backendAddressPools[:existingPoolIndex], backendAddressPools[existingPoolIndex+1:]...) + } + } + + loadBalancer.LoadBalancerPropertiesFormat.BackendAddressPools = &backendAddressPools + resGroup, loadBalancerName, err := resourceGroupAndLBNameFromId(d.Get("loadbalancer_id").(string)) + if err != nil { + return fmt.Errorf("Error parsing LoadBalancer Name and Group: %+v", err) + } + + future, err := client.CreateOrUpdate(ctx, resGroup, loadBalancerName, *loadBalancer) + if err != nil { + return fmt.Errorf("Error Creating/Updating LoadBalancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err) + } + + err = future.WaitForCompletion(ctx, client.Client) + if err != nil { + return fmt.Errorf("Error Creating/Updating LoadBalancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err) + } + + read, err := client.Get(ctx, resGroup, loadBalancerName, "") + if err != nil { + return fmt.Errorf("Error retrieving Load Balancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err) + } + if read.ID == nil { + return fmt.Errorf("Cannot read LoadBalancer %q (Resource Group %q) ID", loadBalancerName, resGroup) + } + + if read.LoadBalancerPropertiesFormat == nil { + return fmt.Errorf("Error creating LoadBalancer (%q Resource Group %q)", loadBalancerName, resGroup) + } + + var poolId string + for _, BackendAddressPool := range *(*read.LoadBalancerPropertiesFormat).BackendAddressPools { + if *BackendAddressPool.Name == d.Get("name").(string) { + poolId = *BackendAddressPool.ID + } + } + + if poolId == "" { + return fmt.Errorf("Cannot find created LoadBalancer Backend Address Pool ID %q", poolId) + } + + d.SetId(poolId) + + // TODO: is this still needed? + log.Printf("[DEBUG] Waiting for LoadBalancer (%s) to become available", loadBalancerName) + stateConf := &resource.StateChangeConf{ + Pending: []string{"Accepted", "Updating"}, + Target: []string{"Succeeded"}, + Refresh: loadbalancerStateRefreshFunc(ctx, client, resGroup, loadBalancerName), + Timeout: 10 * time.Minute, + } + if _, err := stateConf.WaitForState(); err != nil { + return fmt.Errorf("Error waiting for LoadBalancer (%q Resource Group %q) to become available: %+v", loadBalancerName, resGroup, err) + } + + return resourceArmLoadBalancerBackendAddressPoolRead(d, meta) +} + +func resourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, meta interface{}) error { + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + name := id.Path["backendAddressPools"] + + loadBalancer, exists, err := retrieveLoadBalancerById(d.Get("loadbalancer_id").(string), meta) + if err != nil { + return fmt.Errorf("Error retrieving Load Balancer by ID: %+v", err) + } + if !exists { + d.SetId("") + log.Printf("[INFO] LoadBalancer %q not found. Removing from state", name) + return nil + } + + config, _, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, name) + if !exists { + d.SetId("") + log.Printf("[INFO] LoadBalancer Backend Address Pool %q not found. Removing from state", name) + return nil + } + + d.Set("name", config.Name) + d.Set("resource_group_name", id.ResourceGroup) + + var backendIpConfigurations []string + var loadBalancingRules []string + + if props := config.BackendAddressPoolPropertiesFormat; props != nil { + if configs := props.BackendIPConfigurations; configs != nil { + for _, backendConfig := range *configs { + backendIpConfigurations = append(backendIpConfigurations, *backendConfig.ID) + } + } + + if rules := props.LoadBalancingRules; rules != nil { + for _, rule := range *rules { + loadBalancingRules = append(loadBalancingRules, *rule.ID) + } + } + } + + d.Set("backend_ip_configurations", backendIpConfigurations) + d.Set("load_balancing_rules", loadBalancingRules) + + return nil +} + +func resourceArmLoadBalancerBackendAddressPoolDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).loadBalancerClient + ctx := meta.(*ArmClient).StopContext + + loadBalancerID := d.Get("loadbalancer_id").(string) + armMutexKV.Lock(loadBalancerID) + defer armMutexKV.Unlock(loadBalancerID) + + loadBalancer, exists, err := retrieveLoadBalancerById(loadBalancerID, meta) + if err != nil { + return fmt.Errorf("Error retrieving Load Balancer by ID: %+v", err) + } + if !exists { + d.SetId("") + return nil + } + + _, index, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, d.Get("name").(string)) + if !exists { + return nil + } + + oldBackEndPools := *loadBalancer.LoadBalancerPropertiesFormat.BackendAddressPools + newBackEndPools := append(oldBackEndPools[:index], oldBackEndPools[index+1:]...) + loadBalancer.LoadBalancerPropertiesFormat.BackendAddressPools = &newBackEndPools + + resGroup, loadBalancerName, err := resourceGroupAndLBNameFromId(d.Get("loadbalancer_id").(string)) + if err != nil { + return errwrap.Wrapf("Error Getting LoadBalancer Name and Group: {{err}}", err) + } + + future, err := client.CreateOrUpdate(ctx, resGroup, loadBalancerName, *loadBalancer) + if err != nil { + return fmt.Errorf("Error Creating/Updating LoadBalancer: %+v", err) + } + + err = future.WaitForCompletion(ctx, client.Client) + if err != nil { + return fmt.Errorf("Error waiting for the completion for the LoadBalancer: %+v", err) + } + + read, err := client.Get(ctx, resGroup, loadBalancerName, "") + if err != nil { + return fmt.Errorf("Error retrieving the LoadBalancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err) + } + if read.ID == nil { + return fmt.Errorf("Cannot read LoadBalancer %q (resource group %q) ID", loadBalancerName, resGroup) + } + + return nil +} + +func expandAzureRmLoadBalancerBackendAddressPools(d *schema.ResourceData) network.BackendAddressPool { + return network.BackendAddressPool{ + Name: utils.String(d.Get("name").(string)), + } +} diff --git a/azurestack/resource_arm_loadbalancer_backend_address_pool_test.go b/azurestack/resource_arm_loadbalancer_backend_address_pool_test.go new file mode 100644 index 000000000..df0375167 --- /dev/null +++ b/azurestack/resource_arm_loadbalancer_backend_address_pool_test.go @@ -0,0 +1,240 @@ +package azurestack + +import ( + "fmt" + "os" + "testing" + + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2015-06-15/network" + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureStackLoadBalancerBackEndAddressPool_basic(t *testing.T) { + var lb network.LoadBalancer + ri := acctest.RandInt() + addressPoolName := fmt.Sprintf("%d-address-pool", ri) + + subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") + backendAddressPoolId := fmt.Sprintf( + "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/backendAddressPools/%s", + subscriptionID, ri, ri, addressPoolName) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureStackLoadBalancerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureStackLoadBalancerBackEndAddressPool_basic(ri, addressPoolName, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureStackLoadBalancerExists("azurestack_lb.test", &lb), + testCheckAzureStackLoadBalancerBackEndAddressPoolExists(addressPoolName, &lb), + resource.TestCheckResourceAttr( + "azurestack_lb_backend_address_pool.test", "id", backendAddressPoolId), + ), + }, + { + ResourceName: "azurestack_lb_backend_address_pool.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureStackLoadBalancerBackEndAddressPool_removal(t *testing.T) { + var lb network.LoadBalancer + ri := acctest.RandInt() + addressPoolName := fmt.Sprintf("%d-address-pool", ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureStackLoadBalancerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureStackLoadBalancerBackEndAddressPool_removal(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureStackLoadBalancerExists("azurestack_lb.test", &lb), + testCheckAzureStackLoadBalancerBackEndAddressPoolNotExists(addressPoolName, &lb), + ), + }, + }, + }) +} + +func TestAccAzureStackLoadBalancerBackEndAddressPool_reapply(t *testing.T) { + var lb network.LoadBalancer + ri := acctest.RandInt() + addressPoolName := fmt.Sprintf("%d-address-pool", ri) + + deleteAddressPoolState := func(s *terraform.State) error { + return s.Remove("azurestack_lb_backend_address_pool.test") + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureStackLoadBalancerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureStackLoadBalancerBackEndAddressPool_basic(ri, addressPoolName, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureStackLoadBalancerExists("azurestack_lb.test", &lb), + testCheckAzureStackLoadBalancerBackEndAddressPoolExists(addressPoolName, &lb), + deleteAddressPoolState, + ), + ExpectNonEmptyPlan: true, + }, + { + Config: testAccAzureStackLoadBalancerBackEndAddressPool_basic(ri, addressPoolName, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureStackLoadBalancerExists("azurestack_lb.test", &lb), + testCheckAzureStackLoadBalancerBackEndAddressPoolExists(addressPoolName, &lb), + ), + }, + }, + }) +} + +func TestAccAzureStackLoadBalancerBackEndAddressPool_disappears(t *testing.T) { + var lb network.LoadBalancer + ri := acctest.RandInt() + addressPoolName := fmt.Sprintf("%d-address-pool", ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureStackLoadBalancerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureStackLoadBalancerBackEndAddressPool_basic(ri, addressPoolName, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureStackLoadBalancerExists("azurestack_lb.test", &lb), + testCheckAzureStackLoadBalancerBackEndAddressPoolExists(addressPoolName, &lb), + testCheckAzureStackLoadBalancerBackEndAddressPoolDisappears(addressPoolName, &lb), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testCheckAzureStackLoadBalancerBackEndAddressPoolExists(addressPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc { + return func(s *terraform.State) error { + _, _, exists := findLoadBalancerBackEndAddressPoolByName(lb, addressPoolName) + if !exists { + return fmt.Errorf("A BackEnd Address Pool with name %q cannot be found.", addressPoolName) + } + + return nil + } +} + +func testCheckAzureStackLoadBalancerBackEndAddressPoolNotExists(addressPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc { + return func(s *terraform.State) error { + _, _, exists := findLoadBalancerBackEndAddressPoolByName(lb, addressPoolName) + if exists { + return fmt.Errorf("A BackEnd Address Pool with name %q has been found.", addressPoolName) + } + + return nil + } +} + +func testCheckAzureStackLoadBalancerBackEndAddressPoolDisappears(addressPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).loadBalancerClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + _, i, exists := findLoadBalancerBackEndAddressPoolByName(lb, addressPoolName) + if !exists { + return fmt.Errorf("A BackEnd Address Pool with name %q cannot be found.", addressPoolName) + } + + currentPools := *lb.LoadBalancerPropertiesFormat.BackendAddressPools + pools := append(currentPools[:i], currentPools[i+1:]...) + lb.LoadBalancerPropertiesFormat.BackendAddressPools = &pools + + id, err := parseAzureResourceID(*lb.ID) + if err != nil { + return err + } + + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, *lb.Name, *lb) + if err != nil { + return fmt.Errorf("Error Creating/Updating LoadBalancer %+v", err) + } + + err = future.WaitForCompletion(ctx, client.Client) + if err != nil { + return fmt.Errorf("Error Creating/Updating LoadBalancer %+v", err) + } + + _, err = client.Get(ctx, id.ResourceGroup, *lb.Name, "") + return err + } +} + +func testAccAzureStackLoadBalancerBackEndAddressPool_basic(rInt int, addressPoolName string, location string) string { + return fmt.Sprintf(` +resource "azurestack_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurestack_public_ip" "test" { + name = "test-ip-%d" + location = "${azurestack_resource_group.test.location}" + resource_group_name = "${azurestack_resource_group.test.name}" + public_ip_address_allocation = "static" +} + +resource "azurestack_lb" "test" { + name = "arm-test-loadbalancer-%d" + location = "${azurestack_resource_group.test.location}" + resource_group_name = "${azurestack_resource_group.test.name}" + + frontend_ip_configuration { + name = "one-%d" + public_ip_address_id = "${azurestack_public_ip.test.id}" + } +} + +resource "azurestack_lb_backend_address_pool" "test" { + resource_group_name = "${azurestack_resource_group.test.name}" + loadbalancer_id = "${azurestack_lb.test.id}" + name = "%s" +} + +`, rInt, location, rInt, rInt, rInt, addressPoolName) +} + +func testAccAzureStackLoadBalancerBackEndAddressPool_removal(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurestack_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurestack_public_ip" "test" { + name = "test-ip-%d" + location = "${azurestack_resource_group.test.location}" + resource_group_name = "${azurestack_resource_group.test.name}" + public_ip_address_allocation = "static" +} + +resource "azurestack_lb" "test" { + name = "arm-test-loadbalancer-%d" + location = "${azurestack_resource_group.test.location}" + resource_group_name = "${azurestack_resource_group.test.name}" + + frontend_ip_configuration { + name = "one-%d" + public_ip_address_id = "${azurestack_public_ip.test.id}" + } +} +`, rInt, location, rInt, rInt, rInt) +} diff --git a/azurestack/resource_arm_loadbalancer_test.go b/azurestack/resource_arm_loadbalancer_test.go index 8be5e1043..9ad9235c2 100644 --- a/azurestack/resource_arm_loadbalancer_test.go +++ b/azurestack/resource_arm_loadbalancer_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func TestResourceAzureRMLoadBalancerPrivateIpAddressAllocation_validation(t *testing.T) { +func TestResourceAzureStackLoadBalancerPrivateIpAddressAllocation_validation(t *testing.T) { cases := []struct { Value string ErrCount int @@ -47,45 +47,45 @@ func TestResourceAzureRMLoadBalancerPrivateIpAddressAllocation_validation(t *tes } } -func TestAccAzureRMLoadBalancer_basic(t *testing.T) { +func TestAccAzureStackLoadBalancer_basic(t *testing.T) { var lb network.LoadBalancer ri := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMLoadBalancerDestroy, + CheckDestroy: testCheckAzureStackLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_basic(ri, testLocation()), + Config: testAccAzureStackLoadBalancer_basic(ri, testLocation()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists("azurestack_lb.test", &lb), + testCheckAzureStackLoadBalancerExists("azurestack_lb.test", &lb), ), }, }, }) } -func TestAccAzureRMLoadBalancer_standard(t *testing.T) { +func TestAccAzureStackLoadBalancer_standard(t *testing.T) { var lb network.LoadBalancer ri := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMLoadBalancerDestroy, + CheckDestroy: testCheckAzureStackLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_standard(ri, testLocation()), + Config: testAccAzureStackLoadBalancer_standard(ri, testLocation()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists("azurestack_lb.test", &lb), + testCheckAzureStackLoadBalancerExists("azurestack_lb.test", &lb), ), }, }, }) } -func TestAccAzureRMLoadBalancer_frontEndConfig(t *testing.T) { +func TestAccAzureStackLoadBalancer_frontEndConfig(t *testing.T) { var lb network.LoadBalancer resourceName := "azurestack_lb.test" ri := acctest.RandInt() @@ -94,26 +94,26 @@ func TestAccAzureRMLoadBalancer_frontEndConfig(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMLoadBalancerDestroy, + CheckDestroy: testCheckAzureStackLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_frontEndConfig(ri, location), + Config: testAccAzureStackLoadBalancer_frontEndConfig(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), + testCheckAzureStackLoadBalancerExists(resourceName, &lb), resource.TestCheckResourceAttr(resourceName, "frontend_ip_configuration.#", "2"), ), }, { - Config: testAccAzureRMLoadBalancer_frontEndConfigRemovalWithIP(ri, location), + Config: testAccAzureStackLoadBalancer_frontEndConfigRemovalWithIP(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), + testCheckAzureStackLoadBalancerExists(resourceName, &lb), resource.TestCheckResourceAttr(resourceName, "frontend_ip_configuration.#", "1"), ), }, { - Config: testAccAzureRMLoadBalancer_frontEndConfigRemoval(ri, location), + Config: testAccAzureStackLoadBalancer_frontEndConfigRemoval(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), + testCheckAzureStackLoadBalancerExists(resourceName, &lb), resource.TestCheckResourceAttr(resourceName, "frontend_ip_configuration.#", "1"), ), }, @@ -121,7 +121,7 @@ func TestAccAzureRMLoadBalancer_frontEndConfig(t *testing.T) { }) } -func TestAccAzureRMLoadBalancer_tags(t *testing.T) { +func TestAccAzureStackLoadBalancer_tags(t *testing.T) { var lb network.LoadBalancer resourceName := "azurestack_lb.test" ri := acctest.RandInt() @@ -130,21 +130,21 @@ func TestAccAzureRMLoadBalancer_tags(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMLoadBalancerDestroy, + CheckDestroy: testCheckAzureStackLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_basic(ri, location), + Config: testAccAzureStackLoadBalancer_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), + testCheckAzureStackLoadBalancerExists(resourceName, &lb), resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), resource.TestCheckResourceAttr(resourceName, "tags.Environment", "production"), resource.TestCheckResourceAttr(resourceName, "tags.Purpose", "AcceptanceTests"), ), }, { - Config: testAccAzureRMLoadBalancer_updatedTags(ri, location), + Config: testAccAzureStackLoadBalancer_updatedTags(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), + testCheckAzureStackLoadBalancerExists(resourceName, &lb), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), resource.TestCheckResourceAttr(resourceName, "tags.Purpose", "AcceptanceTests"), ), @@ -153,7 +153,7 @@ func TestAccAzureRMLoadBalancer_tags(t *testing.T) { }) } -func testCheckAzureRMLoadBalancerExists(name string, lb *network.LoadBalancer) resource.TestCheckFunc { +func testCheckAzureStackLoadBalancerExists(name string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -184,7 +184,7 @@ func testCheckAzureRMLoadBalancerExists(name string, lb *network.LoadBalancer) r } } -func testCheckAzureRMLoadBalancerDestroy(s *terraform.State) error { +func testCheckAzureStackLoadBalancerDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*ArmClient).loadBalancerClient ctx := testAccProvider.Meta().(*ArmClient).StopContext @@ -210,7 +210,7 @@ func testCheckAzureRMLoadBalancerDestroy(s *terraform.State) error { return nil } -func testAccAzureRMLoadBalancer_basic(rInt int, location string) string { +func testAccAzureStackLoadBalancer_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurestack_resource_group" "test" { name = "acctestRG-%d" @@ -230,7 +230,7 @@ resource "azurestack_lb" "test" { }`, rInt, location, rInt) } -func testAccAzureRMLoadBalancer_standard(rInt int, location string) string { +func testAccAzureStackLoadBalancer_standard(rInt int, location string) string { return fmt.Sprintf(` resource "azurestack_resource_group" "test" { name = "acctestRG-%d" @@ -250,7 +250,7 @@ resource "azurestack_lb" "test" { }`, rInt, location, rInt) } -func testAccAzureRMLoadBalancer_updatedTags(rInt int, location string) string { +func testAccAzureStackLoadBalancer_updatedTags(rInt int, location string) string { return fmt.Sprintf(` resource "azurestack_resource_group" "test" { @@ -270,7 +270,7 @@ resource "azurestack_lb" "test" { }`, rInt, location, rInt) } -func testAccAzureRMLoadBalancer_frontEndConfig(rInt int, location string) string { +func testAccAzureStackLoadBalancer_frontEndConfig(rInt int, location string) string { return fmt.Sprintf(` resource "azurestack_resource_group" "test" { name = "acctestRG-%d" @@ -308,7 +308,7 @@ resource "azurestack_lb" "test" { }`, rInt, location, rInt, rInt, rInt, rInt, rInt) } -func testAccAzureRMLoadBalancer_frontEndConfig_withZone(rInt int, location string) string { +func testAccAzureStackLoadBalancer_frontEndConfig_withZone(rInt int, location string) string { return fmt.Sprintf(` resource "azurestack_resource_group" "test" { name = "acctestRG-%d" @@ -348,7 +348,7 @@ resource "azurestack_lb" "test" { }`, rInt, location, rInt, rInt, rInt, rInt, rInt) } -func testAccAzureRMLoadBalancer_frontEndConfigRemovalWithIP(rInt int, location string) string { +func testAccAzureStackLoadBalancer_frontEndConfigRemovalWithIP(rInt int, location string) string { return fmt.Sprintf(` resource "azurestack_resource_group" "test" { name = "acctestRG-%d" @@ -381,7 +381,7 @@ resource "azurestack_lb" "test" { }`, rInt, location, rInt, rInt, rInt, rInt) } -func testAccAzureRMLoadBalancer_frontEndConfigRemoval(rInt int, location string) string { +func testAccAzureStackLoadBalancer_frontEndConfigRemoval(rInt int, location string) string { return fmt.Sprintf(` resource "azurestack_resource_group" "test" { name = "acctestRG-%d" diff --git a/website/azurestack.erb b/website/azurestack.erb index c7dd229c7..584eb4066 100644 --- a/website/azurestack.erb +++ b/website/azurestack.erb @@ -148,6 +148,10 @@ azurestack_lb + > + azurestack_lb_backend_address_pool + + diff --git a/website/docs/r/loadbalancer_backend_address_pool.html.markdown b/website/docs/r/loadbalancer_backend_address_pool.html.markdown new file mode 100644 index 000000000..a678b8599 --- /dev/null +++ b/website/docs/r/loadbalancer_backend_address_pool.html.markdown @@ -0,0 +1,69 @@ +--- +layout: "azurestack" +page_title: "Azure Resource Manager: azurestack_lb_backend_address_pool" +sidebar_current: "docs-azurestack-resource-loadbalancer-backend-address-pool" +description: |- + Manages a LoadBalancer Backend Address Pool. +--- + +# azurestack_lb_backend_address_pool + +Manages a LoadBalancer Backend Address Pool. + +~> **NOTE:** When using this resource, the LoadBalancer needs to have a FrontEnd IP Configuration Attached + +## Example Usage + +```hcl +resource "azurestack_resource_group" "test" { + name = "LoadBalancerRG" + location = "West US" +} + +resource "azurestack_public_ip" "test" { + name = "PublicIPForLB" + location = "West US" + resource_group_name = "${azurestack_resource_group.test.name}" + public_ip_address_allocation = "static" +} + +resource "azurestack_lb" "test" { + name = "TestLoadBalancer" + location = "West US" + resource_group_name = "${azurestack_resource_group.test.name}" + + frontend_ip_configuration { + name = "PublicIPAddress" + public_ip_address_id = "${azurestack_public_ip.test.id}" + } +} + +resource "azurestack_lb_backend_address_pool" "test" { + resource_group_name = "${azurestack_resource_group.test.name}" + loadbalancer_id = "${azurestack_lb.test.id}" + name = "BackEndAddressPool" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Backend Address Pool. +* `resource_group_name` - (Required) The name of the resource group in which to create the resource. +* `loadbalancer_id` - (Required) The ID of the LoadBalancer in which to create the Backend Address Pool. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the LoadBalancer to which the resource is attached. + +## Import + +Load Balancer Backend Address Pools can be imported using the `resource id`, e.g. + +```shell +terraform import azurestack_lb_backend_address_pool.test /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/loadBalancers/lb1/backendAddressPools/pool1 +``` +