Skip to main content

azure_policy_insights_query_result Resource

Use the azure_policy_insights_query_result InSpec audit resource to test the properties and configuration of an Azure Policy Insights query result.

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

The policy_definition and the resource_id are required parameters.

describe azure_policy_insights_query_result(policy_definition: 'de875639-505c-4c00-b2ab-bb290dab9a54', resource_id: '/subscriptions/80b824de-ec53-4116-9868-3deeab10b0cd/resourcegroups/jfm-winimgbuilderrg2/providers/microsoft.virtualmachineimages/imagetemplates/win1021h1') do
  it { should exist }
end
describe azure_policy_insights_query_result(policy_definition: 'de875639-505c-4c00-b2ab-bb290dab9a54', resource_id: '/subscriptions/80b824de-ec53-4116-9868-3deeab10b0cd/resourcegroups/jfm-winimgbuilderrg2/providers/microsoft.virtualmachineimages/imagetemplates/win1021h1') do
  it { should exist }
end

Parameters

policy_definition
Name of the policy definition. policyDefinitionName.
resource_id
The unique resource ID. /subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderId}.

Submit both parameters for a valid query:

  • resource_id
  • policy_definition

Properties

resource_id
Resource ID.
policy_assignment_id
Policy assignment ID.
policy_definition_id
Policy definition ID.
policy_assignment_name
Policy assignment name.
policy_definition_name
Policy definition name.
policy_definition_action
Policy definition action. For example, effect.
compliance_state
Compliance state of the resource.
effective_parameters
Effective parameters for the policy assignment.
is_compliant
Flag indicating whether the resource is compliant against the policy assignment it was evaluated.

Note

This property is deprecated; please use ComplianceState instead.
policy_assignment_owner
Policy assignment owner.
policy_assignment_parameters
Policy assignment parameters.
policy_assignment_scope
Policy assignment scope.
subscription_id
Subscription ID.
resource_type
Resource type.
resource_location
Resource location.
resource_group
Resource group name.
resource_tags
List of resource tags.
policy_definition_category
Policy definition category.
management_group_ids
Comma separated list of management group IDs, which represent the hierarchy of the management groups the resource is part of.
compliance_reason_code
Populated with the failure error code sometimes.

Also, refer to Azure documentation for other properties available. Any attribute in the response may be accessed with the key names separated by dots (.). For example, properties.<attribute>.

Examples

Test a policy definition resource type

describe azure_policy_insights_query_result(policy_definition: 'de875639-505c-4c00-b2ab-bb290dab9a54',  resource_id: '/subscriptions/80b824de-ec53-4116-9868-3deeab10b0cd/resourcegroups/jfm-winimgbuilderrg2/providers/microsoft.virtualmachineimages/imagetemplates/win1021h1') do
  its('resourceType') { should eq 'Microsoft.VirtualMachineImages/imageTemplates' }
end

Test a policy definition and policy assignment scope

describe azure_policy_insights_query_result(policy_definition: 'de875639-505c-4c00-b2ab-bb290dab9a54', resource_id: '/subscriptions/80b824de-ec53-4116-9868-3deeab10b0cd/resourcegroups/jfm-winimgbuilderrg2/providers/microsoft.virtualmachineimages/imagetemplates/win1021h1') do
  its('policyAssignmentScope') { should cmp '/subscriptions/80b824de-ec53-4116-9868-3deeab10b0cd' }
end

Matchers

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

This resource has the following special matchers.

compliant

Test if a policy definition type is Compliant or not.

describe azure_policy_insights_query_result(policy_definition: 'de875639-505c-4c00-b2ab-bb290dab9a54', resource_id: '/subscriptions/80b824de-ec53-4116-9868-3deeab10b0cd/resourcegroups/jfm-winimgbuilderrg2/providers/microsoft.virtualmachineimages/imagetemplates/win1021h1') do
  it { should be_compliant }
end

exists

# If we expect a resource to always exist.

describe azure_policy_insights_query_result(policy_definition: 'de875639-505c-4c00-b2ab-bb290dab9a54', resource_id: '/subscriptions/80b824de-ec53-4116-9868-3deeab10b0cd/resourcegroups/jfm-winimgbuilderrg2/providers/microsoft.virtualmachineimages/imagetemplates/win1021h1') do
  it { should exist }
end

not_exists

# If we expect a resource to never exist.

describe azure_policy_insights_query_result(policy_definition: 'de875639-505c-4c00-b2ab-bb290dab9a54', resource_id: '/subscriptions/80b824de-ec53-4116-9868-3deeab10b0cd/resourcegroups/jfm-winimgbuilderrg2/providers/microsoft.virtualmachineimages/imagetemplates/win1021h1') 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!

×









Search Results