41/53
Sign inSign up free

857. Adopt an Existing Value With an import Block

medium 20 XP ~9 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/indexer has never been applied. It picks a listening port with random_integer.port (between 8000 and 8999) and writes /home/student/out/listen.conf. But the service already runs on port 8123, assigned by hand (see ports.txt), and the firewall rules depend on it. A plain tofu apply would pick a random new port.

Task

Bring the existing port under management with an import block, so that after your apply:

  • random_integer.port in the state has the result 8123 (min 8000, max 8999),
  • /home/student/out/listen.conf contains listen 8123,
  • a new plan shows no changes.

The random provider imports a random_integer from an ID of the form RESULT,MIN,MAX.

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.