title | platform |
---|---|
About the azure_subnet Resource |
azure |
Use the azure_subnet
InSpec audit resource to test properties related to a subnet for a given virtual network.
This resource interacts with api versions supported by the resource provider.
The api_version
can be defined as a resource parameter.
If not provided, the latest version will be used.
For more information, refer to azure_generic_resource
.
Unless defined, azure_cloud
global endpoint, and default values for the http client will be used.
For more information, refer to the resource pack README.
This resource is available in the InSpec Azure resource pack.
For an example inspec.yml
file and how to set up your Azure credentials, refer to resource pack README.
resource_group
, vnet
and name
or the resource_id
must be given as a parameter.
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
it { should exist }
end
describe azure_subnet(resource_id: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Network/virtualNetworks/{vnName}/subnets/{subnetName}') do
it { should exist }
end
Name | Description |
---|---|
resource_group | Azure resource group that the targeted resource resides in. MyResourceGroup |
vnet | Name of the Azure virtual network that the subnet is created in. MyVNetName |
name | Name of the Azure subnet to test. MySubnetName |
resource_id | The unique resource ID. /subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Network/virtualNetworks/{vnName}/subnets/{subnetName} |
Either one of the parameter sets can be provided for a valid query:
resource_id
resource_group
,vnet
andname
Property | Description |
---|---|
address_prefix | The address prefix for the subnet. its('address_prefix') { should eq "x.x.x.x/x" } |
nsg | The network security group attached to the subnet. its('nsg') { should eq 'MyNetworkSecurityGroupName' } |
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 (.
).
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
its('address_prefix') { should eq '192.168.0.0/24' }
end
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
its('nsg') { should eq 'NetworkSecurityGroupName'}
end
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our Universal Matchers page.
# If a subnet is found it will exist
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
it { should exist }
end
# subnets that aren't found will not exist
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', 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.