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.
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)- A3% (1)
- B91% (29)
- C6% (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.
'terraform import' brings existing infrastructure into Terraform state, not for managing multiple environments.
'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.
'terraform state' is used for advanced state management operations, like moving or removing resources from the state file, but not for creating separate environments.
'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
Community Discussion
No community discussion yet for this question.