diff --git a/azurerm/internal/services/network/data_source_virtual_network.go b/azurerm/internal/services/network/data_source_virtual_network.go index dca55e7f23f6..d7d576142917 100644 --- a/azurerm/internal/services/network/data_source_virtual_network.go +++ b/azurerm/internal/services/network/data_source_virtual_network.go @@ -31,7 +31,6 @@ func dataSourceArmVirtualNetwork() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), "location": azure.SchemaLocationForDataSource(), - "address_space": { Type: schema.TypeList, Computed: true, @@ -48,6 +47,11 @@ func dataSourceArmVirtualNetwork() *schema.Resource { }, }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "subnets": { Type: schema.TypeList, Computed: true, @@ -94,6 +98,8 @@ func dataSourceArmVnetRead(d *schema.ResourceData, meta interface{}) error { } if props := resp.VirtualNetworkPropertiesFormat; props != nil { + d.Set("guid", props.ResourceGUID) + if as := props.AddressSpace; as != nil { if err := d.Set("address_space", utils.FlattenStringSlice(as.AddressPrefixes)); err != nil { return fmt.Errorf("error setting `address_space`: %v", err) diff --git a/azurerm/internal/services/network/data_source_virtual_network_gateway_connection.go b/azurerm/internal/services/network/data_source_virtual_network_gateway_connection.go index 103f5e792ce6..b10387aaf01c 100644 --- a/azurerm/internal/services/network/data_source_virtual_network_gateway_connection.go +++ b/azurerm/internal/services/network/data_source_virtual_network_gateway_connection.go @@ -183,45 +183,16 @@ func dataSourceArmVirtualNetworkGatewayConnectionRead(d *schema.ResourceData, me if resp.VirtualNetworkGatewayConnectionPropertiesFormat != nil { gwc := *resp.VirtualNetworkGatewayConnectionPropertiesFormat - if gwc.SharedKey != nil { - d.Set("shared_key", gwc.SharedKey) - } - - if gwc.AuthorizationKey != nil { - d.Set("authorization_key", gwc.AuthorizationKey) - } - - if gwc.EnableBgp != nil { - d.Set("enable_bgp", gwc.EnableBgp) - } - - if gwc.IngressBytesTransferred != nil { - d.Set("ingress_bytes_transferred", gwc.IngressBytesTransferred) - } - - if gwc.EgressBytesTransferred != nil { - d.Set("egress_bytes_transferred", gwc.EgressBytesTransferred) - } - - if gwc.UsePolicyBasedTrafficSelectors != nil { - d.Set("use_policy_based_traffic_selectors", gwc.UsePolicyBasedTrafficSelectors) - } - - if gwc.ExpressRouteGatewayBypass != nil { - d.Set("express_route_gateway_bypass", gwc.ExpressRouteGatewayBypass) - } - - if string(gwc.ConnectionType) != "" { - d.Set("type", string(gwc.ConnectionType)) - } - - if string(gwc.ConnectionProtocol) != "" { - d.Set("connection_protocol", string(gwc.ConnectionProtocol)) - } - - if gwc.RoutingWeight != nil { - d.Set("routing_weight", gwc.RoutingWeight) - } + d.Set("shared_key", gwc.SharedKey) + d.Set("authorization_key", gwc.AuthorizationKey) + d.Set("enable_bgp", gwc.EnableBgp) + d.Set("ingress_bytes_transferred", gwc.IngressBytesTransferred) + d.Set("egress_bytes_transferred", gwc.EgressBytesTransferred) + d.Set("use_policy_based_traffic_selectors", gwc.UsePolicyBasedTrafficSelectors) + d.Set("express_route_gateway_bypass", gwc.ExpressRouteGatewayBypass) + d.Set("type", string(gwc.ConnectionType)) + d.Set("connection_protocol", string(gwc.ConnectionProtocol)) + d.Set("routing_weight", gwc.RoutingWeight) if gwc.VirtualNetworkGateway1 != nil { d.Set("virtual_network_gateway_id", gwc.VirtualNetworkGateway1.ID) @@ -239,9 +210,7 @@ func dataSourceArmVirtualNetworkGatewayConnectionRead(d *schema.ResourceData, me d.Set("express_route_circuit_id", gwc.Peer.ID) } - if gwc.ResourceGUID != nil { - d.Set("resource_guid", gwc.ResourceGUID) - } + d.Set("resource_guid", gwc.ResourceGUID) ipsecPoliciesSettingsFlat := flattenArmVirtualNetworkGatewayConnectionDataSourceIpsecPolicies(gwc.IpsecPolicies) if err := d.Set("ipsec_policy", ipsecPoliciesSettingsFlat); err != nil { diff --git a/azurerm/internal/services/network/resource_arm_virtual_network.go b/azurerm/internal/services/network/resource_arm_virtual_network.go index 25f761ef7e8b..c874dbc4461c 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_network.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network.go @@ -93,6 +93,11 @@ func resourceArmVirtualNetwork() *schema.Resource { }, }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "subnet": { Type: schema.TypeSet, Optional: true, @@ -232,11 +237,14 @@ func resourceArmVirtualNetworkRead(d *schema.ResourceData, meta interface{}) err d.Set("name", resp.Name) d.Set("resource_group_name", resGroup) + if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } if props := resp.VirtualNetworkPropertiesFormat; props != nil { + d.Set("guid", props.ResourceGUID) + if space := props.AddressSpace; space != nil { d.Set("address_space", utils.FlattenStringSlice(space.AddressPrefixes)) } diff --git a/azurerm/internal/services/network/tests/data_source_virtual_network_test.go b/azurerm/internal/services/network/tests/data_source_virtual_network_test.go index d0bc0b15c950..7315e9e3e6fd 100644 --- a/azurerm/internal/services/network/tests/data_source_virtual_network_test.go +++ b/azurerm/internal/services/network/tests/data_source_virtual_network_test.go @@ -24,7 +24,7 @@ func TestAccDataSourceArmVirtualNetwork_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "name", name), resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), resource.TestCheckResourceAttr(data.ResourceName, "dns_servers.0", "10.0.0.4"), - resource.TestCheckResourceAttr(data.ResourceName, "address_spaces.0", "10.0.0.0/16"), + resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "10.0.0.0/16"), resource.TestCheckResourceAttr(data.ResourceName, "subnets.0", "subnet1"), ), }, @@ -48,7 +48,7 @@ func TestAccDataSourceArmVirtualNetwork_peering(t *testing.T) { Config: testAccDataSourceArmVirtualNetwork_peeringWithDataSource(data), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(data.ResourceName, "name", virtualNetworkName), - resource.TestCheckResourceAttr(data.ResourceName, "address_spaces.0", "10.0.1.0/24"), + resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "10.0.1.0/24"), resource.TestCheckResourceAttr(data.ResourceName, "vnet_peerings.%", "1"), ), }, diff --git a/website/docs/d/virtual_network.html.markdown b/website/docs/d/virtual_network.html.markdown index d68a84a9a3c9..655b059263d5 100644 --- a/website/docs/d/virtual_network.html.markdown +++ b/website/docs/d/virtual_network.html.markdown @@ -34,6 +34,7 @@ output "virtual_network_id" { * `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. +* `guid` - The GUID of the virtual network. * `subnets` - The list of name of the subnets that are attached to this virtual network. * `vnet_peerings` - A mapping of name - virtual network id of the virtual network peerings. diff --git a/website/docs/r/virtual_network.html.markdown b/website/docs/r/virtual_network.html.markdown index 037f62616687..dec6cc1ddf69 100644 --- a/website/docs/r/virtual_network.html.markdown +++ b/website/docs/r/virtual_network.html.markdown @@ -124,10 +124,12 @@ The following attributes are exported: * `resource_group_name` - The name of the resource group in which to create the virtual network. -* `location` - The location/region where the virtual network is created +* `location` - The location/region where the virtual network is created. * `address_space` - The address space that is used the virtual network. +* `guid` - The GUID of the virtual network. + * `subnet`- One or more `subnet` blocks as defined below. ---