Home / Insights / Platform Engineering
Infrastructure as Code with Terraform
Terraform is an open-source tool from HashiCorp that allows you to define cloud infrastructure using a high-level configuration language. By writing declarative code, you can manage and provision infrastructure in a predictable and consistent way, across virtually every major cloud provider.
Further reading: Terraform Official Docs
Core Concepts
- Providers — plugins that translate Terraform configuration into API calls for a specific platform (AWS, GCP, Azure, Kubernetes, and hundreds more).
- Resources — the individual infrastructure objects you define, such as a virtual machine, a storage bucket, or a DNS record.
- State — Terraform's record of what it believes exists in the real world, used to compute the diff between your configuration and reality on every run.
- Modules — reusable, parameterized groups of resources that let teams standardize patterns instead of copy-pasting configuration.
The Core Workflow
terraform init downloads providers and configures the backend. terraform plan shows exactly what will change before anything happens. terraform apply executes that plan. terraform destroy tears infrastructure back down. This plan-before-apply loop is what makes Terraform safer than ad hoc console changes — nothing happens without a reviewable diff first.
State Management
For anything beyond solo experimentation, state should live in a remote backend (S3 with DynamoDB locking, Terraform Cloud, or equivalent) rather than a local file. Remote state with locking prevents two people from applying conflicting changes simultaneously and keeps state out of version control, where it could leak sensitive values.
Best Practices
Keep environments (dev/staging/prod) isolated via separate state files or workspaces rather than a single sprawling configuration. Pin provider and module versions to avoid surprise upgrades. And treat terraform plan output as a required part of code review — the plan is the real diff, not just the .tf file changes.
Questions about your architecture? Reach us at accounts@stackgrains.com.
Working on something like this?
StackGrains builds and operates cloud-native products end to end — architecture, delivery, and 24/7 operations. Tell us what you are building and we will give you an honest read on the approach.
Email accounts@stackgrains.com Explore services