website logo
HomeGithubSlack
⌘K
Overview
Quick Start
Supported Services
Running CloudGraph in EKS
Compliance
Rules Engine
AWS
Querying AWS Data
AWS Policy Packs
Billing Data
Services
Azure
Querying Azure Data
Azure Policy Packs
Services
GCP
Querying GCP Data
GCP Policy Packs
Services
K8s
Querying Kubernetes Data
Services
Docs powered by
Archbee
Azure
...
Services
Policy

Policy Assignment

15min

Note: if you are running CloudGraph locally you can view the interactive, automatically generated documentation in either GraphQL Playground or Altair by clicking the docs button on the right-hand side of the screen. After reading the below information we highly suggest you use one of these tools to test your queries as they will autocomplete fields for you and let you know if your queries are valid before you even submit them.

Overview

You can currently query the following attributes on an Azure Policy Assignment

GraphQL
|
query {
  queryazurePolicyAssignment{
    id
    name
    type
    subscriptionId
    region
    resourceGroupId
    description
    displayName
    enforcementMode
    identity{
      principalId
      tenantId
      type
    }
    nonComplianceMessages{
      id
      message
      policyDefinitionReferenceId
    }
    notScopes
    parameters{
      id
      key
      value{
        id
        key
        value
      }
    }
    policyDefinitionId
    scope
    createdBy
    createdByType
    createdAt
  }
}


Filtering

Get data for a single Azure Policy Assignment key that you know the ID for:

GraphQL
|
query {
  getazurePolicyAssignment(id: "12345") {
    id
    # Other fields and connections here...
  }
}


Get data for all of the Policy Assignments in a certain Azure subscription:

GraphQL
|
query {
  queryazureDisk(filter: { subscriptionId: { eq: "12345" } }) {
    id
    # Other fields and connections here...
  }
}

# Note that in addition to "subscriptionId" you can
# Filter based on any of the following attributes:

# id
# name
# type
# subscriptionId
# region
# resourceGroupId
# description
# displayName
# enforcementMode
# policyDefinitionId
# scope
# createdBy
# createdByType
# createdAt

# And the following Dgraph filters can also be applied:

# has
# and
# or
# not
# regexp (regular expressions)

# fulltext filters

# alloftext
# anyoftext


Get data for all of the Policy Assignments that are NOT in a certain Azure subscription:

GraphQL
|
query {
  queryazurePolicyAssignment(filter: { not: { subscriptionId: { eq: "12345" } } }) {
    id
    # Other fields and connections here...
  }
}


Advanced Filtering

Get data for all of the Policy Assignments that are connected to a nonComplianceMessage:

GraphQL
|
query {
  queryazurePolicyAssignment(filter: { has: nonComplianceMessages }) {
    id
    # Other fields and connections here...
  }
}

# Note that in addition to "nonComplianceMessages" you can filter
# Using "has" based on any of the following attributes:

# enforcementMode
# identity
# nonComplianceMessages
# notScopes
# parameters
# policyDefinitionId
# scope
# createdBy
# createdByType
# createdAt


Ordering

You can order the results you get back either asc or desc depending on your preference:

GraphQL
|
query {
  queryazurePolicyAssignment(order: { desc: createdAt }) {
    id
    # Other fields and connections here...
  }
}

# Note that in addition to "createdAt" you can filter
# Using "asc" or "desc" based on any of the following attributes:

# id
# name
# type
# subscriptionId
# region
# resourceGroupId
# description
# displayName
# enforcementMode
# policyDefinitionId
# scope
# createdBy
# createdByType


Only select and return the first two Policy Assignments that are found:

GraphQL
|
query {
  queryazurePolicyAssignment(first: 2, order: { desc: createdAt }) {
    id
    # Other fields and connections here...
  }
}


Only select and return the first two Disks that are found, but offset by one so keys two & three are returned:

GraphQL
|
query {
  queryazurePolicyAssignment(first: 2, order: { desc: createdAt }, offset: 1) {
    id
    # Other fields and connections here...
  }
}


Aggregation

Count the number of Policy Assignments across all scanned Azure subscriptions:

GraphQL
|
query {
  aggregateazurePolicyAssignment {
    count
    # Other fields and connections here...
  }
}

# Note that in addition to "count" you can request the
# Following min and max values based on attributes of your Disks:

# idMin
# idMax
# nameMin
# nameMax
# typeMin
# typeMax
# subscriptionIdMin
# subscriptionIdMax
# regionMin
# regionMax
# resourceGroupIdMin
# resourceGroupIdMax
# descriptionMin
# descriptionMax
# displayNameMin
# displayNameMax
# enforcementModeMin
# enforcementModeMax
# policyDefinitionIdMin
# policyDefinitionIdMax
# scopeMin
# scopeMax
# createdByMin
# createdByMax
# createdByTypeMin
# createdByTypeMax
# createdAtMin
# createdAtMax


Count the number of Policy Assignments in a single account. Note that you can apply all of the same filters that are listed above to aggregate queries:

GraphQL
|
query {
  aggregateazurePolicyAssignment(filter: { subscriptionId: { eq: "12345" } }) {
    count
    # Other fields and connections here...
  }
}


Examples

Find all of the Policy Assignments that are in the eastus region across all your accounts:

GraphQL
|
query {
  queryazurePolicyAssignment(filter: { region: { eq: "eastus" } }) {
    id
    # Other fields and connections here...
  }
}


Kitchen Sink

Putting it all together; get all data for all Policy Assignments across all regions for all scanned Azure subscriptions in a single query:

GraphQL
|
query {
  queryazurePolicyAssignment {
    id
    name
    type
    subscriptionId
    region
    resourceGroupId
    description
    displayName
    enforcementMode
    identity{
      principalId
      tenantId
      type
    }
    nonComplianceMessages{
      id
      message
      policyDefinitionReferenceId
    }
    notScopes
    parameters{
      id
      key
      value{
        id
        key
        value
      }
    }
    policyDefinitionId
    scope
    createdBy
    createdByType
    createdAt
  }
}


References

Dgraph documentation on querying

Azure Policy Documentation

Updated 03 Mar 2023
Did this page help you?
PREVIOUS
Network Interface
NEXT
Private DNS Zone
Docs powered by
Archbee
TABLE OF CONTENTS
Overview
Filtering
Advanced Filtering
Ordering
Aggregation
Examples
Kitchen Sink
References
Docs powered by
Archbee