52/53
Sign inSign up free

861. Stop Bad Plans With Preconditions

medium 20 XP ~11 minHands-on lab

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/ledgerd takes env and replicas and writes /home/student/out/deploy.conf. Last week someone deployed prod with a single replica, and another time with more replicas than the cluster quota allows. The quota is kept in quota.json and already read by the configuration.

Task

Add preconditions to local_file.deploy so that a plan fails:

  • when env is prod and replicas is less than 2, with the message prod needs at least 2 replicas,
  • when replicas is more than max_replicas from quota.json, with the message replicas exceed the quota of <max_replicas> (for example … quota of 10).

Valid combinations must plan as before. Keep the defaults (dev, 1): with them, a plan shows 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.

Teaching or writing about this? Embed this lab on your page

TerminalNot started

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.