Development, staging and production from shared code: separate root modules and backends, CLI workspaces and terraform.workspace, and per-environment variable files.
Study it
Environments from shared code: root modules, backends and workspaces
Lesson coming
Sample questions
Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.
Question 1 · choose 1
One configuration manages dev, staging and production through CLI workspaces in a single S3 backend. An audit requires that engineers who can change dev cannot read or write production state, and that production runs use a different AWS account for state storage. What should the team do?
AKeep the workspaces and set workspace_key_prefix to prod for production runs
BGive each environment its own root configuration and backend that call shared modules
CKeep the workspaces and use terraform.workspace in the configuration to choose a production provider role
DKeep the workspaces and make production plans run with -lock=false to avoid contention
Show the answer and why
AKeep the workspaces and set workspace_key_prefix to prod for production runs
Incorrect
The prefix only changes object paths in the same backend; the backend and its credentials stay shared.
BGive each environment its own root configuration and backend that call shared modules
Correct
Separate configurations with separate backends can use different credentials and access controls, which CLI workspaces in one backend cannot provide.
CKeep the workspaces and use terraform.workspace in the configuration to choose a production provider role
Incorrect
That changes the credentials used for resources, but state for every workspace still lives in the same backend with the same access.
DKeep the workspaces and make production plans run with -lock=false to avoid contention
Incorrect
Disabling locking adds risk and does nothing for access separation.
CLI workspaces share one backend, so they are not an isolation mechanism. When environments need different credentials or access controls, give each its own root module and backend configuration.