Skip to content

Commit

Permalink
Merge pull request #665 from justaugustus/add-lb-standard
Browse files Browse the repository at this point in the history
Add support for Azure LB Standard and Public IP Standard
  • Loading branch information
tombuildsstuff authored Jan 26, 2018
2 parents 79ba59a + b82e64f commit b863434
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 5 deletions.
21 changes: 21 additions & 0 deletions azurerm/resource_arm_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -100,6 +101,18 @@ func resourceArmLoadBalancer() *schema.Resource {
},
},

"sku": {
Type: schema.TypeString,
Optional: true,
Default: string(network.LoadBalancerSkuNameBasic),
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.LoadBalancerSkuNameBasic),
string(network.LoadBalancerSkuNameStandard),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"tags": tagsSchema(),
},
}
Expand All @@ -114,6 +127,9 @@ func resourceArmLoadBalancerCreate(d *schema.ResourceData, meta interface{}) err
name := d.Get("name").(string)
location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string)
sku := network.LoadBalancerSku{
Name: network.LoadBalancerSkuName(d.Get("sku").(string)),
}
tags := d.Get("tags").(map[string]interface{})
expandedTags := expandTags(tags)

Expand All @@ -127,6 +143,7 @@ func resourceArmLoadBalancerCreate(d *schema.ResourceData, meta interface{}) err
Name: utils.String(name),
Location: utils.String(location),
Tags: expandedTags,
Sku: &sku,
LoadBalancerPropertiesFormat: &properties,
}

Expand Down Expand Up @@ -188,6 +205,10 @@ func resourecArmLoadBalancerRead(d *schema.ResourceData, meta interface{}) error
d.Set("location", azureRMNormalizeLocation(*location))
}

if sku := loadBalancer.Sku; sku != nil {
d.Set("sku", string(sku.Name))
}

if props := loadBalancer.LoadBalancerPropertiesFormat; props != nil {
if feipConfigs := props.FrontendIPConfigurations; feipConfigs != nil {
d.Set("frontend_ip_configuration", flattenLoadBalancerFrontendIpConfiguration(feipConfigs))
Expand Down
40 changes: 40 additions & 0 deletions azurerm/resource_arm_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ func TestAccAzureRMLoadBalancer_basic(t *testing.T) {
})
}

func TestAccAzureRMLoadBalancer_standard(t *testing.T) {
var lb network.LoadBalancer
ri := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMLoadBalancer_standard(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
),
},
},
})
}

func TestAccAzureRMLoadBalancer_frontEndConfig(t *testing.T) {
var lb network.LoadBalancer
resourceName := "azurerm_lb.test"
Expand Down Expand Up @@ -211,6 +230,27 @@ resource "azurerm_lb" "test" {
}`, rInt, location, rInt)
}

func testAccAzureRMLoadBalancer_standard(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestrg-%d"
location = "%s"
}
resource "azurerm_lb" "test" {
name = "acctest-loadbalancer-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
tags {
Environment = "production"
Purpose = "AcceptanceTests"
}
}`, rInt, location, rInt)
}

