Skip to main content

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

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, see here.
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 and name

Properties

provisioning_state
The provisioning state of the network watcher resource. For the valid values, see here.
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, refer to Azure documentation for other properties available. Any attribute in the response may be accessed 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.

Edit this page on GitHub

Thank you for your feedback!

×