Environment and identity isolation
Environment names are not security controls
A team might use dev and prod CLI workspaces in one root configuration. If both use a credential that can modify production, selecting dev does not revoke that permission. The same backend settings may expose multiple state sets. A safe production design defines who can read state, who can change resources, which resources each state owns, and where approval occurs. Name-based labels help humans but cannot enforce access.
Choose the right separation
For similar experiments, one root with CLI workspaces minimizes configuration duplication. For independent teams or production boundaries, separate root configurations and backends can limit state access, while different cloud accounts or projects and scoped workload identities can restrict resource actions. Reuse shared implementation through modules instead of copying every resource definition. Here is a conceptual layout; modules are taught next.
environments/ dev/ # root configuration, dev backend and dev identity prod/ # root configuration, prod backend and prod identitymodules/ catalog/ # shared implementation (introduced in the next chapter)A separate directory by itself does not restrict permissions: someone can still configure both roots to use the same powerful identity or state. Verify backend access independently from cloud provider access. A separate account or project can improve isolation, but policies, federation, network relationships and shared administrators determine the actual boundary.
Distinguish HCP Terraform workspaces
An HCP Terraform workspace is an operational unit with its own state and configuration association, input variables, run history, execution settings and permission controls. It resembles a separate working directory rather than simply a CLI state selector. For example, a fictional catalog-dev workspace could run a test root under a development identity; catalog-prod could use a protected production root, a production-scoped identity and restricted apply approval. Actual permission availability depends on the edition and role assignments. HCP Terraform can use remote, agent or local execution depending on supported settings; do not infer where a run executes merely from its name. No hosted workspace is created in this lesson.
Verify the environment before a plan or apply
A deployment preflight compares the approved environment to the actual root directory, effective workspace, backend state location, cloud account or project, region, workload identity, configuration revision and inputs. It also checks the intended execution mode and approval gate. Use approved provider-specific identity verification only in authorized environments. Never discover personal credentials, print tokens or run a cloud command merely to see where it connects. Study this fictional record.
Fictional deployment review (not CLI output)Approved target: prod / account P / eu-west-1 / state prod/catalogObserved target: prod / account D / eu-west-1 / state dev/catalogDecision: STOP — identity and state target mismatch.The workspace label matches but the account and state do not. Stop before planning or applying, then ask the responsible operator to correct the target. Re-check the full tuple after correction. Do not simply rename the workspace to make the mismatch disappear.
Design a safe promotion workflow
Promote a reviewed code revision from dev to test to production using independently generated plans for each environment. Do not reuse a dev plan file in production: plans describe one specific configuration, inputs and state context. Store only approved artifacts in access-controlled locations; state and plans can contain sensitive data. Limit apply permission, review replacements and deletions, and check actual service health after changes. Track ownership so that two states never manage the same object. Treat HCP workspace deletion separately from destruction of its managed resources; deleting state can leave infrastructure unmanaged.
Practice the trade-off
A temporary catalog preview managed by one trusted developer may need only a CLI workspace and synthetic data. A production catalog maintained by a separate team needs independent credentials, protected state and explicit approval. A shared module can keep the code consistent without combining those boundaries. Use the environment review worksheet to select a design and explain what it cannot guarantee.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Environment and identity isolation — knowledge check
Review workspace selection and environment boundaries.
Why is a CLI workspace not a sufficient production security boundary?
Which design is stronger for distinct production permissions?
What distinguishes an HCP Terraform workspace?
A preflight shows prod label but dev account and state. What should happen?
What plan should be used for production promotion?