title | platform |
---|---|
About the azurerm_virtual_network Resource |
azure |
WARNING This resource will be deprecated in InSpec Azure Resource Pack version 2. Please start using fully backward compatible
azure_virtual_network
InSpec audit resource.
Use the azurerm_virtual_network
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 official Azure documentation.
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. 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 README.
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 azurerm_virtual_network(resource_group: 'MyResourceGroup', name: 'MyVnetName') do
...
end
describe azurerm_virtual_network(resource_group: resource_group, name: 'MyVnetName') do
it { should exist }
its('location') { should eq 'East US' }
end
describe azurerm_virtual_network(resource_group: resource_group, name: 'MyVnetName') do
its('dns_servers') { should eq ["192.168.0.6"] }
end
describe azurerm_virtual_network(resource_group: resource_group, 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 azurerm_virtual_network(resource_group: 'MyResourceGroup', name: 'MyVnetName') do
...
end
Defines the name of the virtual network that you wish to test.
describe azurerm_virtual_network(resource_group: 'MyResourceGroup', name: 'MyVnetName') do
...
end
id
name
location
tags
type
subnets
address_space
dns_servers
vnet_peerings
enable_ddos_protection
enable_vm_protection
The virtual network's id.
its('id') { should eq(id) }
Id will be in format:
'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Inspec-Azure-mmclane/providers/Microsoft.Network/virtualNetworks/MyVnetName'
The virtual network's name.
its('name') { should eq('MyVnetName') }
The virtual network's location.
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('enable_ddos_protection') { should eq true }
Boolean value showing if the virtual network has VM protection enabled.
its('enable_vm_protection') { should eq false }
There are additional attributes that may be accessed that we have not
documented. Please take a look at the Azure documentation.
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.
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our Universal Matchers page.
# If a virtual network is found it will exist
describe azurerm_virtual_network(resource_group: 'MyResourceGroup', name: 'MyVnetName') do
it { should exist }
end
# virtual networks that aren't found will not exist
describe azurerm_virtual_network(resource_group: 'MyResourceGroup', name: 'DoesNotExist') do
it { should_not exist }
end
Your Service
Principal
must be setup with a contributor
role on the subscription you wish to test.