HashiCorp Terraform Associate (003) — All Questions
5 questions
What is the primary purpose of Terraform state?
- a.To map real-world resources to your configuration and track metadata so Terraform can plan changes✓
- b.To store your provider credentials in plain text for reuse
- c.To serve as the human-readable documentation of your architecture
- d.To replace the need for a version control system
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.
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.terraform fmt
- b.provider aliasing
- c.State locking✓
- d.The count meta-argument
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.
Which practice is recommended for storing Terraform state when a team collaborates on the same infrastructure?
- a.Commit terraform.tfstate to a public Git repository
- b.Use a remote backend such as Terraform Cloud or an object store with locking✓
- c.Email the state file to teammates after each apply
- d.Delete state after every apply to keep things clean
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.
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 apply -replace
- b.terraform destroy
- c.terraform refresh only
- d.terraform import✓
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.
What does terraform state rm do to a resource?
- a.It removes the resource from Terraform state without destroying the real infrastructure✓
- b.It deletes the real resource in the cloud provider
- c.It renames the resource in the configuration file
- d.It refreshes the resource's attributes from the 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.