Courseiva

TF-004 · topic practice

Implement and maintain state practice questions

This domain covers how Terraform records and reconciles infrastructure state: remote backends, state locking, partial backend configuration, inspecting and editing state, importing existing resources, and handling version or drift errors. Questions present short operational scenarios and ask which command, backend setting, or recovery step is correct.

Courseiva uses original exam-style practice questions designed for learning and revision. The goal is to understand the concepts, recognise exam patterns, and improve through explanations — not memorise copied exam dumps.

Editorial oversight:Johnson Ajibi· MSc IT Security, IEEE Senior Member
20 questionsDomain: Implement and maintain state

What the exam tests

What to know about Implement and maintain state

Be able to configure and migrate remote backends, run state inspection and manipulation commands, import existing resources, and recover from version or lock errors. The most important thing is knowing that state is Terraform's source of truth and must be changed through Terraform commands, not manual edits.

Configuring remote backends such as S3 with DynamoDB locking and partial backend configuration via terraform init

Using terraform state list, show, mv, rm, and pull to inspect or modify tracked resources

Importing existing infrastructure with terraform import and matching resource addresses in configuration

Resolving state errors including version mismatches, locking conflicts, and drift between state and reality

Watch out for

Common Implement and maintain state exam traps

  • ▸Assuming terraform import also writes the resource configuration; it only adds the object to state, so the matching resource block must already exist.
  • ▸Forgetting that changing backend settings requires terraform init with -migrate-state or -reconfigure, not just an apply.
  • ▸Editing state files by hand or ignoring lock errors, which risks corruption or concurrent writes instead of using state commands and lock release.

Practice set

Implement and maintain state questions

20 questions · select your answer, then reveal the explanation

An organization uses Terraform with AWS S3 backend and DynamoDB for state locking. During a plan, you receive an error: 'Error acquiring the state lock'. The lock information in DynamoDB shows a lock from a previous session that crashed. What is the most appropriate next step?

A team uses Terraform Cloud workspaces to manage multiple environments. They notice that the state file for the production workspace is stored in a different backend than the development workspace. Which Terraform feature allows different workspaces to use different backends?

Which TWO of the following are valid reasons to use Terraform state?

Match each Terraform state command to its action.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

List resources in the state

Show details of a single resource in state

Move an item in the state

Remove an item from the state

Download current state from backend

After running `terraform state mv` to rename a resource, the resource's state binding is lost and the resource cannot be managed. Which command should be run to restore the state binding?

A team uses a Consul backend for Terraform state. They want to encrypt state at rest. What should they do?

Which of the following is NOT a valid backend type for storing Terraform state?

Which TWO of the following are valid strategies to migrate Terraform state from a local backend to a remote backend?

An organization uses Terraform Cloud workspaces to manage multiple environments. They notice that after promoting a configuration change from development to production workspace, the production workspace's state file contains references to resources that were only created in development. What is the most likely cause?

A user runs `terraform plan` and notices that the plan includes 'Outgoing changes' for a number of resources that were not modified in the configuration. What is the most likely cause?

Refer to the exhibit. A user runs `terraform state list` and receives the output shown. The configuration defines an `aws_instance.web` resource with count = 3 and an `aws_s3_bucket.data` resource. After some changes, the user runs `terraform plan` and sees that the plan wants to create a new `aws_instance.web[2]` and destroy the existing `aws_instance.web[2]`. What is the most likely cause?

Exhibit

$ terraform state list
aws_instance.web[0]
aws_instance.web[1]
aws_instance.web[2]
aws_s3_bucket.data

A team is migrating from local state to an S3 remote backend. They have existing state files in the working directory. After configuring the backend block and running `terraform init`, what is the correct next step to migrate the existing state?

After making manual changes to an AWS resource via the console, a Terraform user wants to update the state file to reflect those changes without modifying infrastructure. Which command should they run?

Which TWO of the following are valid methods to acquire a state lock in Terraform Cloud?

Your organization uses Terraform Cloud with a remote execution mode. There are two workspaces: `app-prod` and `app-staging`. The state for `app-prod` is stored in the `prod` workspace, and `app-staging` in the `staging` workspace. Recently, a new developer joined the team and tried to run `terraform plan` locally for the `app-staging` workspace. They received an error: "S3Backend bucket 'my-company-tf-state' does not exist." The developer is not using Terraform Cloud locally. The team uses a remote backend configuration with Terraform Cloud. What is the most likely cause?

