Skip to main content

Policies

Use policies to regulate Atmos's execution lifecycle: control component operations and require hooks at lifecycle events. For Terraform, use policies to inspect plan changes and reject operations that violate your rules. Policies use CEL expressions or Starlark function bodies and load from policy.d/ by default, with ATMOS_POLICY_DIR available as an override. Use tag and label selectors to attach rules to instances.

Experimental

Choose an input​

Input kindComponentsEvaluated whenActions
functionConfiguration loading and resolutionBefore YAML function execution and Go-template callsdeny, require_approval
sourceImports, downloads, includes, and guarded template accessBefore accessing each guarded source destinationdeny, require_approval
commandAll runnable CLI commandsBefore argument validation and pre-run hooksdeny, require_approval
component.commandShared stack resolutionBefore component templates/functions and tool executiondeny, require_approval
terraform.planTerraform / OpenTofuAfter a successful saved plan and before saved-plan applydeny, require_approval
operationTerraform, Helmfile, Helm, KubernetesAt the component's lifecycle hook eventsdeny, hooks, require_approval
atmos.affectedAll supported inventory typesDuring explicit affected analysis, before filtering or schedulingdeny, require_approval

GitHub Actions context is available to all kinds. Admission, plan, and lifecycle rules run regardless of --affected; affected rules run only when affected analysis is requested. Component configuration validation uses the separate settings.validation configuration.

Quick start​

Create a policy file:

policy.d/terraform.yaml
apiVersion: atmos/v1
kind: Policy
metadata:
name: safety
description: Prevent accidental deletion or replacement of managed resources.
spec:
policies:
prevent-deletion:
on: terraform.plan
action: deny
reason: Resources must not be deleted or replaced
rule: >-
has(input.resource_changes) && input.resource_changes.exists(r,
r.mode == 'managed' && 'delete' in r.change.actions)

Run a plan from the directory containing policy.d/:

atmos terraform plan vpc -s dev

A matching rule blocks the command, names itself in the error, and exits with code 77. A plan containing no managed-resource deletions passes this rule. To apply a passing saved plan:

atmos terraform apply vpc -s dev --from-plan

For CI enforcement, load policies from a protected source, not an unreviewed pull-request checkout.

Reference​

Browse the Policy Library for individual policies, parameters, and tested input cases. Each policy offers CEL and Starlark tabs backed by the same test fixtures. Copy one implementation; the selected language is remembered across library pages.

PageContents
LibrarySearchable catalog with CEL/Starlark implementations and shared tests per policy
ConfigurationDirectory loading, manifest fields, rule actions, enforcement setup
Inputs and ExpressionsCEL variables, operation fields, missing values, evaluation results
Sources and FilesystemSource transports, destinations, and local path confinement
StarlarkFunction bodies, read-only inputs, loops, helpers, and execution limits
Terraform PlansPlan JSON, saved-plan commands, failure handling
Affected ChangesFile, instance, component, stack, and structured-field changes
HooksHook definitions, selection, execution and success requirements
CI ContextGitHub event data, metadata, required inputs, permissions
ExamplesTested policy configurations to copy and adapt