Terraform Configuration
Drill 19 practice questions focused entirely on Terraform Configuration for the HashiCorp Terraform Associate exam. Tap an answer for instant feedback and a full explanation — no sign-up, always free.
Your team manages an existing AWS S3 bucket named 'legacy-data-archive' that was created manually in the console. You have written a resource block 'aws_s3_bucket.archive' in your configuration but have not yet brought the bucket under Terraform management. Using the CLI import workflow, which command correctly associates the existing bucket with your resource address?
You need to bring an existing AWS EC2 instance (instance ID i-0abc123def456) under Terraform management using the CLI-based `terraform import` command. You have already written a matching resource block named `aws_instance.web` in your configuration. Which command correctly imports the instance into your current state?
A DevOps engineer must bring a manually-created AWS S3 bucket under Terraform management using the legacy `terraform import` command (not import blocks). The engineer runs `terraform import aws_s3_bucket.logs my-existing-bucket` in a directory that currently has no resource block for that bucket. What happens, and what must be done first?
A colleague manually created an AWS security group in the console named 'legacy-web-sg' with ID 'sg-0a1b2c3d4e5f'. You have written a matching `aws_security_group` resource block labeled 'web' in your configuration. You want Terraform to begin managing this existing security group without destroying and recreating it. Which command accomplishes this?
You inherited a Terraform configuration with a large state file and need to locate the exact resource address of a specific EC2 instance before running a targeted operation. You want to see all resource addresses currently tracked in state without querying the cloud provider or modifying anything. Which command should you run?
Your team refactored the Terraform configuration by moving an existing `aws_instance.web` resource into a new module named `frontend`. After running `terraform plan`, Terraform proposes to destroy the original instance and create a new one inside the module. You want to preserve the running EC2 instance and simply update the state to reflect the new address. Which command should you run?
You renamed an AWS instance resource in your configuration from `aws_instance.web` to `aws_instance.frontend` without changing any of its arguments. When you run `terraform plan`, Terraform proposes to destroy `aws_instance.web` and create `aws_instance.frontend`. You want Terraform to keep the existing instance and simply track it under the new resource address. Which command accomplishes this?
Your team manages an S3 bucket via Terraform, but ownership of that bucket is being transferred to another department that will manage it manually. You must remove the bucket from your Terraform state so future plans and applies ignore it, but the bucket itself must NOT be deleted from AWS. Which command accomplishes this?
You are troubleshooting a running EC2 instance managed by Terraform. A teammate changed something out of band and you want to inspect all current attributes (including the AMI ID and security group IDs) that Terraform has recorded for just that one resource, without listing every resource in the state. Which command should you run?
A web server EC2 instance managed by Terraform has become corrupted after a failed manual patch. The configuration itself is correct and unchanged, but you want Terraform to destroy and recreate this single resource on the next apply without altering any other infrastructure. Which approach uses the current, recommended Terraform command to accomplish this?
A colleague's older runbook instructs the team to run `terraform taint aws_instance.web` to force an EC2 instance to be recreated on the next apply. You are on a recent version of Terraform (0.15.2+) and want to follow the currently recommended approach that lets you preview the recreation in a plan before committing to it. Which command should you use instead?
A platform engineer suspects that a colleague manually resized an EC2 instance in the AWS console last week. Before making any configuration changes, the engineer wants to update the state file to match the real infrastructure attributes and see what has drifted — but without proposing any changes to bring resources back to the configured values. Which command best accomplishes this?
A Terraform run intermittently fails during apply with a vague provider error, and you suspect the underlying HTTP requests to the cloud provider's API are being rejected. You want to capture detailed logs including the API request and response payloads so you can share them with support. Which approach correctly enables this debugging output?
A developer is troubleshooting an intermittent apply failure and wants to enable verbose Terraform logging, but also needs the log output written to a file for later analysis by a colleague rather than only appearing on the terminal. Which combination of environment variables should the developer set before running the command?
A platform engineer is troubleshooting an intermittent failure during 'terraform apply' and wants the most detailed internal logging Terraform can produce, including provider RPC calls and core graph operations. Which value should they assign to the TF_LOG environment variable to get the highest verbosity?
You are working on a project that uses multiple CLI workspaces to isolate state for dev, staging, and prod. Before running an apply, you want to confirm which workspace is currently active so you don't accidentally modify the wrong environment's state. Which command shows all existing workspaces and marks the one currently selected with an asterisk?
Your team manages a single Terraform configuration for a web application. You currently use the default workspace for production. You need to spin up an isolated staging environment from the same configuration without affecting production's state file, and you want to start managing it under a new named workspace. Which command creates the new workspace and switches you into it?
You manage a single Terraform configuration for a web application and want to maintain separate state files for your 'dev' and 'prod' environments using Terraform's built-in CLI workspaces, all within the same backend. You are currently on the 'default' workspace and need to create and switch to a new workspace called 'prod'. Which command accomplishes this?
Your team uses CLI workspaces with an S3 remote backend to manage separate state for dev, staging, and prod. A colleague asks where the state for the non-default workspaces is physically stored relative to the default workspace's state. Which statement correctly describes how Terraform stores workspace state with a remote backend?
More Terraform Associate practice
Keep going with the other HashiCorp Certified: Terraform Associate (004) domains, or take a full timed mock exam.
← Back to Terraform Associate overview