WebMagicInformatica
Terraform Associate (004) practice questions

Terraform Associate (004) practice questions: Terraform state management

5 free questions on Terraform state management, 12% of the HashiCorp Terraform Associate exam. Try each one, then open the answer and explanation. None of them are in the free readiness check, so you can still take it fresh.

Question 1

A team stores state in S3 with locking enabled, as in this backend configuration. What does state locking protect against?

terraform {
  backend "s3" {
    bucket       = "acme-tfstate"
    key          = "prod/network.tfstate"
    region       = "us-east-1"
    use_lockfile = true
  }
}
  1. A.

    Anyone reading the bucket without permissions.

  2. B.

    Provider plugins being updated.

  3. C.

    Variable values appearing in logs.

  4. D.

    Two people or pipelines running operations that write state at the same time.

Show answer and explanation

Answer: D

State locking blocks concurrent operations that could write to the same state and corrupt it.

  • Anyone reading the bucket without permissions.: Access control is separate from locking.
  • Provider plugins being updated.: Locking doesn't control provider versions.
  • Variable values appearing in logs.: That relates to sensitive values.
Question 2

You want two environments, dev and test, to use the same configuration with separate state files in the same backend. Which CLI feature supports this?

  1. A.

    Child modules, which give each environment its own state file automatically.

  2. B.

    CLI workspaces, created with terraform workspace new.

  3. C.

    The terraform fmt command.

  4. D.

    Provider aliases.

Show answer and explanation

Answer: B

CLI workspaces let one configuration keep multiple state instances in the same backend, selected with terraform workspace select.

  • Child modules, which give each environment its own state file automatically.: Modules don't create separate states by themselves.
  • The terraform fmt command.: It formats code only.
  • Provider aliases.: Aliases select provider configurations, not state files.
Question 3Choose 2

Which TWO statements about the Terraform state file are correct? (Choose two.)

  1. A.

    It can contain sensitive values in plain text, so the backend must be protected.

  2. B.

    It is encrypted automatically by the Terraform CLI.

  3. C.

    It is safe to commit to a public repository.

  4. D.

    It should be changed through Terraform commands, not edited by hand.

  5. E.

    It is only created when you run terraform destroy.

Show answer and explanation

Answer: A and D

State may hold secrets, so use a secure remote backend with restricted access. To change it, use commands such as terraform state mv or rm, not manual editing.

  • It is encrypted automatically by the Terraform CLI.: The CLI doesn't encrypt state; the backend may.
  • It is safe to commit to a public repository.: State often has sensitive data.
  • It is only created when you run terraform destroy.: State is created by apply.
Question 4

You run terraform state rm aws_instance.web. What is the result?

  1. A.

    The instance is destroyed and removed from state.

  2. B.

    The instance is recreated.

  3. C.

    The configuration block is deleted from the .tf file.

  4. D.

    Terraform stops tracking the instance, but the real instance is not destroyed.

Show answer and explanation

Answer: D

terraform state rm removes the binding from state only. The real object keeps running and could be imported again later.

  • The instance is destroyed and removed from state.: That is terraform destroy -target.
  • The instance is recreated.: State removal doesn't create anything.
  • The configuration block is deleted from the .tf file.: State commands don't edit configuration files.
Question 5

Which value does the bucket argument take when the staging workspace is selected?

resource "aws_s3_bucket" "b" {
  bucket = "acme-${terraform.workspace}"
}
  1. A.

    acme-staging

  2. B.

    acme-default

  3. C.

    acme-${terraform.workspace} literally

  4. D.

    An error, because workspaces cannot be used in names.

Show answer and explanation

Answer: A

terraform.workspace returns the name of the current workspace.

  • acme-default: That applies only in the default workspace.
  • acme-${terraform.workspace} literally: Interpolation replaces the expression.
  • An error, because workspaces cannot be used in names.: The value can be used in expressions.

How ready are you for Terraform Associate (004)?

Take the free readiness check: 15 questions from every exam domain in 20 minutes, with your score per domain.

  • 20 minutes
  • 15 questions
  • Free with an account

More Terraform Associate (004) practice by topic

Back to the Terraform Associate (004) practice test →

Independent practice material written from the official exam guide. Not affiliated with or endorsed by the exam provider.