Skip to content

Commit

Permalink
Expose ID of an embedded subnet defined in azurerm_virtual_network (#…
Browse files Browse the repository at this point in the history
…1913)

* Modify test cases to check for vnet subnet id attribute

* Expose ID attribute of embedded subnet in vnet

* Add documentation and sample of embedded subnet id

* Change documentation according to the feedback

* Removing the ID accessor sample until TF0.12 makes this better
  • Loading branch information
Junyi Yi authored and tombuildsstuff committed Sep 28, 2018
1 parent f6eab11 commit 5d28e73
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
8 changes: 8 additions & 0 deletions azurerm/resource_arm_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func resourceArmVirtualNetwork() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"id": {
Type: schema.TypeString,
Computed: true,
},
},
},
Set: resourceAzureSubnetHash,
Expand Down Expand Up @@ -297,6 +301,10 @@ func flattenVirtualNetworkSubnets(input *[]network.Subnet) *schema.Set {
for _, subnet := range *input {
output := map[string]interface{}{}

if id := subnet.ID; id != nil {
output["id"] = *id
}

if name := subnet.Name; name != nil {
output["name"] = *name
}
Expand Down
18 changes: 10 additions & 8 deletions azurerm/resource_arm_virtual_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func TestAccAzureRMVirtualNetwork_basic(t *testing.T) {
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualNetworkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "subnet.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "subnet.1472110187.id"),
),
},
},
Expand Down Expand Up @@ -136,21 +138,21 @@ func TestAccAzureRMVirtualNetwork_withTags(t *testing.T) {
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualNetworkExists(resourceName),
resource.TestCheckResourceAttr(
resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(
resourceName, "tags.environment", "Production"),
resource.TestCheckResourceAttr(resourceName, "subnet.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "subnet.1472110187.id"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"),
resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"),
),
},
{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualNetworkExists(resourceName),
resource.TestCheckResourceAttr(
resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(
resourceName, "tags.environment", "staging"),
resource.TestCheckResourceAttr(resourceName, "subnet.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "subnet.1472110187.id"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"),
),
},
},
Expand Down
12 changes: 11 additions & 1 deletion website/docs/r/virtual_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ resource "azurerm_network_security_group" "test" {
resource "azurerm_virtual_network" "test" {
name = "virtualNetwork1"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
address_space = ["10.0.0.0/16"]
location = "West US"
dns_servers = ["10.0.0.4", "10.0.0.5"]
subnet {
Expand Down Expand Up @@ -82,6 +82,8 @@ The following arguments are supported:

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

---

The `subnet` block supports:

* `name` - (Required) The name of the subnet.
Expand All @@ -105,6 +107,14 @@ The following attributes are exported:

* `address_space` - The address space that is used the virtual network.

* `subnet`- One or more `subnet` blocks as defined below.

---

The `subnet` block exports:

* `id` - The ID of this subnet.


## Import

Expand Down

0 comments on commit 5d28e73

Please sign in to comment.