[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-en-terraform-best-practices":3},{"id":4,"title":5,"body":6,"category":167,"date":168,"description":169,"extension":170,"image":171,"meta":172,"navigation":181,"path":182,"readTime":183,"seo":184,"stem":185,"__hash__":186},"blog_en/blog/en/terraform-best-practices.md","Terraform Best Practices for Infrastructure as Code",{"type":7,"value":8,"toc":146},"minimark",[9,13,17,22,25,30,33,37,40,51,55,59,62,78,82,85,89,93,96,110,114,117,121,125,132,136,139,143],[10,11,5],"h1",{"id":12},"terraform-best-practices-for-infrastructure-as-code",[14,15,16],"p",{},"Infrastructure as Code (IaC) has revolutionized how we manage cloud resources. Terraform, with its declarative syntax and extensive provider ecosystem, has become the industry standard. Here are the practices I've developed over years of managing infrastructure at scale.",[18,19,21],"h2",{"id":20},"state-management","State Management",[14,23,24],{},"Terraform state is the source of truth for your infrastructure. Treat it with care:",[26,27,29],"h3",{"id":28},"remote-state-is-non-negotiable","Remote State is Non-Negotiable",[14,31,32],{},"Always use remote state storage (S3, Azure Blob, GCS) with state locking. Local state is only acceptable for personal experiments.",[26,34,36],{"id":35},"state-structure","State Structure",[14,38,39],{},"Organize your state files thoughtfully:",[41,42,47],"pre",{"className":43,"code":45,"language":46},[44],"language-text","terraform/\n├── environments/\n│   ├── prod/\n│   ├── staging/\n│   └── dev/\n├── modules/\n│   ├── vpc/\n│   ├── compute/\n│   └── database/\n","text",[48,49,45],"code",{"__ignoreMap":50},"",[18,52,54],{"id":53},"code-organization","Code Organization",[26,56,58],{"id":57},"module-design","Module Design",[14,60,61],{},"Create reusable modules with clear interfaces:",[63,64,65,69,72,75],"ul",{},[66,67,68],"li",{},"Expose only necessary variables",[66,70,71],{},"Provide sensible defaults",[66,73,74],{},"Document all inputs and outputs",[66,76,77],{},"Version your modules",[26,79,81],{"id":80},"workspace-vs-directory-structure","Workspace vs. Directory Structure",[14,83,84],{},"For most use cases, directory-based environments are clearer than workspaces. They're more explicit and easier to understand for team members.",[18,86,88],{"id":87},"security-practices","Security Practices",[26,90,92],{"id":91},"secrets-management","Secrets Management",[14,94,95],{},"Never commit secrets to your repository. Use:",[63,97,98,101,104,107],{},[66,99,100],{},"HashiCorp Vault",[66,102,103],{},"AWS Secrets Manager",[66,105,106],{},"Azure Key Vault",[66,108,109],{},"Environment variables for CI/CD",[26,111,113],{"id":112},"least-privilege","Least Privilege",[14,115,116],{},"Apply the principle of least privilege to your Terraform execution roles. Separate plans from applies using different credentials.",[18,118,120],{"id":119},"cicd-integration","CI/CD Integration",[26,122,124],{"id":123},"automated-planning","Automated Planning",[14,126,127,128,131],{},"Run ",[48,129,130],{},"terraform plan"," on every pull request. This provides visibility into infrastructure changes before they're applied.",[26,133,135],{"id":134},"approval-gates","Approval Gates",[14,137,138],{},"Require manual approval for production changes. Automated deployments to production infrastructure are risky.",[18,140,142],{"id":141},"conclusion","Conclusion",[14,144,145],{},"Good Terraform practices are about more than just working code—they're about maintainability, security, and team collaboration. Invest time in setting up proper patterns early; it pays dividends as your infrastructure grows.",{"title":50,"searchDepth":147,"depth":147,"links":148},2,[149,154,158,162,166],{"id":20,"depth":147,"text":21,"children":150},[151,153],{"id":28,"depth":152,"text":29},3,{"id":35,"depth":152,"text":36},{"id":53,"depth":147,"text":54,"children":155},[156,157],{"id":57,"depth":152,"text":58},{"id":80,"depth":152,"text":81},{"id":87,"depth":147,"text":88,"children":159},[160,161],{"id":91,"depth":152,"text":92},{"id":112,"depth":152,"text":113},{"id":119,"depth":147,"text":120,"children":163},[164,165],{"id":123,"depth":152,"text":124},{"id":134,"depth":152,"text":135},{"id":141,"depth":147,"text":142},"DevOps","2024-11-28","Essential patterns and practices for managing infrastructure at scale using Terraform.","md","https://images.unsplash.com/photo-1558494949-ef010cbdcc31?w=1200&h=675&fit=crop",{"tags":173,"author":177,"locale":178,"slug":179,"draft":180,"sitemap":181},[174,175,167,176],"Terraform","IaC","Cloud","Aboubakar Sidik Faha","en","terraform-best-practices",false,true,"/blog/en/terraform-best-practices",6,{"title":5,"description":169},"blog/en/terraform-best-practices","_323PkT3OVblDRnpCbfrEAe66nmFLZ6Vc33xgTRjMTc"]