Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ID of an embedded subnet defined in azurerm_virtual_network #1913

Merged
merged 5 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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