Project: Chef InSpec (Provisioning / Security & Compliance)
File: azurerm_virtual_network.md

+++ title = "azurermvirtualnetwork resource" draft = false gh_repo = "inspec" platform = "azure" [menu] [menu.inspec] title = "azurermvirtualnetwork" identifier = "inspec/resources/azure/azurermvirtualnetwork.md azurermvirtualnetwork resource" parent = "inspec/resources/azure" +++ {{< inspec/azurermdeprecated resource="azurevirtual_network" >}} Use the `azurermvirtualnetwork` InSpec audit resource to test properties related to a virtual network. This resource interacts with version `2018-02-01` of the Azure Management API. For more information see the . At the moment, there doesn't appear to be a way to select the version of the Azure API docs. If you notice a newer version being referenced in the official documentation please open an issue or submit a pull request using the updated version. This resource is available in the `inspec-azure` [resource pack](/inspec/glossary/#resource-pack). To use it, add the following to your `inspec.yml` in your top-level profile: depends: name: inspec-azure git: https://github.com/inspec/inspec-azure.git You'll also need to setup your Azure credentials; see the resource pack . This resource first became available in 1.1.0 of the inspec-azure resource pack. The `resource_group` and virtual network `name` must be given as parameters. describe azurermvirtualnetwork(resource_group: 'MyResourceGroup', name: 'MyVnetName') do ... end describe azurermvirtualnetwork(resourcegroup: resourcegroup, name: 'MyVnetName') do it { should exist } its('location') { should eq 'East US' } end describe azurermvirtualnetwork(resourcegroup: resourcegroup, name: 'MyVnetName') do its('dns_servers') { should eq ["192.168.0.6"] } end describe azurermvirtualnetwork(resourcegroup: resourcegroup, name: 'MyVnetName') do its('address_space') { should eq ["192.168.0.0/24"] } end `resource_group` `name` Defines the resource group that the virtual network that you wish to test resides in. describe azurermvirtualnetwork(resource_group: 'MyResourceGroup', name: 'MyVnetName') do ... end Defines the name of the virtual network that you wish to test. describe azurermvirtualnetwork(resource_group: 'MyResourceGroup', name: 'MyVnetName') do ... end `id` `name` `location` `tags` `type` `subnets` `address_space` `dns_servers` `vnet_peerings` `enableddosprotection` `enablevmprotection` The virtual network's id. its('id') { should eq(id) } Id will be in format: '/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/MyVnetName' The virtual network's name. its('name') { should eq('MyVnetName') } The virtual network's

its('location') { should eq('East US') } The virtual network's resource type. its('type') { should eq 'Microsoft.Network/virtualNetworks' } The virtual network's tags. its('tags') { should eq({ 'key' => 'value' }) } The list of subnet names that are attached to this virtual network. its('subnets') { should eq ["MySubnetName"] } The list of address spaces used by the virtual network. its('address_space') { should eq ["x.x.x.x/x"] } The list of DNS servers configured for the virtual network. The virtual network returns these IP addresses when virtual machines makes a DHCP request. its('dns_servers') { should eq ["x.x.x.x", "x.x.x.x"] } A mapping of names and the virtual network ids of the virtual network peerings. its('vnet_peerings') { should eq "MyVnetPeeringConnection"=>"PeeringConnectionID"} Boolean value showing if Azure DDoS standard protection is enabled on the virtual network. its('enableddosprotection') { should eq true } Boolean value showing if the virtual network has VM protection enabled. its('enablevmprotection') { should eq false } There are additional attributes that may be accessed that we have not documented. Please take a look at the . Any attribute in the response may be accessed with the key names separated by dots (`.`). The API may not always return keys that do not have any associated data. There may be cases where the deeply nested property may not have the desired attribute along your call chain. If you find yourself writing tests against properties that may be nil, fork this resource pack and add an accessor to the resource. Within that accessor you'll be able to guard against nil keys. Pull requests are always welcome. {{< readfile file="content/inspec/reusable/md/inspecmatcherslink.md" >}} This resource has the following special matchers. describe azurermvirtualnetwork(resource_group: 'MyResourceGroup', name: 'MyVnetName') do it { should exist } end describe azurermvirtualnetwork(resource_group: 'MyResourceGroup', name: 'DoesNotExist') do it { should_not exist } end Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be setup with a `contributor` role on the subscription you wish to test.