Skip to main content

azure_policy_exemption resource

Use the azure_policy_exemption InSpec audit resource to test the properties related to an Azure Policy Exemption.

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

describe azure_policy_exemption(resource_group: 'RESOURCE_GROUP', name: 'POLICY_EXEMPTION_NAME') do
  it                                      { should exist }
  its('name')                             { should cmp '3b8b3f3bbec24cd6af583694' }
  its('type')                             { should cmp 'Microsoft.Authorization/policyExemptions' }
  its('properties.exemptionCategory')     { should cmp 'Waiver' }
  its('properties.policyAssignmentId')    { should cmp '/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/CostManagement' }
  its('systemData.createdByType')         { should cmp 'User' }
end
describe azure_policy_exemption(name: 'POLICY_EXEMPTION_NAME') do
  it  { should exist }
end

Parameters

name (required)

The name of the Azure Policy Exemption to test.

resource_group (optional)

The name of the resource group.

Properties

id
Resource ID.
name
Policy Exemption Name.
type
Resource type.
properties.policyAssignmentId
The ID of the policy assignment that is being exempted.
properties.policyDefinitionReferenceIds
The policy definition reference ID list when the associated policy assignment is an assignment of a policy set definition.
properties.exemptionCategory
The policy exemption category. Possible values are Waiver and Mitigated.
properties.displayName
The display name of the policy exemption.
properties.description
The description of the policy exemption.
systemData.createdBy
The identity that created the resource.

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 that the policy exemption category is Waiver:

describe azure_policy_exemption(name: 'POLICY_EXEMPTION_NAME') do
  its('properties.exemptionCategory') { should eq 'Waiver' }
end

Test that the definition reference ID list includes a particular reference ID:

describe azure_policy_exemption(resource_group: 'RESOURCE_GROUP', name: 'POLICY_EXEMPTION_NAME') do
  its('properties.policyDefinitionReferenceIds') { should include 'POLICY_DEFINITION_REFERENCE_ID' }
end

Matchers

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

exists

# If a policy exemption is found, it will exist.

describe azure_policy_exemption(name: 'POLICY_EXEMPTION_NAME') do
  it { should exist }
end

not_exists

# policy exemptions that aren't found will not exist.

describe azure_policy_exemption('3b8b3f3bbec24cd6af583694') 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!

×