A Terraform setup a small team can live with keeps state remote and locked, splits it into one state per environment and component, and uses a plain folder layout with modules only for things you repeat. Pin your provider and module versions, run plan on every pull request and apply only from CI, keep secrets out of code and state, and check for drift on a schedule.
A small team does not need a platform. You need infrastructure that anyone on the team can change safely on a Tuesday afternoon, that does not break when one person is on leave, and that a new hire can understand in a day.
That means boring choices: one obvious place for each piece of infrastructure, changes reviewed like code, and no step that only works from someone's laptop. The rest of this article is how to get there.
Not on a laptop and not in Git. State is the record of what Terraform manages, and it often contains sensitive values in plain text. Put it in a remote backend: an S3 bucket on AWS, a Cloud Storage bucket on GCP, or a managed service such as HCP Terraform.
Turn on locking so two people, or two CI jobs, cannot apply at the same time and corrupt the state. On GCS, locking is built in. On S3, recent Terraform versions can lock using a lock file stored in the same bucket, while older setups use a DynamoDB table for locks. Check which your Terraform version supports and pick one. Either way, enable versioning and encryption on the bucket and restrict who can read it.
Use one state per environment, and within each environment, one state per component that changes at a different pace. Networking changes rarely. Databases change carefully. Application services change often. Putting them in separate states means a routine service change cannot accidentally touch your VPC, and plans stay fast and readable.
Do not go too far the other way. Ten tiny states per environment with a web of dependencies between them is its own kind of pain. For most small teams, three to five components per environment is plenty.
Keep it flat and obvious. Each folder that you run Terraform in is one state. A layout like this is enough for most teams:
Each environment folder has its own backend configuration and its own variable values. Differences between staging and production are visible in the files, not hidden in flags someone has to remember to pass.
When you have written the same thing at least twice and expect to write it again. Not before. A module you design up front guesses at what will vary, and the guesses are usually wrong, so you end up with dozens of input variables and conditional logic that nobody wants to touch.
Start by writing resources directly in the component folders. When a pattern repeats, such as every service needing the same task definition, log group, alarms and IAM role, pull it into a module. Prefer well-maintained public modules for common building blocks only if you read what they create, and keep your own modules small.
Yes. Set a required Terraform version and version constraints for each provider, and commit the dependency lock file that Terraform generates. Pin modules to a specific version or Git tag, not a branch. Otherwise a provider release can change behaviour between your plan on Monday and your apply on Thursday.
Upgrade on purpose, one thing at a time, in a pull request where you can read the plan. A dependency update bot can open these pull requests for you.
Run plan automatically on every pull request that touches a Terraform folder, and post the plan output where reviewers can see it. Reviewers approve the plan, not just the code. After merge, apply runs from CI using the same plan, with a manual approval step for production.
Give CI its own cloud role with the permissions it needs, using short-lived credentials such as OIDC federation from your CI provider rather than long-lived access keys. Then remove write access to infrastructure from individual laptops, except for a documented break-glass role.
| Practice | Why it matters | What to do |
|---|---|---|
| Remote state with locking | Prevents lost or corrupted state | S3 or GCS bucket with locking, versioning and encryption |
| One state per environment and component | Small blast radius, fast plans | One folder per component per environment |
| Pinned versions | Same code gives the same result | Version constraints plus a committed lock file |
| Plan on every pull request | Reviewers see real changes | CI posts plan output to the pull request |
| Apply only from CI | One audited path to production | CI role with short-lived credentials, approval for prod |
| Scheduled drift checks | Catches console changes early | Nightly plan that alerts when changes appear |
Never put secrets in .tf files or committed variable files. Store them in a secrets manager, such as AWS Secrets Manager, GCP Secret Manager or Vault, and have your applications read them at runtime.
Be aware that any value Terraform reads or creates can end up in state, even if you mark it as sensitive. Marking a value sensitive hides it from plan output, not from the state file. Where you can, let Terraform create the secret container and set its value outside Terraform, or let the cloud service generate and manage the password. Newer Terraform versions add features for keeping some values out of state, so check what your version supports. And treat state access as access to secrets.
Drift is when real infrastructure no longer matches your code, usually because someone fixed something in the console during an incident. Run plan on a schedule, for example nightly, against every state. Running plan with the detailed exit code option tells you whether changes are pending, and you can alert on that. When drift shows up, either bring the change into code or revert it. Do not let it sit.
Pick a naming pattern once, such as environment, component and purpose, and apply it everywhere. Then tag every resource with the same small set of keys: environment, service, team or owner, and cost centre if finance needs it.
On AWS, the provider's default tags setting applies tags to every resource it supports without repeating them in each block. GCP uses labels in a similar way. Remember to activate your tag keys as cost allocation tags in AWS Billing, or they will not show up in cost reports. Good tags are what let you answer "what does staging cost?" without guessing.
For most small teams, no. CLI workspaces share the same code and backend, which makes it easy to apply to the wrong environment. Separate folders per environment make differences visible and the target obvious.
In a remote backend with locking, such as an S3 or GCS bucket or HCP Terraform, with versioning and encryption enabled. Never commit state to Git, because it can contain secrets in plain text.
In CI. Run plan on every pull request, review the plan, and apply from CI after merge with approval for production. Keep a documented break-glass role for emergencies.
Run terraform plan on a schedule against each state and alert when it reports pending changes. Then either update the code to match the change or revert the manual change.
Talk to the engineers who do this work every week. Replies within one working day.