Skip to content

Commit 2ebe2c0

Browse files
committed
Add acceptance tests and docs update to allow the tagging of AzureRM resource &
1 parent 14344d0 commit 2ebe2c0

4 files changed

Lines changed: 148 additions & 0 deletions

File tree

builtin/providers/azurerm/resource_arm_resource_group_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,39 @@ func TestAccAzureRMResourceGroup_basic(t *testing.T) {
2525
})
2626
}
2727

28+
func TestAccAzureRMResourceGroup_withTags(t *testing.T) {
29+
resource.Test(t, resource.TestCase{
30+
PreCheck: func() { testAccPreCheck(t) },
31+
Providers: testAccProviders,
32+
CheckDestroy: testCheckAzureRMResourceGroupDestroy,
33+
Steps: []resource.TestStep{
34+
resource.TestStep{
35+
Config: testAccAzureRMResourceGroup_withTags,
36+
Check: resource.ComposeTestCheckFunc(
37+
testCheckAzureRMResourceGroupExists("azurerm_resource_group.test"),
38+
resource.TestCheckResourceAttr(
39+
"azurerm_resource_group.test", "tags.#", "2"),
40+
resource.TestCheckResourceAttr(
41+
"azurerm_resource_group.test", "tags.environment", "Production"),
42+
resource.TestCheckResourceAttr(
43+
"azurerm_resource_group.test", "tags.cost_center", "MSFT"),
44+
),
45+
},
46+
47+
resource.TestStep{
48+
Config: testAccAzureRMResourceGroup_withTagsUpdated,
49+
Check: resource.ComposeTestCheckFunc(
50+
testCheckAzureRMResourceGroupExists("azurerm_resource_group.test"),
51+
resource.TestCheckResourceAttr(
52+
"azurerm_resource_group.test", "tags.#", "1"),
53+
resource.TestCheckResourceAttr(
54+
"azurerm_resource_group.test", "tags.environment", "staging"),
55+
),
56+
},
57+
},
58+
})
59+
}
60+
2861
func testCheckAzureRMResourceGroupExists(name string) resource.TestCheckFunc {
2962
return func(s *terraform.State) error {
3063
// Ensure we have enough information in state to look up in API
@@ -80,3 +113,26 @@ resource "azurerm_resource_group" "test" {
80113
location = "West US"
81114
}
82115
`
116+
117+
var testAccAzureRMResourceGroup_withTags = `
118+
resource "azurerm_resource_group" "test" {
119+
name = "acceptanceTestResourceGroup1_basic"
120+
location = "West US"
121+
122+
tags {
123+
environment = "Production"
124+
cost_center = "MSFT"
125+
}
126+
}
127+
`
128+
129+
var testAccAzureRMResourceGroup_withTagsUpdated = `
130+
resource "azurerm_resource_group" "test" {
131+
name = "acceptanceTestResourceGroup1_basic"
132+
location = "West US"
133+
134+
tags {
135+
environment = "staging"
136+
}
137+
}
138+
`

builtin/providers/azurerm/resource_arm_virtual_network_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,39 @@ func TestAccAzureRMVirtualNetwork_basic(t *testing.T) {
2525
})
2626
}
2727

28+
func TestAccAzureRMVirtualNetwork_withTags(t *testing.T) {
29+
resource.Test(t, resource.TestCase{
30+
PreCheck: func() { testAccPreCheck(t) },
31+
Providers: testAccProviders,
32+
CheckDestroy: testCheckAzureRMVirtualNetworkDestroy,
33+
Steps: []resource.TestStep{
34+
resource.TestStep{
35+
Config: testAccAzureRMVirtualNetwork_withTags,
36+
Check: resource.ComposeTestCheckFunc(
37+
testCheckAzureRMVirtualNetworkExists("azurerm_virtual_network.test"),
38+
resource.TestCheckResourceAttr(
39+
"azurerm_virtual_network.test", "tags.#", "2"),
40+
resource.TestCheckResourceAttr(
41+
"azurerm_virtual_network.test", "tags.environment", "Production"),
42+
resource.TestCheckResourceAttr(
43+
"azurerm_virtual_network.test", "tags.cost_center", "MSFT"),
44+
),
45+
},
46+
47+
resource.TestStep{
48+
Config: testAccAzureRMVirtualNetwork_withTagsUpdated,
49+
Check: resource.ComposeTestCheckFunc(
50+
testCheckAzureRMVirtualNetworkExists("azurerm_virtual_network.test"),
51+
resource.TestCheckResourceAttr(
52+
"azurerm_virtual_network.test", "tags.#", "1"),
53+
resource.TestCheckResourceAttr(
54+
"azurerm_virtual_network.test", "tags.environment", "staging"),
55+
),
56+
},
57+
},
58+
})
59+
}
60+
2861
func testCheckAzureRMVirtualNetworkExists(name string) resource.TestCheckFunc {
2962
return func(s *terraform.State) error {
3063
// Ensure we have enough information in state to look up in API
@@ -98,3 +131,50 @@ resource "azurerm_virtual_network" "test" {
98131
}
99132
}
100133
`
134+
135+
var testAccAzureRMVirtualNetwork_withTags = `
136+
resource "azurerm_resource_group" "test" {
137+
name = "acceptanceTestResourceGroup1"
138+
location = "West US"
139+
}
140+
141+
resource "azurerm_virtual_network" "test" {
142+
name = "acceptanceTestVirtualNetwork1"
143+
address_space = ["10.0.0.0/16"]
144+
location = "West US"
145+
resource_group_name = "${azurerm_resource_group.test.name}"
146+
147+
subnet {
148+
name = "subnet1"
149+
address_prefix = "10.0.1.0/24"
150+
}
151+
152+
tags {
153+
environment = "Production"
154+
cost_center = "MSFT"
155+
}
156+
}
157+
`
158+
159+
var testAccAzureRMVirtualNetwork_withTagsUpdated = `
160+
resource "azurerm_resource_group" "test" {
161+
name = "acceptanceTestResourceGroup1"
162+
location = "West US"
163+
}
164+
165+
resource "azurerm_virtual_network" "test" {
166+
name = "acceptanceTestVirtualNetwork1"
167+
address_space = ["10.0.0.0/16"]
168+
location = "West US"
169+
resource_group_name = "${azurerm_resource_group.test.name}"
170+
171+
subnet {
172+
name = "subnet1"
173+
address_prefix = "10.0.1.0/24"
174+
}
175+
176+
tags {
177+
environment = "staging"
178+
}
179+
}
180+
`

website/source/docs/providers/azurerm/r/resource_group.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Creates a new resource group on Azure.
1616
resource "azurerm_resource_group" "test" {
1717
name = "testResourceGroup1"
1818
location = "West US"
19+
20+
tags {
21+
environment = "Production"
22+
}
1923
}
2024
```
2125

@@ -28,6 +32,8 @@ The following arguments are supported:
2832

2933
* `location` - (Required) The location where the resource group should be created.
3034
For a list of all Azure locations, please consult [this link](http://azure.microsoft.com/en-us/regions/).
35+
36+
* `tags` - (Optional) A mapping of tags to assign to the resource.
3137

3238
## Attributes Reference
3339

website/source/docs/providers/azurerm/r/virtual_network.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ resource "azurerm_virtual_network" "test" {
3434
name = "subnet3"
3535
address_prefix = "10.0.3.0/24"
3636
}
37+
38+
tags {
39+
environment = "Production"
40+
}
3741
}
3842
```
3943

@@ -60,6 +64,8 @@ The following arguments are supported:
6064
* `subnet` - (Optional) Can be specified multiple times to define multiple
6165
subnets. Each `subnet` block supports fields documented below.
6266

67+
* `tags` - (Optional) A mapping of tags to assign to the resource.
68+
6369
The `subnet` block supports:
6470

6571
* `name` - (Required) The name of the subnet.

0 commit comments

Comments
 (0)