A team uses Terraform with the `azurerm` backend. A junior engineer accidentally deletes the state file from the storage container. The team has a backup from 2 hours ago in a different container. What is the correct procedure to recover from this state loss?

Refer to the exhibit. A developer modifies the configuration by changing the resource name from 'aws_instance.web' to 'aws_instance.web2'. After running terraform plan, the output indicates that a new resource 'aws_instance.web2' will be created, but no resource will be destroyed. What should the developer do to update the state to match the configuration?

Exhibit

$ terraform state list
aws_instance.web
aws_security_group.sg

Refer to the exhibit. A developer runs terraform plan and receives this error. What should the developer do to resolve the error?

Exhibit

Error: Backend initialization required: please run "terraform init"

Reason: Backend configuration has changed.

The configured backend "s3" has changed since the last "terraform init".
Previous configuration:
  bucket = "prod-terraform-state"
  key    = "network/terraform.tfstate"
  region = "us-east-1"

New configuration:
  bucket = "prod-terraform-state"
  key    = "network/terraform.tfstate"
  region = "us-west-2"

Refer to the exhibit. After importing an AWS instance, the state file shows the resource. However, the configuration file (main.tf) does not yet contain the resource definition. What will happen when 'terraform plan' is run?

Exhibit

$ terraform import aws_instance.web_server i-0a1b2c3d4e5f6g7h8
aws_instance.web_server: Importing from ID "i-0a1b2c3d4e5f6g7h8"...
aws_instance.web_server: Import prepared!
  Prepared aws_instance for import
aws_instance.web_server: Refreshing state... [id=i-0a1b2c3d4e5f6g7h8]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

$ terraform state pull
{
  "version": 4,
  "terraform_version": "1.5.0",
  "serial": 1,
  "lineage": "abc123",
  "outputs": {},
  "resources": [
    {
      "mode": "managed",
      "type": "aws_instance",
      "name": "web_server",
      "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
      "instances": [
        {
          "schema_version": 1,
          "attributes": {
            "id": "i-0a1b2c3d4e5f6g7h8",
            "ami": "ami-0c55b159cbfafe1f0",
            "instance_type": "t2.micro"
          }
        }
      ]
    }
  ]
}

Refer to the exhibit. An engineer modifies the instance's tags via the AWS console, then runs 'terraform apply'. The apply output shows 1 change, but the state file still shows the original tags. What is the most likely reason?

Exhibit

$ terraform apply -auto-approve
aws_instance.web_server: Modifying... [id=i-0a1b2c3d4e5f6g7h8]
aws_instance.web_server: Modifications complete after 5s [id=i-0a1b2c3d4e5f6g7h8]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

$ terraform state show aws_instance.web_server
# aws_instance.web_server:
resource "aws_instance" "web_server" {
    ami           = "ami-0c55b159cbfafe1f0"
    instance_type = "t2.micro"
    tags          = {
        "Name" = "WebServer"
    }
    subnet_id = "subnet-0a1b2c3d4e5f6g7h8"
    vpc_security_group_ids = [
        "sg-0a1b2c3d4e5f6g7h8",
    ]
}

$ terraform state pull | jq '.resources[0].instances[0].attributes_flat'
{
  "ami": "ami-0c55b159cbfafe1f0",
  "instance_type": "t2.micro"
}

Free account

Track your progress over time

Create a free account to save your results and see which topics improve across sessions.

Focused Implement and maintain state sessions

Start a Implement and maintain state only practice session

Every question in these sessions is drawn from the Implement and maintain state domain — nothing else.

Related practice questions

Related TF-004 topic practice pages

Move into related areas when this topic feels solid.

Frequently asked questions

What does the TF-004 exam test about Implement and maintain state?
Be able to configure and migrate remote backends, run state inspection and manipulation commands, import existing resources, and recover from version or lock errors. The most important thing is knowing that state is Terraform's source of truth and must be changed through Terraform commands, not manual edits.
How should I use these practice questions?
Select your answer before revealing the explanation. Then read why each option is right or wrong — this active recall approach builds retention far faster than re-reading notes.
Can I practise just Implement and maintain state questions in a focused session?
Yes — the session launcher on this page draws every question from the Implement and maintain state domain. Use a 10-question session first to gauge your baseline, then move to 20 or 30 once the weak spots are clear.
Where can I practise other TF-004 topics?
Use the topic links above to move to related areas, or go back to the TF-004 question bank to see all topics.
Are these real exam questions or dumps?
These are original practice questions written to test the same concepts the TF-004 exam covers. They are not copied from any real exam or dump site.