Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      10 Top Node.js Development Companies for Enterprise-Scale Projects (2025-2026 Ranked & Reviewed)

      July 4, 2025

      12 Must-Know Cost Factors When Hiring Node.js Developers for Your Enterprise

      July 4, 2025

      Mirantis reveals Lens Prism, an AI copilot for operating Kubernetes clusters

      July 3, 2025

      Avoid these common platform engineering mistakes

      July 3, 2025

      I compared my Sonos Arc Ultra with Samsung’s flagship soundbar, and it’s pretty dang close

      July 5, 2025

      Distribution Release: MocaccinoOS 1.8.3

      July 5, 2025

      Hideo Kojima’s “OD” is still in development with Xbox, at least for today

      July 4, 2025

      Microsoft is replacing salespeople with “solutions engineers” amid recent layoffs — promoting Copilot AI while ChatGPT dominates the enterprise sector

      July 4, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The dog days of JavaScript summer

      July 4, 2025
      Recent

      The dog days of JavaScript summer

      July 4, 2025

      Databricks Lakebase – Database Branching in Action

      July 4, 2025

      Flutter + GitHub Copilot = Your New Superpower

      July 4, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Windows 11 hits 59.84% on Steam as gamers move on from Windows 10

      July 5, 2025
      Recent

      Windows 11 hits 59.84% on Steam as gamers move on from Windows 10

      July 5, 2025

      GeForce NOW adds 21 new games in July, including Killing Floor 3 and RoboCop DLC

      July 5, 2025

      Microsoft 365 Web Apps Get Simple Edit Access Request Option

      July 5, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Operating Systems»Linux»10 Scenario-Based Terraform Interview Questions and Answers

    10 Scenario-Based Terraform Interview Questions and Answers

    May 19, 2025

    Terraform interviews often include scenario-based questions to test how you solve real-world problems. These questions check your practical knowledge and decision-making. This article covers 10 common scenarios with answers written like you’d say them in an interview. Let’s jump in!

    1. Your team accidentally deleted the Terraform state file. What do you do?

    Candidate Reply: Losing the state file is bad because Terraform won’t know what resources it’s managing. First, I’d check if we have a backup, like in an S3 bucket if we’re using a remote backend. If there’s no backup, I’d use `terraform import` to rebuild the state file by manually importing existing resources, like an EC2 instance. For example, I’d write a resource block and run terraform import aws_instance.web i-1234567890abcdef0. To prevent this in the future, I’d set up a remote backend with versioning enabled.
    
    resource "aws_instance" "web" {
      ami           = "ami-12345678"
      instance_type = "t2.micro"
    }
    # Run: terraform import aws_instance.web i-1234567890abcdef0
    
    

    2. A `terraform apply` fails halfway through. How do you fix it?

    Candidate Reply: If `terraform apply` fails, I first read the error message to understand what went wrong, like a missing permission or invalid config. I check the state file with `terraform state list` to see which resources were created. If something’s broken, I might remove it from the state using `terraform state rm`. Then, I fix the code, run `terraform plan` to confirm the changes, and re-run `terraform apply`. I always back up the state file before making changes.

    3. Your team needs to set up dev, staging, and prod environments. How do you do it with Terraform?

    Candidate Reply: I’d organize the Terraform code to handle multiple environments without duplicating code. I’d create a folder structure like `environments/dev`, `environments/staging`, and `environments/prod`, each with its own `terraform.tfvars` file for settings like instance sizes. I’d use modules for shared resources, like a VPC, and call them from each environment. This keeps the code DRY and easy to manage.
    
    # environments/dev/terraform.tfvars
    instance_type = "t2.micro"
    environment   = "dev"
    
    # main.tf
    module "vpc" {
      source = "../../modules/vpc"
      cidr   = var.vpc_cidr
    }
    
    

    4. Someone manually changed an AWS resource outside Terraform. How do you handle it?

    Candidate Reply: This is called drift. I’d run `terraform plan` to see the differences between the code and the actual resource. If the manual change is okay, I’d update the Terraform code to match it. If it’s wrong, I’d run `terraform apply` to bring the resource back to the coded state. To prevent this, I’d use IAM policies to limit manual changes and set up drift detection in Terraform Cloud.

    5. You need to refactor a big Terraform config into modules. How do you start?

    Candidate Reply: Refactoring needs to be careful to avoid breaking things. I’d identify logical pieces, like networking or compute, and create a module for each. I’d move one resource group at a time to a module, update the state with `terraform state mv`, and test with `terraform plan` to ensure no changes happen. For example, I’d move a VPC to a module and update the main config to call it.
    
    # modules/vpc/main.tf
    resource "aws_vpc" "main" {
      cidr_block = var.cidr
    }
    
    # Run: terraform state mv aws_vpc.main module.vpc.aws_vpc.main
    
    

    6. Your Terraform state is locked, and you can’t apply changes. What do you do?

    Candidate Reply: A state lock means someone else is running Terraform, or a previous run crashed. I’d first check the lock info with `terraform state lock-info` to see who’s holding it. If it’s a teammate, I’d coordinate with them. If it’s stuck, I’d use `terraform force-unlock` with the lock ID, but only after confirming no one’s actively applying changes. To avoid this, I ensure CI/CD pipelines queue Terraform runs.
    
    # Check lock
    terraform state lock-info
    
    # Force unlock if needed
    terraform force-unlock LOCK_ID
    
    

    7. You need to deploy a new version of an app with zero downtime. How do you use Terraform?

    Candidate Reply: I’d use a blue-green deployment. In Terraform, I’d create a new auto-scaling group with the updated app version and update the load balancer to route traffic to it. Once it’s stable, I’d destroy the old group. I’d use `create_before_destroy` to ensure the new resources are ready first.
    
    resource "aws_autoscaling_group" "app" {
      # Config for new version
      lifecycle {
        create_before_destroy = true
      }
    }
    
    

    8. A provider update breaks your Terraform config. How do you fix it?

    Candidate Reply: If a provider update breaks things, I’d check the provider’s changelog for breaking changes. I’d pin the provider to the last working version in the code to avoid issues. Then, I’d test the new version in a dev environment, update the config to match any new requirements, and run `terraform init -upgrade` to apply it safely.
    
    terraform {
      required_providers {
        aws = {
          source  = "hashicorp/aws"
          version = "~> 4.0"
        }
      }
    }
    
    

    9. You need to share a VPC ID across multiple Terraform projects. How do you do it?

    Candidate Reply: I’d use a remote state data source to share the VPC ID. In the project that creates the VPC, I’d define an output for the VPC ID. In other projects, I’d use the `terraform_remote_state` data source to fetch it. This keeps projects independent but connected.
    
    # VPC project
    output "vpc_id" {
      value = aws_vpc.main.id
    }
    
    # Other project
    data "terraform_remote_state" "vpc" {
      backend = "s3"
      config = {
        bucket = "my-terraform-state"
        key    = "vpc/terraform.tfstate"
        region = "us-east-1"
      }
    }
    resource "aws_subnet" "subnet" {
      vpc_id = data.terraform_remote_state.vpc.outputs.vpc_id
    }
    
    

    10. Your team wants to adopt an existing AWS resource into Terraform. How do you do it?

    Candidate Reply: I’d use `terraform import` to bring the resource into Terraform’s state. First, I’d write a resource block in the code matching the existing resource, like an S3 bucket. Then, I’d run `terraform import` with the resource’s ID. After importing, I’d run `terraform plan` to check for differences and update the code if needed.
    
    resource "aws_s3_bucket" "my_bucket" {
      bucket = "my-existing-bucket"
    }
    
    # Run: terraform import aws_s3_bucket.my_bucket my-existing-bucket
    
    

    These scenario-based questions test how you handle real Terraform challenges. Practice these answers to show you can think on your feet and solve problems like a pro. Good luck in your interview!

    The post 10 Scenario-Based Terraform Interview Questions and Answers appeared first on TecAdmin.

    Source: Read More

    Facebook Twitter Reddit Email Copy Link
    Previous Article25 Advanced Terraform Interview Questions for Senior Roles
    Next Article Helwan OS: la distribuzione GNU/Linux multiuso egiziana

    Related Posts

    Operating Systems

    Windows 11 hits 59.84% on Steam as gamers move on from Windows 10

    July 5, 2025
    Operating Systems

    GeForce NOW adds 21 new games in July, including Killing Floor 3 and RoboCop DLC

    July 5, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Rilasciati il driver OpenRazer 3.10.3 per dispositivi Razer compatibile con Linux 6.15

    Linux

    CVE-2025-52784 – Hideoguchi Bluff Post CSRF Stored XSS

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-47768 – Cisco ASA SSL/TLS Certificate Pinning Bypass

    Common Vulnerabilities and Exposures (CVEs)

    Last Week in AI #302 – QwQ 32B, OpenAI injunction refused, Alexa Plus

    Artificial Intelligence

    Highlights

    SonicWall-lek dat voor fabrieksreset zorgt mogelijk misbruikt bij aanvallen

    May 8, 2025

    SonicWall-lek dat voor fabrieksreset zorgt mogelijk misbruikt bij aanvallen

    Een kwetsbaarheid in SonicWall SMA 100-gateways die voor een fabrieksreset kan zorgen is mogelijk misbruikt bij aanvallen, zo laat securitybedrijf Rapid7 weten. SonicWall heeft gisteren updates uitgeb …
    Read more

    Published Date:
    May 08, 2025 (3 hours, 30 minutes ago)

    Vulnerabilities has been mentioned in this article.

    CVE-2025-32820

    CVE-2025-32819

    CVE-2025-3282

    Trump Media’s $3 Billion Crypto Investment Plan: A Bold Vision for the Digital Future

    May 30, 2025

    Why the road from passwords to passkeys is long, bumpy, and worth it – probably

    April 25, 2025

    Redesigning the UK Transport Watchdog Website

    July 2, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.