Managing Policies

Policies allow you to define configuration settings in Guardrails and apply them across your environment. Guardrails' hierarchical structure provides a powerful but simple mechanism for centralizing policy administration, along with managing exceptions. Every control relies on one or more policies to determine what to check and how to respond, making policy management the foundation of your governance strategy.

Best Practices

Before diving into the how-to guides, keep these principles in mind to avoid surprises and minimize ongoing maintenance.

Use Policy Packs Instead of Direct Settings

Whenever possible, define your policy settings inside a Policy Pack rather than creating them directly on individual resources. Policy packs are reusable, auditable, and easy to manage. You can attach the same pack to multiple accounts or folders, detach it cleanly, and version it as code with Terraform. Direct settings on individual resources are harder to track, don't scale, and quickly become unmanageable in larger environments.

Minimize Administration by Leveraging the Policy Hierarchy

Create policy settings as high as possible in the resource hierarchy and manage exceptions below. For example, set a tagging standard at the folder level and only override it for specific accounts that need different treatment.

Review and Set ALL Sub-Policies Before Enabling a Control

Many controls such as Active, Approved, and Tags use multiple policies to determine their behavior. To avoid unwanted changes, make sure all of these dependent sub-policies are configured before enabling the control.

For example, before setting AWS > EC2 > Instance > Approved to Enforce: Delete unapproved if new, review and set all sub-policies first: Instance Types, Public IP, Regions, Usage, and others. Enabling the parent control without configuring the sub-policies may cause resources to be flagged or deleted based on default values you didn't intend.

Preview Changes by Setting a Policy to Check Before Enforce

Creating a policy setting is a powerful action. A single setting may affect thousands of resources. Setting the policy to Check first helps you determine the impact before enforcement is enabled.

For example, set AWS > EC2 > Instance > Approved > * sub-policies to define your approval criteria, then set the parent to Check: Approved. Review the resulting alarms across your environment. Once you're confident the criteria are correct, switch to Enforce: Delete unapproved to begin enforcement.

Policy Settings

Policy settings tell Guardrails what to do with a specific policy type at a specific point in the resource hierarchy. You can set a simple static value, or use a calculated policy to dynamically compute the value based on resource metadata.

GuideDescription
Create a Policy SettingCreate a new policy setting on a resource using the Guardrails console or Terraform.
Create a Calculated PolicyUse GraphQL queries and Nunjucks templates to dynamically compute policy values based on resource data.
Update a Policy SettingChange the value, precedence, or other attributes of an existing policy setting.
Delete a Policy SettingRemove a policy setting and revert to the inherited or default value.
Create an ExceptionOverride a required policy setting for a specific resource lower in the hierarchy.

Calculated Policies

Calculated policies let you dynamically determine a policy's value based on the actual properties of each resource in scope, rather than applying a single fixed value to everything. They are defined by two components:

  1. A GraphQL query that automatically pivots to the current resource, simplifying the query syntax. You write the query once, and Guardrails runs it against each resource individually, so a query like { resource { tags } } returns the tags for whichever resource is being evaluated.

  2. A Nunjucks template that defines the logic to parse the query response and output a valid policy value. The template receives the query results and uses conditional logic to produce the final value (e.g., Check: Enabled for production resources, Skip for everything else).

This combination is powerful. You can create a single policy setting that behaves differently for thousands of resources based on their tags, configuration, region, or any other queryable attribute.

For a step-by-step walkthrough, see Create a Calculated Policy.

Policy Packs

Policy packs enable administrators to apply one or more policies across multiple accounts and/or resources, automating what would otherwise be a time-consuming manual process of creating individual policy settings on each resource. The policies a pack defines govern all resources below the attachment point in the hierarchy.

Attachment order matters. Guardrails resolves policies by starting at the resource and ascending the resource hierarchy towards the root. The closest policy setting to the resource wins. When multiple policy packs are attached at the same level, the order of attachment determines precedence. Packs attached later take priority over those attached earlier.

[!NOTE] Policy pack attachments and detachments are heavy database operations if the policy pack is attached to many resources or contains many policies. Be mindful when making large policy or attachment changes. Consider breaking them into smaller batches to reduce the impact on your workspace.

GuideDescription
Create a Policy PackCreate a new policy pack with a title and description.
Attach a Policy PackAttach a policy pack to a resource so its settings take effect.
Detach a Policy PackRemove a policy pack from a resource.
Modify a Policy PackAdd settings, edit the title and description, or delete a policy pack.
Policy Packs as CodeCreate and manage policy packs with Terraform, and contribute to the Guardrails Hub.

Policy Examples

For detailed policy configuration examples (including OCL rules, YAML templates, RDS approved configurations, S3 access logging, AMI management, and Azure tagging at scale), see Policy Configuration Examples.

Further Reading