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