& Terraform Purpose
βοΈ Terraform
CLI & Workflow
π HCL &
Configuration
π State &
Modules
What is Infrastructure as Code (IaC)?
Terraform uses a declarative approach to defining infrastructure. What does “declarative” mean in this context?
Which of the following is a key advantage of Terraform over cloud-specific IaC tools like AWS CloudFormation?
Terraform CLI & Core Workflow
Domains 3-4 β Commands & Workflow
What is the correct order of the core Terraform workflow?
terraform init downloads providers and initializes the backend; (3) Plan β terraform plan previews changes without applying; (4) Apply β terraform apply executes the plan and creates/modifies resources. Optional: terraform destroy removes all managed resources. This workflow is the most tested concept.What does terraform init do?
terraform init is the first command you run in any Terraform project. It: downloads required provider plugins (AWS, Azure, etc.), initializes the state backend (local or remote like S3/Terraform Cloud), downloads referenced modules, and creates the .terraform directory. It must be re-run when providers, modules, or backend configuration change. It is safe to run multiple times (idempotent).What does terraform plan do?
terraform plan compares the desired state (your .tf files) with the current state (terraform.tfstate) and generates an execution plan showing what will be created (+), changed (~), or destroyed (-). It does NOT modify any infrastructure β it’s a dry run. This is essential for reviewing changes before applying. You can save a plan with -out=planfile and apply it later with terraform apply planfile.HCL & Configuration
Domains 5-7 β Variables, Outputs, Resources
In Terraform HCL, which block type is used to define a piece of infrastructure such as an EC2 instance or an S3 bucket?
variableresource β
outputproviderresource block is the most important block in Terraform β it defines an infrastructure object. Syntax: resource "aws_instance" "web" { ... }. The first label is the resource type (from the provider), the second is the local name. variable accepts input, output returns values, provider configures the cloud platform. data sources read existing infrastructure.Which Terraform block is used to read information about existing infrastructure that was NOT created by the current Terraform configuration?
resourcedata β
modulelocalsdata source (data block) allows Terraform to query and use information from existing infrastructure not managed by the current config. Example: data "aws_ami" "latest" { ... } fetches the latest AMI ID. Data sources are read-only β they don’t create or modify resources. resource creates new infrastructure, module encapsulates reusable config, and locals define computed values.What is the order of precedence (highest to lowest) for variable values in Terraform?
-var and -var-file CLI flags, (2) *.auto.tfvars files (alphabetical), (3) terraform.tfvars, (4) TF_VAR_ environment variables, (5) variable default values. If no value is found and no default is set, Terraform prompts for input. This precedence order is a commonly tested exam topic.How do you mark a Terraform variable as sensitive so its value is redacted from CLI output and logs?
sensitive = true in the variable block β
-hide CLI flagsensitive = true to a variable block tells Terraform to redact the value in plan/apply output and logs. Example: variable "db_password" { type = string; sensitive = true }. Note: the value is still stored in the state file in plaintext β so encrypt your state file and use remote backends. Sensitive values also propagate to outputs that reference them.State Management & Modules
Domains 8-9 β State, Backends, Modules
What is the purpose of the Terraform state file (terraform.tfstate)?
Why should the Terraform state file be stored in a remote backend for team environments?
What is a Terraform module?
What does the terraform fmt command do?
terraform fmt rewrites .tf files to follow HashiCorp’s canonical formatting style β consistent indentation, alignment, and spacing. It ensures code readability and consistency across teams. terraform validate checks syntax and internal consistency (different command). terraform fmt -check returns a non-zero exit code if formatting changes are needed β useful in CI/CD pipelines.π Terraform Core Workflow
β¨οΈ Must-Know Terraform Commands
download providers
(dry run)
create resources
resources
files
consistency
values
in state
π§± Key HCL Block Types
π‘ Terraform Associate Exam Tips
terraform state list, state show, state mv, and state rm. State questions make up ~15-20% of the exam.π― Keep Practicing β More MCQs Available!
We update our question bank regularly to match the latest HashiCorp exam objectives
Β


Leave a Comment