azure_subnet Resource
Use the azure_subnet
InSpec audit resource to test properties related to a subnet for a given 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
, 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
Parameters
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
Parameters
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 (.
).
Examples
Ensure that the Subnets Address Prefix is Configured As Expected.
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
its('address_prefix') { should eq '192.168.0.0/24' }
end
Ensure that the Subnet is Attached to the Right Network Security Group.
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
its('nsg') { should eq 'NetworkSecurityGroupName'}
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 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
Azure Permissions
Your Service Principal must be set up with at least a contributor
role on the subscription you wish to test.
+++ title = “azure_subnet Resource” platform = “azure” draft = false gh_repo = “inspec-azure”
[menu.inspec] title = “azure_subnet” identifier = “inspec/resources/azure/azure_subnet Resource” parent = “inspec/resources/azure” +++
Use the azure_subnet
InSpec audit resource to test properties related to a subnet for a given 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
, 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
Parameters
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
Parameters
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 (.
).
Examples
Ensure that the Subnets Address Prefix is Configured As Expected.
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
its('address_prefix') { should eq '192.168.0.0/24' }
end
Ensure that the Subnet is Attached to the Right Network Security Group.
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
its('nsg') { should eq 'NetworkSecurityGroupName'}
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 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
Azure Permissions
Your Service Principal must be setup with a contributor
role on the subscription you wish to test.
+++ title = “azure_subnet Resource” platform = “azure” draft = false gh_repo = “inspec-azure”
[menu.inspec] title = “azure_subnet” identifier = “inspec/resources/azure/azure_subnet Resource” parent = “inspec/resources/azure” +++
Use the azure_subnet
InSpec audit resource to test properties related to a subnet for a given 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
, 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
Parameters
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
Parameters
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 (.
).
Examples
Ensure that the Subnets Address Prefix is Configured As Expected.
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
its('address_prefix') { should eq '192.168.0.0/24' }
end
Ensure that the Subnet is Attached to the Right Network Security Group.
describe azure_subnet(resource_group: 'MyResourceGroup', vnet: 'MyVnetName', name: 'MySubnetName') do
its('nsg') { should eq 'NetworkSecurityGroupName'}
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 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
Azure Permissions
Your Service Principal must be setup with a contributor
role on the subscription you wish to test.
Was this page helpful?