nerdexam
HashiCorp

TA-002-P · Question #68

You would like to reuse the same Terraform configuration for your development and production environments with a different state file for each. Which command would you use?

The correct answer is B. terraform workspace. To reuse the same Terraform configuration across different environments with separate state files, 'terraform workspace' is the appropriate command for creating and managing distinct isolated states.

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

Question

You would like to reuse the same Terraform configuration for your development and production environments with a different state file for each. Which command would you use?

Options

  • Aterraform import
  • Bterraform workspace
  • Cterraform state
  • Dterraform init

How the community answered

(32 responses)
  • A
    3% (1)
  • B
    91% (29)
  • C
    6% (2)

Why each option

To reuse the same Terraform configuration across different environments with separate state files, 'terraform workspace' is the appropriate command for creating and managing distinct isolated states.

Aterraform import

'terraform import' brings existing infrastructure into Terraform state, not for managing multiple environments.

Bterraform workspaceCorrect

'terraform workspace' allows you to manage multiple distinct state files (workspaces) from a single Terraform configuration. Each workspace maintains its own state, enabling the deployment of the same configuration to different environments (e.g., dev, prod) independently without interfering with each other's resources.

Cterraform state

'terraform state' is used for advanced state management operations, like moving or removing resources from the state file, but not for creating separate environments.

Dterraform init

'terraform init' initializes the working directory and configures the backend; while necessary for workspaces, it's not the command used to *switch or create* them.

Concept tested: Terraform workspaces for environments

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

Topics

#Terraform CLI#State management#Backend configuration#Multi-environment

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice