Skip to content

Commit

Permalink
Merge pull request hashicorp#4720 from stack72/azurerm-tagging-accept…
Browse files Browse the repository at this point in the history
…ance-tests

Add acceptance tests and docs update to allow the tagging of AzureRM …
  • Loading branch information
jen20 committed Jan 18, 2016
2 parents 14344d0 + 2ebe2c0 commit c23d6d6
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
56 changes: 56 additions & 0 deletions builtin/providers/azurerm/resource_arm_resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -80,3 +113,26 @@ resource "azurerm_resource_group" "test" {
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"
}
}
`
80 changes: 80 additions & 0 deletions builtin/providers/azurerm/resource_arm_virtual_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -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"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Creates a new resource group on Azure.
resource "azurerm_resource_group" "test" {
name = "testResourceGroup1"
location = "West US"
tags {
environment = "Production"
}
}
```

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

* `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/).

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

## Attributes Reference

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ resource "azurerm_virtual_network" "test" {
name = "subnet3"
address_prefix = "10.0.3.0/24"
}
tags {
environment = "Production"
}
}
```

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

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

The `subnet` block supports:

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

0 comments on commit c23d6d6

Please sign in to comment.