azure_virtual_network resource
Use the azure_virtual_network
InSpec audit resource to test the properties related to a virtual network.
Azure REST API version, endpoint, and HTTP client parameters
This resource interacts with API versions supported by the resource provider.
You can specify the api_version
as a resource parameter to use a specific version of the Azure REST API.
If you don’t specify an API version, this resource uses the latest version available.
For more information about API versioning, see the azure_generic_resource
.
By default, this resource uses the azure_cloud
global endpoint and default HTTP client settings.
You can override these settings if you need to connect to a different Azure environment (such as Azure Government or Azure China).
For more information about configuration options, see the resource pack README.
Syntax
resource_group
and virtual network name
or the resource_id
are required parameters.
describe azure_virtual_network(resource_group: 'RESOURCE_GROUP', name: 'VNET_NAME') do
it { should exist }
end
describe azure_virtual_network(resource_id: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Network/virtualNetworks/{vnName}') do
it { should exist }
end
Parameters
resource_group
- Azure resource group where the targeted resource resides.
name
- Name of the virtual network to test.
resource_id
- The unique resource ID.
Either one of the parameter sets can be provided for a valid query:
resource_id
resource_group
andname
Properties
subnets
- The list of subnet names that are attached to this virtual network.
its('subnets') { should eq ["MySubnetName"] }
. address_space
- The list of address spaces used by the virtual network.
its('address_space') { should eq ["x.x.x.x/x"] }
. dns_servers
- 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"] }
. vnet_peerings
- A mapping of names and the virtual network ids of the virtual network peerings.
its('vnet_peerings') { should eq "MyVnetPeeringConnection"=>"PeeringConnectionID"}
. enable_ddos_protection
- Boolean value showing if Azure DDoS standard protection is enabled on the virtual network.
its('enable_ddos_protection') { should eq true }
. enable_vm_protection
- Boolean value showing if the virtual network has VM protection enabled.
its('enable_vm_protection') { should eq false }
.
For properties applicable to all resources, such as type
, name
, id
, and properties
, refer to azure_generic_resource
.
Also, see the Azure documentation for other available properties. Any property in the response may be accessed with the key names separated by dots (.
).
Examples
Ensure that the Virtual Network exists in the east US region:
describe azure_virtual_network(resource_group: 'RESOURCE_GROUP', name: 'VNET_NAME') do
it { should exist }
its('location') { should eq 'eastus' }
end
Ensure that the Virtual Network’s DNS servers are configured as expected:
describe azure_virtual_network(resource_group: 'RESOURCE_GROUP', name: 'VNET_NAME') do
its('dns_servers') { should eq ["192.168.0.6"] }
end
Ensure that the Virtual Network’s address space is configured as expected:
describe azure_virtual_network(resource_group: 'RESOURCE_GROUP', name: 'VNET_NAME') do
its('address_space') { should eq ["192.168.0.0/24"] }
end
Matchers
For a full list of available matchers, see our Universal Matchers page.This resource has the following special matchers.
exists
# If a virtual network is found, it will exist.
describe azure_virtual_network(resource_group: 'RESOURCE_GROUP', name: 'VNET_NAME') do
it { should exist }
end
not_exists
# Virtual networks that are not found, will not exist.
describe azure_virtual_network(resource_group: 'RESOURCE_GROUP', name: 'DOESNOTEXIST') do
it { should_not exist }
end
Azure permissions
Your Service Principal must be set up with at least a contributor
role on the subscription you wish to test.