Interview Q&A · questions with model answers
Terraform Interview Questions
Part of the study plan for: DevOps Engineer · Cloud Engineer · Site Reliability Engineer (SRE)
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked How would you run Terraform in CI/CD?
On every pull request: fmt -check, validate, linting and security scanning, then plan -out with the plan posted to the PR. After review and approval: apply that saved plan from a pipeline with…
-
Most asked How do you bring existing infrastructure under Terraform management?
Use import blocks (Terraform 1.5+) in configuration, which are planned and reviewed like any change, optionally with terraform plan -generate-config-out=generated.tf to generate a starting…
-
Most asked How do you refactor Terraform code without destroying resources? Explain moved blocks and state mv.
When you rename a resource or move it into a module, Terraform would otherwise plan to destroy the old address and create a new one. A moved block (Terraform 1.1+) records the old and new addresses…
-
Most asked How do you pin provider and module versions, and what is the dependency lock file?
Declare required_providers with version constraints (for example ~> 5.0) and required_version for Terraform itself; pin module versions; and commit .terraform.lock.hcl, which records the exact…
-
How do you use Terraform to deploy the same infrastructure to nonprod and production AWS accounts?
Use a single set of modules with environment-specific root configurations. Each root sets its own backend, provider with assume_role into the target account, and a .tfvars file or variable defaults…
-
How do you configure OIDC authentication between GitHub Actions and AWS for Terraform pipelines?
Create an aws_iam_openid_connect_provider for GitHub's OIDC endpoint and an IAM role whose trust policy restricts the sub claim to a specific repository and environment. The GitHub workflow uses…
-
How should you split Terraform state for a large organisation?
Split by blast radius, ownership and change frequency: for example networking, shared services, databases, and each application in separate states (root modules), per environment and region. Smaller…
-
How do you test Terraform code?
Layer the checks: fmt and validate, linting (tflint), security scanning, plan review, the native terraform test framework (Terraform 1.6+) with .tftest.hcl files that can run plans or real applies…
-
How do you bootstrap an S3 remote state backend for Terraform without a chicken-and-egg problem?
Create the S3 bucket and (optionally) a DynamoDB table with Terraform using a local backend first, then migrate the state into the bucket with terraform init -migrate-state. In Terraform 1.10+ the…
-
How do you manage RDS passwords securely with Terraform?
Use manage_master_user_password = true on aws_db_instance so AWS generates the password and stores it in Secrets Manager automatically. This avoids storing the password in Terraform state.
-
How do you set up CloudFront with an S3 origin using Origin Access Control in Terraform?
Create an aws_cloudfront_origin_access_control, reference it on the CloudFront distribution's origin, and add an S3 bucket policy that allows cloudfront:GetObject from the distribution's ARN. The…
-
How do you manage AWS costs with Terraform, and what resources help?
Use aws_budgets_budget resources per environment with both ACTUAL and FORECASTED thresholds, cost allocation tags via default_tags, and nonprod schedules that scale resources to zero outside…
-
How do you manage multiple accounts, regions or subscriptions in one Terraform configuration?
Define several provider configurations with aliases (provider "aws" { alias = "us_east_1" region = "us-east-1" }) and select them per resource or pass them into modules with the providers argument.…
-
How do you structure a Terraform repository for a team?
Separate reusable modules from live configuration: a modules/ area (or separate repositories with versioned releases) and root configurations per environment and component (live/prod/network,…
-
How do you manage Kubernetes resources with Terraform, and what are the pitfalls?
The Kubernetes and Helm providers can create namespaces, RBAC and Helm releases, but managing a cluster and the resources inside it in the same Terraform run is fragile: providers need the cluster's…
-
How do you design a reusable Terraform module for an internal platform team to offer, for example 'a secure S3 bucket'?
Bake in the organisation's defaults (encryption with KMS, public access blocked, versioning, access logging, lifecycle rules, required tags), expose only the choices consumers should make (name,…
-
How do you tag resources consistently with Terraform?
Set common tags centrally (for AWS, the provider's default_tags block; for other providers, a merged local.tags passed to modules) including owner, environment, cost centre, application and…