azure_network_watcher resource
Use the azure_network_watcher
InSpec audit resource to test the properties of an Azure Network Watcher.
Azure REST API version, endpoint, and HTTP client parameters
This resource interacts with API versions supported by the resource provider.
You can specify the api_version
as a resource parameter to use a specific version of the Azure REST API.
If you don’t specify an API version, this resource uses the latest version available.
For more information about API versioning, see the azure_generic_resource
.
By default, this resource uses the azure_cloud
global endpoint and default HTTP client settings.
You can override these settings if you need to connect to a different Azure environment (such as Azure Government or Azure China).
For more information about configuration options, see the resource pack README.
Syntax
An azure_network_watcher
resource block identifies a Network Watcher by name
and resource_group
, or the resource_id
.
describe azure_network_watcher(resource_group: 'RESOURCE_GROUP', name: 'NETWORK_WATCHER_NAME') do
it { should exist }
end
describe azure_network_watcher(resource_id: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}') do
it { should exist }
end
Parameters
resource_group
- Azure resource group where the network watcher resides.
name
- Name of the network watcher to test.
resource_id
- The unique resource ID.
flow_logs_api_version
- The flow log status endpoint API version used for creating
flow_logs
property. The latest version will be used unless provided. A network security group within the same region can be targeted for getting the flow log statuses. For more information, see the Azure Network Watchers Flow Log Status documentation. nsg_resource_id
- The unique resource ID of the network security group being targeted to get the flow log statuses.
/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkSecurityGroups/{networkSecurityGroupName}
. nsg_resource_group
- The resource group of the network security group being targeted to get the flow log statuses. This requires
nsg_name
to be provided. nsg_name
- The name of the network security group being targeted to get the flow log statuses. This requires
nsg_resource_group
to be provided.
Either one of the parameter sets can be provided for a valid query:
resource_id
resource_group
andname
Properties
provisioning_state
- The provisioning state of the network watcher resource. For the valid values, see the Azure Network Watchers ProvisioningState documentation.
flow_logs
- Information on the configuration of flow log and traffic analytics (optional) in this format. All properties can be accessed via dot notation. For example,
flow_logs.properties.enabled
. This resource supports targeting network security groups defined at resource creation only.
For properties applicable to all resources, such as type
, name
, id
, and properties
, refer to azure_generic_resource
.
Also, see the Azure documentation for other available properties. You can access any attribute in the response with the key names separated by dots (.
).
Examples
Test the location of a Network Watcher:
describe azure_network_watcher(resource_group: 'RESOURCE_GROUP', name: 'NETWORK_WATCHER_NAME') do
its('location') { should cmp 'eastus' }
end
Test the Flow Log status of a Network Security group:
describe azure_network_watcher(resource_group: 'RESOURCE_GROUP', name: 'NETWORK_WATCHER_NAME', nsg_resource_group: 'NSG_RESOURCE_GROUP', nsg_name: 'nsg_eastus') do
its('flow_logs.properties.enabled') { should be true }
its('flow_logs.properties.retentionPolicy.days') { should be >= 90 }
end
Loop through Network Security groups with the resource ID:
azure_network_security_groups.where(location: 'eastus').ids.each do |nsg_id|
describe azure_network_watcher(resource_group: 'RESOURCE_GROUP', name: 'NETWORK_WATCHER_NAME', nsg_resource_id: nsg_id) do
its('flow_logs.properties.enabled') { should be true }
its('flow_logs.properties.retentionPolicy.days') { should be >= 90 }
end
end
See integration tests for more examples.
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 we expect 'NETWORKWATCHERNAME' to always exist.
describe azure_network_watcher(resource_group: 'RESOURCE_GROUP', name: 'NETWORK_WATCHER_NAME') do
it { should exist }
end
# If we expect 'NETWORKWATCHERNAME' to never exist.
describe azure_network_watcher(resource_group: 'RESOURCE_GROUP', name: 'NETWORK_WATCHER_NAME') 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.