func testAccAzureRMLoadBalancer_updatedTags(rInt int, location string) string {
return fmt.Sprintf(`
Expand Down
39 changes: 35 additions & 4 deletions azurerm/resource_arm_public_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -84,6 +85,18 @@ func resourceArmPublicIp() *schema.Resource {
Computed: true,
},

"sku": {
Type: schema.TypeString,
Optional: true,
Default: string(network.PublicIPAddressSkuNameBasic),
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.PublicIPAddressSkuNameBasic),
string(network.PublicIPAddressSkuNameStandard),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"tags": tagsSchema(),
},
}
Expand All @@ -98,10 +111,21 @@ func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string)
sku := network.PublicIPAddressSku{
Name: network.PublicIPAddressSkuName(d.Get("sku").(string)),
}
tags := d.Get("tags").(map[string]interface{})

ipAllocationMethod := network.IPAllocationMethod(d.Get("public_ip_address_allocation").(string))

if strings.ToLower(string(sku.Name)) == "standard" {
if strings.ToLower(string(ipAllocationMethod)) != "static" {
return fmt.Errorf("Static IP allocation must be used when creating Standard SKU public IP addresses.")
}
}

properties := network.PublicIPAddressPropertiesFormat{
PublicIPAllocationMethod: network.IPAllocationMethod(d.Get("public_ip_address_allocation").(string)),
PublicIPAllocationMethod: ipAllocationMethod,
}

dnl, hasDnl := d.GetOk("domain_name_label")
Expand Down Expand Up @@ -129,8 +153,9 @@ func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
}

publicIp := network.PublicIPAddress{
Name: &name,
Location: &location,
Name: &name,
Location: &location,
Sku: &sku,
PublicIPAddressPropertiesFormat: &properties,
Tags: expandTags(tags),
}
Expand Down Expand Up @@ -185,6 +210,12 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
d.Set("location", azureRMNormalizeLocation(*location))
}

d.Set("public_ip_address_allocation", strings.ToLower(string(resp.PublicIPAddressPropertiesFormat.PublicIPAllocationMethod)))

if sku := resp.Sku; sku != nil {
d.Set("sku", string(sku.Name))
}

if props := resp.PublicIPAddressPropertiesFormat; props != nil {
d.Set("public_ip_address_allocation", strings.ToLower(string(props.PublicIPAllocationMethod)))

Expand Down Expand Up @@ -236,7 +267,7 @@ func validatePublicIpAllocation(v interface{}, k string) (ws []string, errors []
}

if !allocations[value] {
errors = append(errors, fmt.Errorf("Public IP Allocation can only be Static of Dynamic"))
errors = append(errors, fmt.Errorf("Public IP Allocation must be an accepted value: Static, Dynamic"))
}
return
}
Expand Down
37 changes: 37 additions & 0 deletions azurerm/resource_arm_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ func TestAccAzureRMPublicIpStatic_basic(t *testing.T) {
})
}

func TestAccAzureRMPublicIpStatic_standard(t *testing.T) {

ri := acctest.RandInt()
config := testAccAzureRMPublicIPStatic_standard(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPublicIpDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
),
},
},
})
}

func TestAccAzureRMPublicIpStatic_disappears(t *testing.T) {
resourceName := "azurerm_public_ip.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -324,6 +344,23 @@ resource "azurerm_public_ip" "test" {
`, rInt, location, rInt)
}

func testAccAzureRMPublicIPStatic_standard(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_public_ip" "test" {
name = "acctestpublicip-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
sku = "standard"
}
`, rInt, location, rInt)
}

func testAccAzureRMPublicIPStatic_update(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/loadbalancer.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ The following arguments are supported:
* `resource_group_name` - (Required) The name of the resource group in which to create the LoadBalancer.
* `location` - (Required) Specifies the supported Azure location where the resource exists.
* `frontend_ip_configuration` - (Optional) A frontend ip configuration block as documented below.
* `sku` - (Optional) The SKU of the Azure Load Balancer. Accepted values are `Basic` and `Standard`. Defaults to `Basic`.

-> **Note:** The `Standard` SKU is currently in Public Preview on an opt-in basis. [More information, including how you can register for the Preview, and which regions `Standard` SKU's are available in are available here](https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-standard-overview)

* `tags` - (Optional) A mapping of tags to assign to the resource.

`frontend_ip_configuration` supports the following:
Expand Down
8 changes: 7 additions & 1 deletion website/docs/r/public_ip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ The following arguments are supported:

* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.

* `public_ip_address_allocation` - (Required) Defines whether the IP address is stable or dynamic. Options are Static or Dynamic.
* `sku` - (Optional) The SKU of the Public IP. Accepted values are `Basic` and `Standard`. Defaults to `Basic`.

-> **Note** Public IP Standard SKUs require `public_ip_address_allocation` to be set to `static`.

-> **Note:** The `Standard` SKU is currently in Public Preview on an opt-in basis. [More information, including how you can register for the Preview, and which regions `Standard` SKU's are available in are available here](https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-standard-overview)

* `public_ip_address_allocation` - (Required) Defines whether the IP address is static or dynamic. Options are Static or Dynamic.

~> **Note** `Dynamic` Public IP Addresses aren't allocated until they're assigned to a resource (such as a Virtual Machine or a Load Balancer) by design within Azure - [more information is available below](#ip_address).

Expand Down

0 comments on commit b863434

Please sign in to comment.