Writing YAML Policy Values

Many Guardrails policy types accept YAML-formatted values -- structured data like lists, key-value pairs, or nested maps. While most policies use a simple enumerated value like Skip, Check: Enabled, or Enforce: Enabled, some policies need to express more complex data: a list of approved regions, a set of required tags, a schedule definition, or a set of notification routing rules.

YAML is the input format for these structured policies. If you've configured Kubernetes manifests, Ansible playbooks, or CloudFormation templates, you already know the syntax. If you're new to YAML, the key things to know are: indentation matters (use spaces, not tabs), hyphens (-) denote list items, and colons (:) separate keys from values.

[!NOTE] YAML and OCL serve different purposes. OCL is for rule evaluation -- APPROVE/REJECT logic used in security group rules, IAM policy statements, and KMS key policies. YAML is for structured data -- lists, maps, and configuration objects. See Write OCL Policies for OCL examples.

Simple Lists

The most common YAML pattern is a simple list of allowed values. These are used for region restrictions, approved resource types, and similar allowlists.

Approved Regions

AWS > Account > Approved Regions [Default]

- us-east-1
- us-east-2
- us-west-2
- eu-west-1

Wildcards are supported -- us-* matches all US regions:

- us-*
- eu-west-1

Approved Instance Types

AWS > RDS > DB Instance > Approved > Instance Classes

- db.m5.2xlarge
- db.t3.*

The wildcard db.t3.* matches all t3 instance sizes (db.t3.micro, db.t3.small, db.t3.medium, etc.).

Approved Database Engines

AWS > RDS > DB Instance > Approved > Database Engines

- aurora
- mariadb
- postgresql

Approved AMI IDs

AWS > EC2 > Instance > Approved > Image > AMI IDs

- ami-jc81a385
- ami-fa345678

Key-Value Pair Lists

Some policies accept lists of key-value pairs. The most common use case is tag templates, where each entry defines a tag key and its desired value.

Tag Templates

AWS > S3 > Bucket > Tags > Template

- Cost Center: "Security"
- Environment: "Production"
- Account Owner: "Gary Anderson"

Each entry becomes a tag on the resource. When the Tags control runs, it ensures these tags exist with the specified values.

Removing a tag -- set the value to null:

- Cost Center: "Security"
- Environment: "Production"
- ObsoleteTag: null

Setting a tag to null tells Guardrails to remove it from the resource. This is how you clean up tags that are no longer needed.

Updating a tag key -- use the undefined reserved value to remove the old key and add the new one:

- CostCenter: undefined
- Cost Center: "Security"

The undefined value marks the old key for removal. See Tagging for more on tag template behavior.

Permission Modifiers

AWS > EC2 > Permissions > Levels > Modifiers

- "ec2:createtags": admin
- "ec2:deletetags": admin

Each entry maps an API action to a minimum permission level. This restricts who can perform these actions -- only users with admin level or higher can call ec2:CreateTags or ec2:DeleteTags.

S3 Public Access Block Settings

AWS > S3 > Account > Public Access Block > Settings

- "Block Public ACLs"
- "Block Public Bucket Policies"
- "Ignore Public ACLs"
- "Restrict Public Bucket Policies"

Nested Structures

Some policies require nested YAML with maps, sub-keys, and complex objects.

Change Window Schedules

Turbot > Change Window > Schedule

- name: Daily
  description: "Daily, 12am - 5am UTC"
  cron: "0 0 * * *"
  duration: 5
- name: Weekend
  description: "Weekly, Saturdays 6am - 6pm UTC"
  cron: "0 6 * * SAT"
  duration: 12

Each schedule entry is an object with name, description, cron (when the window opens), and duration (how many hours it stays open). All times are UTC.

Budget Lockdown APIs

AWS > Account > Permissions > Lockdown > Budget > Restricted APIs

critical:
  - ec2:RunInstance
  - ec2:StartInstance
  - rds:StartDB*
  - redshift:createcluster

This uses a nested map where the key (critical) is the budget state and the value is a list of API actions to restrict when the account enters that state. Wildcards (*) are supported in API action names.

Notification Filter Rules

Turbot > Notifications > Rule-Based Routing

- rules: "NOTIFY $.oldControl.state:ok $.control.state:alarm"
  emails:
    - [email protected]
  slackWebhookUrl: "https://hooks.slack.com/services/XXXXXXX/YYYYYYYYYY/ZZZZZZZZZZZZZZ"

Each entry combines a rule expression (using NOTIFY/IGNORE syntax similar to OCL) with delivery targets. Rules can span multiple lines using the YAML pipe (|) operator:

- rules: |
    NOTIFY $.actionType.parent:'#/resource/types/securityGroup'
    NOTIFY $.actionType.uri:'tmod:@turbot/aws-vpc-security#/control/types/securityGroupApproved'
  emails:
    - [email protected]

Tag Transform Rules

Turbot > Tags > Transform Rules

Tag transform rules use deeply nested YAML to define how incorrect tag keys and values should be corrected:

environment:
  incorrectKeys:
    - Env
    - ENV
  replacementValue: undefined
  values:
    production:
      incorrectValues:
        - prod
        - prd
        - PROD
    development:
      incorrectValues:
        - dev
        - DEV
cost_center:
  incorrectKeys:
    - CostCenter
    - costcenter
  replacementValue: undefined
  values:
    SCR1138:
      incorrectValues:
        - scranton-1138

Regex patterns are supported in both incorrectKeys and incorrectValues:

environment:
  incorrectKeys:
    - /env.*/gi
  values:
    production:
      incorrectValues:
        - /pr.*/gi

See Tagging Helpers for the complete transformMap reference.

YAML in Terraform

When managing policies as code with Terraform, YAML values are passed as strings using heredoc syntax:

resource "turbot_policy_setting" "approved_regions" {
  resource = turbot_policy_pack.baseline.id
  type     = "tmod:@turbot/aws#/policy/types/approvedRegionsDefault"
  value    = <<-EOT
    - us-east-1
    - us-east-2
    - us-west-2
  EOT
}

resource "turbot_policy_setting" "tag_template" {
  resource = turbot_policy_pack.baseline.id
  type     = "tmod:@turbot/aws-s3#/policy/types/bucketTagsTemplate"
  value    = <<-EOT
    - Cost Center: "Security"
    - Environment: "Production"
  EOT
}

For more complex Terraform examples including calculated policies that output YAML tag templates, see Tagging with Terraform.

Next Steps