Skip to content

Commit

Permalink
Merge pull request #638 from russellds/local_network_gateway_tags
Browse files Browse the repository at this point in the history
Fixes #637 - adds tags to azurerm_local_network_gateway
  • Loading branch information
tombuildsstuff authored Dec 18, 2017
2 parents 32c9910 + abdd33c commit 8bb42df
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions azurerm/resource_arm_local_network_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func resourceArmLocalNetworkGateway() *schema.Resource {
},
},
},

"tags": tagsSchema(),
},
}
}
Expand All @@ -85,6 +87,8 @@ func resourceArmLocalNetworkGatewayCreate(d *schema.ResourceData, meta interface
return err
}

tags := d.Get("tags").(map[string]interface{})

gateway := network.LocalNetworkGateway{
Name: &name,
Location: &location,
Expand All @@ -95,6 +99,7 @@ func resourceArmLocalNetworkGatewayCreate(d *schema.ResourceData, meta interface
GatewayIPAddress: &ipAddress,
BgpSettings: bgpSettings,
},
Tags: expandTags(tags),
}

_, createError := client.CreateOrUpdate(resGroup, name, gateway, make(chan struct{}))
Expand Down Expand Up @@ -154,6 +159,8 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}
}
}

flattenAndSetTags(d, resp.Tags)

return nil
}

Expand Down
43 changes: 43 additions & 0 deletions azurerm/resource_arm_local_network_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ func TestAccAzureRMLocalNetworkGateway_disappears(t *testing.T) {
})
}

func TestAccAzureRMLocalNetworkGateway_tags(t *testing.T) {
resourceName := "azurerm_local_network_gateway.test"

rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMLocalNetworkGatewayConfig_tags(rInt, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLocalNetworkGatewayExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.environment", "acctest"),
),
},
},
})
}

func TestAccAzureRMLocalNetworkGateway_bgpSettings(t *testing.T) {
name := "azurerm_local_network_gateway.test"
rInt := acctest.RandInt()
Expand Down Expand Up @@ -287,6 +308,28 @@ resource "azurerm_local_network_gateway" "test" {
`, rInt, location, rInt)
}

func testAccAzureRMLocalNetworkGatewayConfig_tags(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctest-%d"
location = "%s"
}
resource "azurerm_local_network_gateway" "test" {
name = "acctestlng-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
gateway_address = "127.0.0.1"
address_space = ["127.0.0.0/8"]
tags {
environment = "acctest"
}
}
`, rInt, location, rInt)
}

func testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/local_network_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The following arguments are supported:
* `bgp_settings` - (Optional) A `bgp_settings` block as defined below containing the
Local Network Gateway's BGP speaker settings.

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

---

`bgp_settings` supports the following:
Expand Down

0 comments on commit 8bb42df

Please sign in to comment.