Skip to main content

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. 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.

Install

This resource is available in the Chef InSpec Azure resource pack.

For information on configuring your Azure environment for Chef InSpec and creating an InSpec profile that uses the InSpec Azure resource pack, see the Chef InSpec documentation for the Azure cloud platform.

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 and name

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, 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: '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.

Edit this page on GitHub

Thank you for your feedback!

×









Search Results