Getting started without cloud resources¶
Goal: inspect a plan, record a local value, and clean it up.
Install¶
Install Terraform CLI, VS Code, and the HashiCorp Terraform extension. Use your platform's official installer and verify:
terraform version
The examples require Terraform 1.7 or later; CI records an exact tested version. The first lab uses the built-in provider and needs no Azure account. Clone the repository or choose Code > Download ZIP:
git clone https://github.com/brown9804/Terraform-Overview.git
cd Terraform-Overview
Read the source¶
terraform {
required_version = ">= 1.7, < 2.0"
}
variable "project_name" {
description = "Lowercase project name used to demonstrate inputs and state."
type = string
default = "learning"
validation {
condition = can(regex("^[a-z][a-z0-9-]{2,19}$", var.project_name))
error_message = "Use 3-20 lowercase letters, digits, or hyphens, beginning with a letter."
}
}
resource "terraform_data" "project" {
input = {
name = var.project_name
goal = "Understand plan, apply, state, and destroy without cloud resources."
}
}
output "project_name" {
description = "The name recorded by the built-in Terraform data resource."
value = terraform_data.project.output.name
}
terraform_data manages a record in Terraform state; it does not call Azure
or create a file through a cloud provider.
The resource address is terraform_data.project.
The input variable has a validated default, and the output reads the
resource's resulting value.
Initialize, validate, and preview¶
terraform -chdir=examples/01-first-plan init
terraform -chdir=examples/01-first-plan validate
terraform -chdir=examples/01-first-plan test
terraform -chdir=examples/01-first-plan plan
Expected: successful validation/tests and a plan adding one resource.
The resource's output may be unknown until apply. init prepares the directory;
plan has not created the managed record.
Apply locally¶
terraform -chdir=examples/01-first-plan apply
terraform -chdir=examples/01-first-plan output
terraform -chdir=examples/01-first-plan state list
Read the plan and type the requested confirmation. Expected output:
project_name = "learning". State lists terraform_data.project.
An immediate second plan should report no changes.
Change an input and compare¶
terraform -chdir=examples/01-first-plan plan -var="project_name=second-lab"
Expected: an input update, not an Azure operation. Do not assume the same behavior for a cloud resource: changing some provider attributes can force replacement. Always inspect each resource's planned action.
Cleanup¶
terraform -chdir=examples/01-first-plan destroy
terraform -chdir=examples/01-first-plan state list
After confirming destruction, the state list is empty. Ignored local state files may still exist; remove them only after you no longer need the lab. For Azure, deleting a state file does not delete resources.
Exercise: use an invalid uppercase name and identify the variable validation error. Continue with language.