Skip to content

Commit

Permalink
Add tags and additional tests to the simple load balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
buzztroll committed May 9, 2016
1 parent cb22fb9 commit 5e68896
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 7 deletions.
5 changes: 5 additions & 0 deletions builtin/providers/azurerm/resource_arm_simple_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func resourceArmSimpleLb() *schema.Resource {
},
Set: resourceARMLoadBalancerRuleHash,
},
"tags": tagsSchema(),
},
}
}
Expand Down Expand Up @@ -387,12 +388,14 @@ func resourceArmSimpleLbCreate(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
location := d.Get("location").(string)
resGrp := d.Get("resource_group_name").(string)
tags := d.Get("tags").(map[string]interface{})

loadBalancer := network.LoadBalancer{
Name: &name,
Type: &typ,
Location: &location,
Properties: &network.LoadBalancerPropertiesFormat{},
Tags: expandTags(tags),
}

fipconfs, err := pullOutFrontEndIps(d)
Expand Down Expand Up @@ -603,6 +606,8 @@ func iResourceArmSimpleLbRead(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
flattenAndSetTags(d, loadBalancer.Tags)

return nil
}

Expand Down
140 changes: 133 additions & 7 deletions builtin/providers/azurerm/resource_arm_simple_lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,65 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func TestAccAzureSimpleLB_basic(t *testing.T) {
func TestAccARMSimpleLB_basic(t *testing.T) {

ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureSimpleLB_min, ri, ri)
config := fmt.Sprintf(testAccAzureSimpleLB_basic, ri, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureSimpleRMLBDestroy,
CheckDestroy: testCheckARMSimpleRMLBDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureSimpleLBExists("azurerm_simple_lb.test"),
testCheckARMSimpleLBExists("azurerm_simple_lb.test"),
),
},
},
})
}

func testCheckAzureSimpleLBExists(name string) resource.TestCheckFunc {
func TestAccARMSimpleLB_updateTage(t *testing.T) {

ri := acctest.RandInt()
preConfig := fmt.Sprintf(testAccAzureSimpleLB_tags, ri, ri)
postConfig := fmt.Sprintf(testAccAzureSimpleLB_updateTags, ri, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckARMSimpleRMLBDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckARMSimpleLBExists("azurerm_simple_lb.test"),
resource.TestCheckResourceAttr(
"azurerm_simple_lb.test", "tags.#", "2"),
resource.TestCheckResourceAttr(
"azurerm_simple_lb.test", "tags.environment", "Production"),
resource.TestCheckResourceAttr(
"azurerm_simple_lb.test", "tags.cost_center", "MSFT"),
),
},

resource.TestStep{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testCheckARMSimpleLBExists("azurerm_simple_lb.test"),
resource.TestCheckResourceAttr(
"azurerm_simple_lb.test", "tags.#", "1"),
resource.TestCheckResourceAttr(
"azurerm_simple_lb.test", "tags.environment", "staging"),
),
},
},
})
}

func testCheckARMSimpleLBExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
rs, ok := s.RootModule().Resources[name]
Expand Down Expand Up @@ -59,7 +97,7 @@ func testCheckAzureSimpleLBExists(name string) resource.TestCheckFunc {
}
}

func testCheckAzureSimpleRMLBDestroy(s *terraform.State) error {
func testCheckARMSimpleRMLBDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).loadBalancerClient

for _, rs := range s.RootModule().Resources {
Expand All @@ -84,7 +122,90 @@ func testCheckAzureSimpleRMLBDestroy(s *terraform.State) error {
return nil
}

var testAccAzureSimpleLB_min = `
var testAccAzureSimpleLB_basic = `
resource "azurerm_resource_group" "test" {
name = "acctestlbrg-%d"
location = "West US"
}
resource "azurerm_public_ip" "test" {
name = "simplelbip"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
}
resource "azurerm_simple_lb" "test" {
name = "acctestlb%d"
location = "West US"
type = "Microsoft.Network/loadBalancers"
resource_group_name = "${azurerm_resource_group.test.name}"
frontend_allocation_method = "Dynamic"
frontend_public_ip_address = "${azurerm_public_ip.test.id}"
probe {
name = "testProbe1"
protocol = "Tcp"
port = 22
interval = 5
number_of_probes = 16
}
rule {
protocol = "Tcp"
load_distribution = "Default"
frontend_port = 22
backend_port = 22
name = "rule1"
probe_name = "testProbe1"
}
}
`

var testAccAzureSimpleLB_tags = `
resource "azurerm_resource_group" "test" {
name = "acctestlbrg-%d"
location = "West US"
}
resource "azurerm_public_ip" "test" {
name = "simplelbip"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
}
resource "azurerm_simple_lb" "test" {
name = "acctestlb%d"
location = "West US"
type = "Microsoft.Network/loadBalancers"
resource_group_name = "${azurerm_resource_group.test.name}"
frontend_allocation_method = "Dynamic"
frontend_public_ip_address = "${azurerm_public_ip.test.id}"
probe {
name = "testProbe1"
protocol = "Tcp"
port = 22
interval = 5
number_of_probes = 16
}
rule {
protocol = "Tcp"
load_distribution = "Default"
frontend_port = 22
backend_port = 22
name = "rule1"
probe_name = "testProbe1"
}
tags {
environment = "Production"
cost_center = "MSFT"
}
}
`

var testAccAzureSimpleLB_updateTags = `
resource "azurerm_resource_group" "test" {
name = "acctestlbrg-%d"
location = "West US"
Expand Down Expand Up @@ -120,5 +241,10 @@ resource "azurerm_simple_lb" "test" {
name = "rule1"
probe_name = "testProbe1"
}
tags {
environment = "Production"
cost_center = "MSFT"
}
}
`

0 comments on commit 5e68896

Please sign in to comment.