Prompt
How do I enforce approved infrastructure patterns across teams with IaC?
Latest observation
To enforce approved infrastructure patterns across teams with IaC, treat “patterns” as products and use policy + reusable modules + automation to make the right thing the easy thing.
1) Standardize on approved building blocks
Create a small catalog of “blessed” components, such as:
- VPC/network baseline
- Kubernetes cluster baseline
- app service / container service baseline
- database baseline
- IAM baseline
- logging/monitoring baseline
Package these as:
- Terraform modules
- CloudFormation/SAM templates
- Pulumi components
- Crossplane Compositions
- or platform templates if you use something else
Design them to be opinionated:
- default tags/labels
- required encryption
- logging enabled
- private networking by default
- guardrails on instance types/regions
- standard naming conventions
2) Make module usage mandatory
Don’t let teams build raw resources when a standard module exists.
Ways to do that:
- Restrict repository access to platform-approved modules only
- Create a “golden path” repo template that references modules
- Use code review rules requiring module usage for certain resource types
- Set org-level standards: “no direct creation of X; must use module Y”
3) Add policy-as-code guardrails
Use policy to block noncompliant infra before it reaches cloud.
Common tools:
- OPA/Conftest
- Terraform Cloud/Enterprise Sentinel
- AWS Organizations SCPs
- Azure Policy
- GCP Organization Policies
- Kyverno / Gatekeeper for Kubernetes
- Checkov / tfsec / Terrascan for static checks
Examples of policy rules:
- Only approved regions
- Mandatory encryption at rest
- No public S3 buckets/storage accounts
- No inbound 0.0.0.0/0 on sensitive ports
- Required tags/labels
- Only approved VM sizes
- Approved container registries only
Use a layered approach:
- Pre-commit: quick checks
- CI: policy validation on every PR
- Plan/apply gate: block noncompliant changes
- Cloud-level guardrails: stop drift or out-of-band changes
4) Validate at plan time, enforce at apply time
In CI/CD:
terraform fmtterraform validate- security/compliance scan
- policy evaluation against the plan
- approval gate if needed
- apply only if checks pass
This catches violations before deployment, which is cheaper and easier than remediating later.
5) Use drift detection and auto-remediation
Even if teams start compliant, drift happens.
Implement:
- scheduled drift detection
- cloud configuration monitoring
- automatic rollback or alerting for certain violations
- periodic re-scans against policies
For high-risk patterns, consider auto-remediation:
- public bucket → make private
- missing encryption → flag or patch
- missing tags → add via wrapper or platform automation
6) Separate “platform control” from “team customization”
Give teams flexibility only where it’s safe.
Pattern:
- Platform team owns the core module
- Teams can configure a limited set of inputs
- Sensitive settings are not exposed or are constrained
- Add validation on inputs to enforce ranges/enums
Example:
- allow team to choose app name, size tier, environment
- disallow custom CIDRs, public exposure, unsupported regions, custom IAM policies
7) Centralize standards in CI/CD pipelines
If every team has its own pipeline, standards drift.
Best practice:
- provide a shared pipeline template
- centralize policy checks, scanning, approvals
- require deployment through approved pipelines
- publish pipeline as a service rather than letting every team invent their own
8) Track exceptions with a formal waiver process
Not every exception is bad, but it should be deliberate.
Create:
- documented exception workflow
- expiration date on waivers
- risk owner approval
- audit trail
- periodic review of exceptions
This prevents “temporary exceptions” from becoming permanent.
9) Measure adoption and noncompliance
Track:
- percent of infra using approved modules
- number of policy violations by team
- drift incidents
- exception count
- time-to-remediate violations
This helps you find where teams need support versus enforcement.
10) Make it easy to consume
If the approved patterns are painful, teams will bypass them.
Invest in:
- clear docs
- examples
- versioned modules
- one-command scaffolding
- internal registry/catalog
- changelogs and upgrade guides
- office hours / support channel
A practical operating model
A good mature setup looks like this:
- Platform team defines approved patterns and owns modules/policies
- Security/compliance defines non-negotiable controls
- App teams consume approved modules via templates
- CI/CD validates, scans, and blocks noncompliance
- Cloud org controls enforce baseline restrictions
- Exception process handles rare cases
Recommended implementation order
If you’re starting from scratch:
- Define 5–10 critical infrastructure standards
- Build blessed modules for those standards
- Add CI policy checks to all repos
- Enforce cloud org guardrails
- Roll out shared pipeline templates
- Add drift detection
- Establish exception workflow and metrics
Example rule set
For a typical enterprise, you might enforce:
- approved regions only
- mandatory encryption everywhere
- private-by-default networking
- centralized logging
- mandatory tags: owner, environment, cost-center, data-classification
- no wildcard IAM permissions without approval
- no public endpoints unless explicitly approved
- only approved base images and registries
If you want, I can also give you:
- a Terraform-based reference architecture
- a policy-as-code example
- or a step-by-step rollout plan for a platform team.