Skip to main content

azure_lock resource

Use the azure_lock InSpec audit resource to test the properties and configuration of a Management Lock.

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

The Management Lock resources do not follow the common resouce_group and name patterns for identification. As a result, the resource_id must be given as a parameter to the azure_lock resource.

The azure_locks resource can be used for gathering the Management Lock resource IDs to be tested within the desired level, such as subscription, resource group, or individual resource.

describe azure_lock(resource_id: '/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/locks/{lockName}') do
  it { should exist }
end

Parameters

resource_id
The unique resource ID.

Properties

properties.level
The level of the lock. Possible values are: NotSpecified, CanNotDelete, and ReadOnly. For more information, see the Microsoft lock level documentation.
properties.notes
Notes about the lock. Maximum of 512 characters.
properties.owners
A list of the owners of the lock with these properties.

Please note that the properties can vary depending on the api_version used for the lookup.

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 (.). For example, properties.<attribute>.

Examples

Test if a ‘ReadOnly’ Management Lock exists in a specific resource group:

azure_locks(resource_group: 'EXAMPLE-GROUP').ids.each do |id|
  describe azure_lock(resource_id: id) do
    its('properties.level') { should_not cmp `ReadOnly` }
  end
end

Test if Management Locks on a specific resource contain a certain String:

azure_locks(resouce_id: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vmName}').ids.each do |lock_id|
  describe azure_lock(resource_id: lock_id) do
    it('properties.notes') { should include 'contact jdoe@chef.io' }
  end
end

Matchers

For a full list of available matchers, see our Universal Matchers page.

This resource has the following special matchers.

exists

# If we expect a resource to always exist.

describe azure_lock(resource_id: '/subscriptions/..{lockName}') do
  it { should exist }
end

not_exists

# If we expect a resource to never exist.

describe azure_lock(resource_id: '/subscriptions/..{lockName}') 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.

Thank you for your feedback!

×