Skip to content

Commit

Permalink
'azurerm_virtual_network' - add guid attribute (#2325) (#6445)
Browse files Browse the repository at this point in the history
Addresses #2325

-Add guid (ResourceGUID) attribute to azurerm_virtual_network data source and azurerm_virtual_network resource.
-Update documentation for d/azurerm_virtual_network and r/azurerm_virtual_network to include guid attribute (Also added a trailing period to an existing attribute for consistency)
-Fix acceptance test for azurerm_virtual_network data source (reference to address_space should be singular)
  • Loading branch information
akonrath committed Apr 13, 2020
1 parent 24a4f84 commit 3d70c7e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func dataSourceArmVirtualNetwork() *schema.Resource {
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"location": azure.SchemaLocationForDataSource(),

"address_space": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -48,6 +47,11 @@ func dataSourceArmVirtualNetwork() *schema.Resource {
},
},

"guid": {
Type: schema.TypeString,
Computed: true,
},

"subnets": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func resourceArmVirtualNetwork() *schema.Resource {
},
},

"guid": {
Type: schema.TypeString,
Computed: true,
},

"subnet": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
Expand All @@ -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"),
),
},
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 @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/virtual_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down

0 comments on commit 3d70c7e

Please sign in to comment.