Back to Rules
DevOps

Terraform Best Practices for Cloud IaC: Modules, Security, CI/CD & Optimization

Claude Directory November 29, 2025
2 copies 2 downloads

Master Terraform for Infrastructure as Code with proven best practices on modules, state management, security, performance, and CI/CD integration for AWS, Azure, and GCP.

Rule Content
1. **Adopt remote state storage**: Configure backends like S3, Azure Blob, or GCS to store Terraform state securely, enabling team collaboration, state locking to prevent concurrent modifications, and encryption for data protection.

2. **Implement workspaces for environments**: Separate dev, staging, and prod environments using workspaces to isolate state files and avoid cross-contamination during deployments.

3. **Organize resources modularly**: Group resources by service (e.g., networking, compute) and create reusable modules to reduce code duplication, improve maintainability, and support scaling.

4. **Enforce code formatting and validation**: Run `terraform fmt` for consistent styling, `terraform validate` for syntax checks, and tools like tflint or terrascan to detect issues early in the development cycle.

5. **Parameterize with variables and validation**: Define variables for all configurable values, add validation blocks to ensure valid inputs, and use conditionals or null_resource for optional features and edge cases.

6. **Secure sensitive data**: Never hardcode secrets; integrate with Vault, AWS Secrets Manager, or Azure Key Vault, and apply encryption, security groups, and least-privilege access controls to resources.

7. **Version providers and modules**: Pin provider versions in the required_providers block and use semantic versioning for custom modules to guarantee reproducible builds and avoid unexpected changes.

8. **Leverage outputs and dependencies**: Expose module outputs for cross-module communication and use `depends_on` for explicit resource ordering when implicit dependencies are insufficient.

9. **Optimize performance**: Employ `-target` for targeted applies, cache providers locally, and use `count` or `for_each` judiciously to minimize resource proliferation.

10. **Integrate with CI/CD and testing**: Automate `terraform plan` in pipelines like GitHub Actions, add terratest for module unit tests, and verify critical paths like networking and IAM.

11. **Apply consistent tagging**: Tag all resources for cost allocation, tracking, and compliance, following cloud-specific guidelines for AWS, Azure, or GCP.

12. **Document thoroughly**: Include README.md files in modules detailing inputs, outputs, examples, and usage to facilitate onboarding and maintenance.

Comments

More Rules

View all
AI/ML

GLM-4.7 Optimized Config & System Prompt Designer

Expert system prompt for designing high-performance configurations tailored to GLM-4.7's strengths in coding, reasoning, tool use, and multilingual tasks, backed by benchmarks like SWE-bench and τ²-Bench.

C
Community
AI/ML

GLM-4.7 Open-Source Coding Expert: Optimized System Prompt

Leverage GLM-4.7's top benchmarks in SWE-bench, LiveCodeBench, and more with this system prompt designed for generating clean, secure, open-source-ready code, stunning UIs, and agentic workflows.

C
Community
AI/ML

GLM-4.7 Optimized Coding Agent

This system prompt transforms an AI into GLM-4.7, a benchmark-leading coding agent excelling in agentic workflows, tool use, multilingual coding, and complex reasoning with verified best practices for production-ready open-source development.

C
Community
DevOps

Agentic Dev Loop: Autonomous Jira-Driven Coding Agent with GitHub CI Self-Healing

Ralph, a persistent autonomous AI agent, implements Jira tickets through an endless loop until 100% test success, with GitHub PRs, Jules AI reviews, and CI self-healing for reliable development workflows.

C
Claude Directory
AI/ML

Türk Hukuku Uzmanı AI Agent: Güvenilir Yasal Danışman System Prompt

Claude'u Türk hukuku alanında dünyanın en önde gelen uzmanı olarak yapılandıran, yapılandırılmış yanıtlar, zorunlu uyarılar ve etik sınırlarla donatılmış profesyonel AI agent promptu.

C
Community
Database

PostgreSQL Best Practices: Expert Subagent Guide

Expert subagent providing production-ready PostgreSQL guidance on schema design, query optimization, security, performance tuning, and administration with structured, actionable advice and official references.

C
Claude Directory