Root modules
Each independently applied state has its own root and backend.
Chapter 7 of 24
Keep environment intent explicit, then prove behavior before a provider is called.
.tfvars inputs.Each independently applied state has its own root and backend.
Make reviewable values explicit with learning and production files.
They change state names, not account, region, credentials, or blast radius.
Plan tests assert configuration behavior; use provider mocks only when a provider result is the subject.
Use terraform console or tofu console for expressions. Use TF_LOG=debug only for a focused diagnosis and remove sensitive logs afterward. A refresh-only plan reports drift; it does not decide whether configuration or the remote object is correct.
Learning and production should normally differ by account and role, not merely a workspace. For production, deletion protection is an explicit input in the reviewed production variable file.
Read learning.tfvars, production.tfvars, and the native test file.
cd learn-terraform/labs/07-environments
terraform init -backend=false
terraform test
terraform plan -var-file=learning.tfvars
terraform plan -var-file=production.tfvars
tofu init -backend=false
tofu test
tofu plan -var-file=learning.tfvars
tofu plan -var-file=production.tfvarsThe tests make policy observable: learning returns false, production returns true. The plans confirm the committed variable files express the same intent.
| Input | Learning | Production |
|---|---|---|
| deletion protection | false | true |
| account and role | separate learning access | separate production access and approval |
| workspace | optional state convenience | not an isolation boundary |
This lab does not create provider resources. Remove generated initialization directories and local state before committing.
No. Provider credentials and account selection are separate concerns.
When the test needs a provider response but must not call the real provider.
Values, tests, and identities must agree before an apply. Next, bootstrap a remote backend without a circular state dependency.