[ norboten ]
terraform · lab terraform-02

The Site Removed From the Middle

· about 40 minutes · runs on ubuntu-26.04-devops · unrated

An unrated lab. It runs on your machine with no account and no network, and everything about it — the faults, the checks, the hints and the reference solution — is in the repository. An attempt on it is recorded on your profile and never moves a rating: only rated labs do. Rated and unrated labs.

The briefing

/srv/sites is the Terraform configuration that generates one web-server virtual host per site into /etc/nginx-sites/, each with its own port and its own cookie secret. Three sites have been live for months: shop on 8100, blog on 8101 and docs on 8102.

The blog is being retired. Someone removed "blog" from the list of sites and ran terraform plan. The plan wanted to rewrite docs with the blog's port and the blog's secret, and delete docs.conf — so they stopped, and nothing has been applied.

What is expected, and graded:

  1. blog is gone: no blog.conf, and nothing for the blog in the state.
  2. shop and docs are exactly as they are now — same ports, same cookie secrets, same files — and terraform plan reports no changes.
  3. Each site's resources are identified in the state by the site's name, so that the next site removed or added touches only that site.

Terraform's providers are already on the machine; there is no internet access. You have root through sudo. Everything must still hold after a reboot.

What is graded

The machine is checked, rebooted, and checked again. A check passes only if it passes both times.

CheckObjective
01_blog_retiredRemove one instance of a repeated resource without disturbing the others
02_shop_and_docs_untouchedRemove one instance of a repeated resource without disturbing the others
03_keyed_by_nameKey repeated resources by a stable name instead of a position

Start it

  1. 2Labs
  2. terraform-02select this one
  3. udownload it
  4. sstart the machine

Reading

Where the lab's hints send you, level by level, as you ask for them (h, then l opens a journal section in the TUI).

Theory for this lab

4 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Three of them, to answer here:

Question 1

A resource uses `count = length(var.names)` with `names = ["a", "b", "c"]`. `"a"` is removed. Which instances does the next plan change or destroy?

Question 2

What are the addresses of the instances of `resource "local_file" "vhost" { for_each = { shop = 8100, docs = 8102 } … }`?

Question 3

A resource changes from `count` to `for_each` and the plan says `x.y[1] will be destroyed (because resource does not use count)`. What does that mean?