azure_virtual_network Resource
Use the azure_virtual_network
InSpec audit resource to test 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.
The api_version
can be defined as a resource parameter.
If not provided, this resource uses the latest version.
For more information, refer to the azure_generic_resource document.
Unless defined, this resource uses the azure_cloud
global endpoint and default values for the HTTP client.
For more information, refer to the resource pack README.
Installation
This resource is available in the Chef InSpec Azure resource pack.
See the Chef InSpec documentation on cloud platforms for information on configuring your Azure environment for InSpec and creating an InSpec profile that uses the InSpec Azure resource pack.
Syntax
resource_group
and virtual network name
or the resource_id
must be given as a parameter.
describe azure_virtual_network(resource_group: 'MyResourceGroup', name: 'MyVnetName') 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 that the targeted resource resides in.
MyResourceGroup
. name
- Name of the virtual network to test.
MyVNetwork
. resource_id
- The unique resource ID.
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Network/virtualNetworks/{vnName}
.
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
, properties
, refer to azure_generic_resource.
Also, refer to Azure documentation for other properties available.
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: 'MyVnetName') 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: 'MyVnetName') 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: 'MyVnetName') do
its('address_space') { should eq ["192.168.0.0/24"] }
end
Matchers
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our Universal Matchers page.
exists
# If a virtual network is found it will exist
describe azure_virtual_network(resource_group: 'MyResourceGroup', name: 'MyVnetName') do
it { should exist }
end
# virtual networks that aren't found will not exist
describe azure_virtual_network(resource_group: 'MyResourceGroup', 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.
Was this page helpful?