nerdexam
HashiCorp

TA-002-P · Question #60

What is terraform refresh intended to detect?

The correct answer is C. State file drift. The 'terraform refresh' command is used to reconcile the Terraform state file with the actual infrastructure deployed in the cloud or on-premises. It detects and updates the state file to reflect any changes made to resources outside of Terraform's management.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

Question

What is terraform refresh intended to detect?

Options

  • ATerraform configuration code changes
  • BEmpty state files
  • CState file drift
  • DCorrupt state files

How the community answered

(27 responses)
  • A
    4% (1)
  • C
    89% (24)
  • D
    7% (2)

Why each option

The 'terraform refresh' command is used to reconcile the Terraform state file with the actual infrastructure deployed in the cloud or on-premises. It detects and updates the state file to reflect any changes made to resources outside of Terraform's management.

ATerraform configuration code changes

'terraform plan' or 'terraform apply' detect configuration code changes by comparing the new configuration with the state file.

BEmpty state files

'terraform refresh' operates on an existing state file and doesn't directly detect empty state files, though it might result in an empty state if no resources are found.

CState file driftCorrect

'terraform refresh' is specifically designed to detect "drift," which refers to discrepancies between the actual infrastructure's current configuration and what is recorded in the Terraform state file. It updates the state file to match the real-world state of resources without making any changes to the infrastructure itself.

DCorrupt state files

'terraform refresh' does not validate the integrity of the state file's format; other commands or manual inspection would be needed for corrupt state files.

Concept tested: Terraform refresh command purpose

Source: https://developer.hashicorp.com/terraform/cli/commands/refresh

Topics

#terraform refresh#state file#state drift#CLI commands

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice