A practitioner runs 'terraform apply' in a new directory that contains only 'main.tf', with no 'backend' or 'cloud' block declared. After the apply succeeds, where does Terraform record the resulting state by default?
terraform {
required_providers {
local = {
source = "hashicorp/local"
}
}
}
resource "local_file" "note" {
filename = "${path.module}/note.txt"
content = "hello"
}- AIn a file named 'terraform.tfstate' in the current working directory, using the local backend. Correct
- BIn HCP Terraform, because any workspace is automatically linked to the remote state service.
- CIn the provider's own datastore, since the 'local' provider manages where state is persisted.
- DNowhere on disk, because state is held only in memory until a backend is added.
Why A is correct: With no backend or cloud block configured, Terraform uses the local backend by default and writes state to 'terraform.tfstate' in the working directory.
Why B is wrong: HCP Terraform is only used when a 'cloud' block is present; without one Terraform never links a workspace to a remote service, so this is wrong.
Why C is wrong: It is tempting to conflate the 'local' provider with the local backend, but providers manage resources and never decide where state is stored.
Why D is wrong: Terraform always persists state after an apply; the default local backend writes it to disk immediately rather than keeping it only in memory.