Skip to main content
In this hands-on lab, you’ll learn how to configure, apply, and manage output variables in OpenTofu using the random provider. By the end, you’ll be able to expose resource attributes and query them on demand.

1. Setup and Resource Configuration

  1. Change into the sample project directory:
  2. Examine the HCL files defining nine resources with the random provider:
  3. Open the accompanying output.tf to see how each resource is exposed as an output variable.

2. Initialize, Plan, and Apply

Initialize the working directory, preview the plan, and apply the configuration.
After a successful apply, you should see:
You can learn more about OpenTofu and output variables in the official Terraform Output Variables documentation.

3. Querying Individual Outputs

Test your understanding:
  1. What is the value of id2?
    From the example above, id2 = "9687669a-73d4-9717-52a2-6497826815a1".
  2. What is the value of order1?
    It is 16106.
You can also fetch specific outputs:

4. Inspecting a New Configuration

Switch to the second lab directory and review main.tf:
In main.tf, you’ll find:
If the image below doesn’t render, use the code snippet above to verify your setup.
The image shows a coding environment with a task about inspecting configuration files in a directory. It includes a code editor displaying Terraform code and a terminal window, along with a multiple-choice question about the value of a variable.
Confirm the output:

5. Adding a New Output Variable

The same main.tf defines a local_file resource:
Add an output block below it to capture the file’s content:
Save your changes, then re-run the workflow:
Finally, verify the new output:
Congratulations! You’ve successfully configured and managed OpenTofu output variables.

Watch Video

Practice Lab