DevOpsAnywhere

Remote DevOps, SRE & platform jobs, worldwide.

Guides

Terraform interview questions for remote DevOps roles

By the DevOpsAnywhere team · Published December 2, 2026

Terraform in remote DevOps listings

Terraform is the infrastructure-as-code tool remote DevOps roles ask for most. On 2 December 2026, 140 of the 539 roles on DevOpsAnywhere named it. The details in their descriptions point at what interviews cover: 35 mention state, 23 policy or compliance, and 22 modules. Alternatives come up less: Pulumi in 10 descriptions and CloudFormation in 10. The Terraform DevOps salary page shows a median of $173,000 a year across 35 roles that stated a salary.

Interviewers usually start with how Terraform works, then move to how a team uses it safely.

Core concepts

"What does Terraform actually do when you run plan and apply?"

It reads your configuration, refreshes its view of the real resources through the providers' APIs, compares both with the state file, and builds a dependency graph. plan shows the difference: what will be created, changed, replaced or destroyed. apply makes those changes in dependency order, in parallel where possible, and records the result in state.

"What is the state file, and why does it matter?"

State maps each resource in your configuration to a real object (an ID in the cloud) and stores its attributes. Without it, Terraform can't know what it manages. Follow-ups:

  • Store it remotely (S3, Azure Storage, GCS or Terraform Cloud) so the team shares one copy.
  • Lock it (S3's native lock file or DynamoDB, or the backend's own locking) so two applies can't run at once.
  • Protect it: it can contain secrets in plain text, so encrypt it and restrict access.

"What does 'replace' mean in a plan, and why is it dangerous?"

Some attribute changes can't be made in place, so Terraform destroys the resource and creates a new one. For a database or a load balancer, that means downtime or data loss. Read every plan for replacements, use create_before_destroy where possible, and prevent_destroy on critical resources.

Structure and modules

"How do you structure Terraform code for several environments?"

Two common approaches:

  • A directory per environment (envs/prod, envs/staging), each with its own backend and state, calling shared modules with different variables. Explicit and hard to mix up.
  • Workspaces, one configuration with several states. Simple, but it's easy to apply to the wrong one, and every environment must have the same shape.

Most teams prefer directories (or a wrapper such as Terragrunt) for environments, and keep state small: one state per environment and per area (network, data, each application), so a mistake can't affect everything.

"What makes a good module?"

A clear purpose, a small set of input variables with types, validation and sensible defaults, useful outputs, and no hard-coded provider configuration. Version it (a Git tag or a registry version), so changes roll out deliberately. Avoid modules that only wrap a single resource without adding anything.

"count or for_each?"

for_each with a map or set of strings. With count, removing an item from the middle of a list shifts every index, so Terraform wants to destroy and recreate the resources after it. With for_each, each resource is keyed by a stable name.

Working as a team

"How does Terraform run in your CI/CD pipeline?"

On a pull request: fmt -check, validate, linting (tflint), a security scan (Checkov, Trivy or similar), and plan, with the plan posted to the pull request for review. On merge: apply of that reviewed plan, from the pipeline only, using short-lived credentials (OIDC from the CI system to the cloud) rather than stored keys. Tools such as Atlantis or Terraform Cloud manage this flow.

"How do you enforce policy?"

Policy as code checks plans before apply: OPA with Conftest, Sentinel in Terraform Cloud, or the rules in scanning tools. Typical rules: no public storage buckets, required tags, allowed regions and instance types, encryption on. It came up in 23 of the descriptions, usually alongside compliance.

Problems and recovery

"Someone changed a resource in the console. What happens, and what do you do?"

The next plan shows drift and proposes reverting it to the configuration. Decide whether the manual change was right: if yes, update the code to match. If not, apply to revert. Then prevent it: read-only console access in production, and a scheduled plan that reports drift.

"How do you bring existing resources under Terraform?"

With import blocks (Terraform 1.5 and later) in the configuration, which plan can also use to generate starting code. Then adjust the code until the plan shows no changes. The older terraform import command still works, one resource at a time.

"How do you rename or move a resource without destroying it?"

A moved block in the configuration, reviewed through the normal plan. terraform state mv does the same by hand, but leaves no record in code.

"The state is locked and the person who ran apply has gone home."

Check that no apply is actually running (pipeline logs, the lock's details). Only then force-unlock with the lock ID. Then fix the cause, usually a run that was cancelled mid-way.

"How do you handle secrets in Terraform?"

Don't put them in code or .tfvars files in Git. Read them from a secrets manager through a data source, or generate them and store them there. Mark variables and outputs sensitive, and remember state still holds the values, so it needs the same protection as the secrets themselves. Ephemeral values in recent Terraform versions help keep some out of state.

Comparisons

"Terraform, OpenTofu, Pulumi or CloudFormation?"

  • Terraform: declarative HCL, a huge provider ecosystem, works across clouds. Licensed under the Business Source License since 2023.
  • OpenTofu: the open-source fork, largely compatible.
  • Pulumi: infrastructure in general-purpose languages (TypeScript, Python, Go), handy for complex logic and testing, but code can become harder to review.
  • CloudFormation: AWS only, managed state, and features available on day one for AWS services.

A good answer chooses by team and context, not by preference. The guide to the DevOps tools remote jobs ask for covers where Terraform fits with the rest.

A task to rehearse

"Write Terraform for an S3 bucket (or storage account) that is private, encrypted and versioned, as a reusable module." Use variables with types, sensible defaults, outputs, tags, and explain how you would test it: terraform test or Terratest, plus a policy check in CI.

The open roles below name Terraform.

Open remote DevOps roles that use Terraform

  1. Senior DevOps Engineersustaind GmbH · Berlin
  2. AWS DevOps Engineer (Freelancer)Mactores · USA
  3. Sr Staff Site Reliability EngineerCribl · Remote - Australia
  4. Sr DevOps EngineerBeyondTrust · Remote Canada
  5. Senior DevOps (m/w/d)Skoobe · Berlin

More guides