Write policy logic
Develop policy logic with ordered conditions, a fallback, and explicit treatment of related resources and missing data.
Choose the Input Type
Choose the CMDB object representing the resource you will evaluate. Set its API name in the required inputType field. Optional recordTypes limits evaluation to specific record types.
Use Structure a custom policy to prepare the descriptor and documentation before adding logic.
Build a Worked YAML Example
This focused attachment check adapts the AWS Support Role policy's related-list logic. It evaluates an AWS account for an attachment of AWSSupportAccess to a role. Save it as wip.logic.yaml in your custom policy directory and supply test-data.json alongside it.
inputType: CA10__CaAwsAccount__c
testData:
- file: test-data.json
conditions:
- status: COMPLIANT
currentStateMessage: A support-policy attachment has valid role and policy lookups.
check:
RELATED_LIST_HAS:
status: COMPLIANT
relationshipName: CA10__AWS_IAM_Role_Policy_Attachments__r
- status: INCOMPLIANT
currentStateMessage: Active attachments were evaluated without a qualifying support attachment.
remediationMessage: Review role attachments and attach AWSSupportAccess to the intended role.
check:
RELATED_LIST_HAS:
status: INCOMPLIANT
relationshipName: CA10__AWS_IAM_Role_Policy_Attachments__r
otherwise:
status: UNDETERMINED
currentStateMessage: Related data did not establish an attachment outcome.
relatedLists:
- relationshipName: CA10__AWS_IAM_Role_Policy_Attachments__r
importExtracts:
- file: /types/CA10__CaAwsIamRolePolicyAttachment__c/object.extracts.yaml
conditions:
- status: COMPLIANT
currentStateMessage: This attachment links the support policy to an available role.
check:
AND:
args:
- NOT_EMPTY_LOOKUP: CA10__role__r
- NOT_EMPTY_LOOKUP: CA10__policy__r
- IS_EQUAL:
left:
EXTRACT: CA10__policyArn__c
right:
TEXT: arn:aws:iam::aws:policy/AWSSupportAccess
otherwise:
status: INCOMPLIANT
currentStateMessage: This attachment does not meet the support-policy criteria.
The built-in policy also examines the account's IAM policy list. See Read policy details for its complete evaluation paths.
Order Conditions and Set the Fallback
Conditions run in order; the first match determines the outcome. Here, a qualifying attachment makes the account compliant even when other attachments do not qualify. The second condition detects incompliant related results. If neither matches, otherwise returns UNDETERMINED.
Provide a state message explaining each outcome and remediation guidance for violations. See Policy statuses.
Use Relationships and Reusable Extracts
Distinguish a provider identifier, a CMDB lookup ID, and the related object. For example, an EC2 instance exposes CA10__vpcId__c, CA10__vpc__c, and CA10__vpc__r, respectively. A related list represents the reverse connection to multiple records.
In the example, relationshipName selects attachment records, while NOT_EMPTY_LOOKUP checks their role and policy relationships. The imported extract supplies the policy ARN.
Reusable extracts live under types/{type} and centralize field access. Import their file through importExtracts, then reference the named value with EXTRACT. Use extracts for production logic to keep shared data handling maintainable. See Policy logic reference and Operations for reference topics.
Handle Missing Data
Relationship traversal can return null when the target field is empty, a provider relationship is absent, the CMDB lookup is missing, or a related object has disappeared. A null therefore does not always mean an intentionally empty configuration.
Check relationship completeness with IS_EMPTY_LOOKUP or NOT_EMPTY_LOOKUP as appropriate. Decide whether absence establishes a violation or leaves insufficient evidence. Exercise both cases in fixtures; do not assume an empty related list proves that a role is missing in AWS.
Validate the Example
Before using this adaptation in production:
-
Confirm the input type, relationship, and extract definitions exist in your repository.
-
Create fixtures with expected outcomes for a valid support attachment, an unrelated policy attachment, and no available related records. Include missing lookups and disappeared records to check implicit engine behavior.
-
From the repository root, run the following commands, replacing
YOUR_POLICY_PATHwith your custom policy directory:repo-manager policies test YOUR_POLICY_PATH/wip.logic.yamlrepo-manager policies generate DEBUG YOUR_POLICY_PATH/wip.logic.yaml -
Review test outcomes and generated SQL using Test and debug policies. Compare fixture expectations with actual engine results before selecting production logic.
This adapted example requires validation against your supported engine and fixture schema. Follow Deploy and maintain custom policies for the transition to production.