First terraform_data configuration
A first resource without a cloud account
Terraform normally manages objects through providers. For your first exercise, use terraform_data, a resource included with Terraform itself. It tracks a value through the ordinary create, update and delete lifecycle without creating a virtual machine, network or other external service. This is an offline reading exercise until you have an approved Terraform executable and disposable workspace. The inherited exact version constraint below is provisional, not a recommendation to install an unreviewed binary.
terraform { required_version = "= 1.14.8"}
resource "terraform_data" "greeting" { input = "hello-bytemind"}
output "greeting" { value = terraform_data.greeting.output}After a successful apply in the isolated fixture, the expected greeting is hello-bytemind. This is a predicted result, not a captured terminal run.
Read the configuration from top to bottom
The terraform block restricts the CLI version that may use this configuration. It does not install that version. The resource block declares a resource of type terraform_data and local name greeting. Its address is terraform_data.greeting. The input argument is the value that the resource should store in state. The output block declares a root-module output called greeting; its value expression reads the resource’s output attribute. Notice that the resource name and output name happen to match, but they belong to different namespaces.
Follow the value
The input is written as a string. Terraform can use the reference terraform_data.greeting.output to connect the resource to the named root output. Before the first apply, the computed resource output can appear unknown in the plan even though the input is known. Unknown means the value has not yet been resolved for this operation, not that it is an empty string. After a successful apply, the stored value can be inspected using the output command in the final lesson of this chapter. The resource has an internally generated identity; do not expect a fixed ID.
Example: two names, one value
This is an alternative complete configuration body to read on paper. Use it instead of the greeting resource and output, not in addition to them. Keep the same version block if using the isolated fixture.
resource "terraform_data" "course" { input = "infrastructure-basics"}
output "course_label" { value = terraform_data.course.output}The address is terraform_data.course, but the output is named course_label. The expected value after apply is infrastructure-basics. There is no separate cloud provider to configure for this example; the built-in provider is part of Terraform.
Avoid common mistakes
Do not write terraform_data.course_label.output: the address uses the declared resource name, not the output name. Do not quote the entire reference, because that makes it a literal string instead of an expression. Saving a file does not execute Terraform. Also, do not use a real password as input; this value is stored in state. The built-in resource is not a general replacement for provider-managed cloud resources.
Practice and next step
Trace the alternative example from input to root output. Write down the resource address, output name and expected value. Next, learn how to prepare and check the configuration before asking Terraform to plan. Related reference: First terraform_data configuration.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
First terraform_data configuration — knowledge check
Check the concepts and decisions introduced in this lesson.
What does terraform_data manage in this lab?
What is the address of resource "terraform_data" "course"?
What does value = terraform_data.course.output read?
What does an unresolved output in a first plan mean?
Why use synthetic strings for input?