5 questions

State Management

What is the primary purpose of Terraform state?

  • a.To store your provider credentials in plain text for reuse
  • b.To serve as the human-readable documentation of your architecture
  • c.To replace the need for a version control system
  • d.To map real-world resources to your configuration and track metadata so Terraform can plan changes✓

Terraform state records the mapping between resources defined in configuration and the real objects that exist, along with metadata and dependencies, so Terraform can determine what needs to change. It is not a documentation format or a substitute for version control, and while state can contain sensitive values it is not intended as a credential store.

State Management

A team collaborating on shared infrastructure wants to avoid two people applying changes to the same state at once. Which remote-state feature addresses this?

  • a.provider aliasing
  • b.terraform fmt
  • c.The count meta-argument
  • d.State locking✓

Remote backends that support state locking prevent concurrent operations from corrupting state by holding a lock during writes. This is essential for team collaboration on shared state. Formatting, provider aliases, and count are unrelated to protecting state from concurrent modification.

State Management

Which practice is recommended for storing Terraform state when a team collaborates on the same infrastructure?

  • a.Email the state file to teammates after each apply
  • b.Delete state after every apply to keep things clean
  • c.Commit terraform.tfstate to a public Git repository
  • d.Use a remote backend such as Terraform Cloud or an object store with locking✓

Teams should keep state in a remote backend (for example Terraform Cloud, S3 with DynamoDB locking, or similar) that provides shared access, locking, and often encryption. Committing state to version control risks leaking secrets and causes conflicts, and deleting state would lose the mapping Terraform needs to manage resources.

State Management

You provisioned a resource manually in the cloud console and now want Terraform to manage it without recreating it. Which command brings it under Terraform management?

  • a.terraform destroy
  • b.terraform apply -replace
  • c.terraform import✓
  • d.terraform refresh only

terraform import associates an existing real-world resource with a resource address in your configuration and records it in state, so Terraform manages it going forward without recreating it. You still must write matching configuration. apply -replace forces recreation, and destroy would remove infrastructure.

State Management

What does terraform state rm do to a resource?

  • a.It refreshes the resource's attributes from the provider
  • b.It renames the resource in the configuration file
  • c.It removes the resource from Terraform state without destroying the real infrastructure✓
  • d.It deletes the real resource in the cloud provider

terraform state rm removes a resource's entry from state so Terraform stops tracking it, while the actual cloud object continues to exist. It does not touch real infrastructure. To also delete the real resource you would use destroy, and to update tracked attributes you would refresh.

Report