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 3 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 All @@ -56,6 +56,10 @@ resource "azurerm_virtual_network" "test" {
environment = "Production"
}
}

output "id_of_subnet2" {
value = "${azurerm_virtual_network.test.subnet.2796830261.id}"
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
}
```

## Argument Reference
Expand Down Expand Up @@ -105,6 +109,12 @@ The following attributes are exported:

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

* `subnet` - Set of multiple subnets defined in this virtual network. Each `subnet` block supports the fields documented below.
JunyiYi marked this conversation as resolved.
Show resolved Hide resolved

The `subnet` block supports:
JunyiYi marked this conversation as resolved.
Show resolved Hide resolved

* `id` - The ID of this subnet.


## Import

Expand Down