Your goal
Use Terraform to produce the output Hello, Admiral engineer! and see the same change move through format, initialize, validate, plan, and apply.
Exercise 2 ยท 20 minutes
Create your first configuration, inspect Terraform's proposed change, and apply it locally. No Azure login or cloud resources are required.
Before you start
Use Terraform to produce the output Hello, Admiral engineer! and see the same change move through format, initialize, validate, plan, and apply.
Participant task
Keep this exercise separate from the course website repository.
New-Item -ItemType Directory terraform-exercise-2
Set-Location terraform-exercise-2main.tfAdd the following configuration. terraform_data is built into Terraform, so this exercise does not create a cloud resource or download a provider.
terraform {
required_version = "~> 1.9"
}
variable "learner_name" {
description = "Name used in the greeting"
type = string
default = "Admiral engineer"
}
resource "terraform_data" "greeting" {
input = "Hello, ${var.learner_name}!"
}
output "greeting" {
value = terraform_data.greeting.output
}
Run each command separately. Read the output before moving to the next command.
terraform fmt
terraform init
terraform validateSave the plan, then confirm that Terraform proposes exactly one resource to add and no cloud infrastructure.
terraform plan -out main.tfplanApply the same saved plan you just inspected, then read the output value.
terraform apply main.tfplan
terraform output greetingExpected outcome
terraform validate reports that the configuration is valid, the plan says Plan: 1 to add, 0 to change, 0 to destroy, and the final command prints:
"Hello, Admiral engineer!"Terraform read the desired configuration, proposed a change, recorded the applied result in local state, and exposed a value through an output.
Finish safely
Remove the item from Terraform state, then delete the disposable folder when you no longer need it.
terraform destroyRun a new plan with your own name. Predict the change before reading the plan output.
terraform plan -var="learner_name=Your name"