Merge pull request #4720 from stack72/azurerm-tagging-acceptance-tests

Add acceptance tests and docs update to allow the tagging of AzureRM …
This commit is contained in:
James Nugent 2016-01-18 13:59:51 -05:00
commit c23d6d63b3
4 changed files with 148 additions and 0 deletions

View File

@ -25,6 +25,39 @@ func TestAccAzureRMResourceGroup_basic(t *testing.T) {
}) })
} }
func TestAccAzureRMResourceGroup_withTags(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMResourceGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAzureRMResourceGroup_withTags,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMResourceGroupExists("azurerm_resource_group.test"),
resource.TestCheckResourceAttr(
"azurerm_resource_group.test", "tags.#", "2"),
resource.TestCheckResourceAttr(
"azurerm_resource_group.test", "tags.environment", "Production"),
resource.TestCheckResourceAttr(
"azurerm_resource_group.test", "tags.cost_center", "MSFT"),
),
},
resource.TestStep{
Config: testAccAzureRMResourceGroup_withTagsUpdated,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMResourceGroupExists("azurerm_resource_group.test"),
resource.TestCheckResourceAttr(
"azurerm_resource_group.test", "tags.#", "1"),
resource.TestCheckResourceAttr(
"azurerm_resource_group.test", "tags.environment", "staging"),
),
},
},
})
}
func testCheckAzureRMResourceGroupExists(name string) resource.TestCheckFunc { func testCheckAzureRMResourceGroupExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API // Ensure we have enough information in state to look up in API
@ -80,3 +113,26 @@ resource "azurerm_resource_group" "test" {
location = "West US" location = "West US"
} }
` `
var testAccAzureRMResourceGroup_withTags = `
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1_basic"
location = "West US"
tags {
environment = "Production"
cost_center = "MSFT"
}
}
`
var testAccAzureRMResourceGroup_withTagsUpdated = `
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1_basic"
location = "West US"
tags {
environment = "staging"
}
}
`

View File

@ -25,6 +25,39 @@ func TestAccAzureRMVirtualNetwork_basic(t *testing.T) {
}) })
} }
func TestAccAzureRMVirtualNetwork_withTags(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualNetworkDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAzureRMVirtualNetwork_withTags,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualNetworkExists("azurerm_virtual_network.test"),
resource.TestCheckResourceAttr(
"azurerm_virtual_network.test", "tags.#", "2"),
resource.TestCheckResourceAttr(
"azurerm_virtual_network.test", "tags.environment", "Production"),
resource.TestCheckResourceAttr(
"azurerm_virtual_network.test", "tags.cost_center", "MSFT"),
),
},
resource.TestStep{
Config: testAccAzureRMVirtualNetwork_withTagsUpdated,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualNetworkExists("azurerm_virtual_network.test"),
resource.TestCheckResourceAttr(
"azurerm_virtual_network.test", "tags.#", "1"),
resource.TestCheckResourceAttr(
"azurerm_virtual_network.test", "tags.environment", "staging"),
),
},
},
})
}
func testCheckAzureRMVirtualNetworkExists(name string) resource.TestCheckFunc { func testCheckAzureRMVirtualNetworkExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API // Ensure we have enough information in state to look up in API
@ -98,3 +131,50 @@ resource "azurerm_virtual_network" "test" {
} }
} }
` `
var testAccAzureRMVirtualNetwork_withTags = `
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1"
location = "West US"
}
resource "azurerm_virtual_network" "test" {
name = "acceptanceTestVirtualNetwork1"
address_space = ["10.0.0.0/16"]
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
subnet {
name = "subnet1"
address_prefix = "10.0.1.0/24"
}
tags {
environment = "Production"
cost_center = "MSFT"
}
}
`
var testAccAzureRMVirtualNetwork_withTagsUpdated = `
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1"
location = "West US"
}
resource "azurerm_virtual_network" "test" {
name = "acceptanceTestVirtualNetwork1"
address_space = ["10.0.0.0/16"]
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
subnet {
name = "subnet1"
address_prefix = "10.0.1.0/24"
}
tags {
environment = "staging"
}
}
`

View File

@ -16,6 +16,10 @@ Creates a new resource group on Azure.
resource "azurerm_resource_group" "test" { resource "azurerm_resource_group" "test" {
name = "testResourceGroup1" name = "testResourceGroup1"
location = "West US" location = "West US"
tags {
environment = "Production"
}
} }
``` ```
@ -28,6 +32,8 @@ The following arguments are supported:
* `location` - (Required) The location where the resource group should be created. * `location` - (Required) The location where the resource group should be created.
For a list of all Azure locations, please consult [this link](http://azure.microsoft.com/en-us/regions/). For a list of all Azure locations, please consult [this link](http://azure.microsoft.com/en-us/regions/).
* `tags` - (Optional) A mapping of tags to assign to the resource.
## Attributes Reference ## Attributes Reference

View File

@ -34,6 +34,10 @@ resource "azurerm_virtual_network" "test" {
name = "subnet3" name = "subnet3"
address_prefix = "10.0.3.0/24" address_prefix = "10.0.3.0/24"
} }
tags {
environment = "Production"
}
} }
``` ```
@ -60,6 +64,8 @@ The following arguments are supported:
* `subnet` - (Optional) Can be specified multiple times to define multiple * `subnet` - (Optional) Can be specified multiple times to define multiple
subnets. Each `subnet` block supports fields documented below. subnets. Each `subnet` block supports fields documented below.
* `tags` - (Optional) A mapping of tags to assign to the resource.
The `subnet` block supports: The `subnet` block supports:
* `name` - (Required) The name of the subnet. * `name` - (Required) The name of the subnet.