Skip to content

Commit

Permalink
Data source virtual network add location (#4281)
Browse files Browse the repository at this point in the history
Fixes: #4278
  • Loading branch information
r0bnet authored and katbyte committed Sep 10, 2019
1 parent 7da34ca commit 3697b8b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions azurerm/data_source_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func dataSourceArmVirtualNetwork() *schema.Resource {

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"location": azure.SchemaLocationForDataSource(),

"address_spaces": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -84,6 +86,10 @@ func dataSourceArmVnetRead(d *schema.ResourceData, meta interface{}) error {
}
d.SetId(*resp.ID)

if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}

if props := resp.VirtualNetworkPropertiesFormat; props != nil {
if as := props.AddressSpace; as != nil {
if err := d.Set("address_spaces", utils.FlattenStringSlice(as.AddressPrefixes)); err != nil { //todo remove in 2.0
Expand Down
3 changes: 3 additions & 0 deletions azurerm/data_source_virtual_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
)

Expand All @@ -13,6 +14,7 @@ func TestAccDataSourceArmVirtualNetwork_basic(t *testing.T) {
ri := tf.AccRandTimeInt()

name := fmt.Sprintf("acctestvnet-%d", ri)
location := testLocation()
config := testAccDataSourceArmVirtualNetwork_basic(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -23,6 +25,7 @@ func TestAccDataSourceArmVirtualNetwork_basic(t *testing.T) {
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "name", name),
resource.TestCheckResourceAttr(dataSourceName, "location", azure.NormalizeLocation(location)),
resource.TestCheckResourceAttr(dataSourceName, "dns_servers.0", "10.0.0.4"),
resource.TestCheckResourceAttr(dataSourceName, "address_spaces.0", "10.0.0.0/16"),
resource.TestCheckResourceAttr(dataSourceName, "subnets.0", "subnet1"),
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/virtual_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ output "virtual_network_id" {
## Attributes Reference

* `id` - The ID of the virtual network.
* `location` - Location of the virtual network.
* `address_space` - The list of address spaces used by the virtual network.
* `dns_servers` - The list of DNS servers used by the virtual network.
* `subnets` - The list of name of the subnets that are attached to this virtual network.
Expand Down

0 comments on commit 3697b8b

Please sign in to comment.