From count to for_each Without Replacing Anything
This machine has OpenTofu, the open-source tool that reads the same configuration language as Terraform. Run it as tofu (terraform runs the same program). There is no network: the local, random and null providers are already installed.
/home/student/infra/harbor creates a bucket name (random_pet.bucket) and a file for each team, with count. The search team was disbanded, but removing it from the list makes the plan replace growth's bucket name too: everything after the removed index shifts.
for_each, so their addresses look like random_pet.bucket["payments"] and local_file.team["payments"].payments and growth must keep their current bucket names (no replacement).search: its bucket name and its file go away./home/student/out/teams/<team>.txt still contains bucket=<name>.Apply your changes. A new plan must show no changes.
About this machine
Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.
Part of Prepare for the Terraform Associate. Next step: Every Environment Times Every Service
Teaching or writing about this? Embed this lab on your page
Your machine is ready to start
A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.
No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.