Terraform Associate (004) – Exam Cheat Sheet

Search for a command to run...

No comments yet. Be the first to comment.
Network wide ad-blocking in your home internet

On My Basement Kubernetes Cluster (With Optional S3 Backups)

I've recently configured the Prometheus and Grafana stack on my Kubernetes cluster to monitor system performance, including memory, CPU, and network usage. In this post, I’ll walk you through how I integrated Prometheus into my Spring Boot applicatio...

In the last blog, I configured an ArgoCD-based GitOps pipeline and deployed my distributed app called vote-app. In this post, I’ll walk through how to set up Prometheus and Grafana to monitor the Kubernetes cluster and track resource usage of the vot...

This cheat sheet is based on my notes from online courses, Hashicorp documentation, and missing & updated concepts for the Terraform Associate 004 exam after completing the exam. It is optimized for quick revision before the exam.
terraform init # Initialize providers & backend
terraform plan # Preview execution plan
terraform apply # Apply changes
terraform destroy # Destroy resources
Write .tf files
terraform init
terraform plan
terraform apply
resource "aws_instance" "example" {}
| Block | Purpose |
| provider | Define cloud provider |
| resource | Infrastructure object |
| variable | Input variable |
| output | Export values |
| data | Read external data |
| module | Reusable configuration |
| terraform | Backend & version config |
| action | Invoke provider-defined action |
| check | Validate your infrastructure |
| ephermal | define temporary resources |
| import | import existing infrastructure |
| locals | define values and reuse |
| moved | change the address of a resource |
| removed | remove from state without changing infra |
Official
Partner
Community
provider "aws" {
region = "us-east-1"
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
Version rules:
>= 1.2.0
<= 2.0.0
~> 1.2 → >=1.2,<2.0
!= 1.4.0
variable "filename" {
type = string
description = "File name"
default = "/tmp/file.txt"
}
string
number
bool
list(type)
map(type)
object({})
tuple([])
CLI var
.tfvars or var-file
Environment (TF_VAR_name)
Default
${resource_type.resource_name.attribute}
Example:
aws_instance.web.public_ip
instance_id = aws_instance.web.id
depends_on = [aws_instance.web]
output "public_ip" {
value = aws_instance.web.public_ip
}
Commands:
terraform output
terraform output public_ip
Maps config → real infrastructure
Tracks metadata & dependencies
Local (default)
Remote (recommended):
S3
Terraform Cloud
GCS
Consul
Remote state locking is available, depending on whether the backend supports
terraform {
backend "s3" {
bucket = "tf-state-bucket"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
}
}
terraform state list
terraform state show <resource>
terraform state mv
terraform state rm
terraform state pull
lifecycle {
create_before_destroy = true
prevent_destroy = true
ignore_changes = [tags]
}
https://developer.hashicorp.com/terraform/language/meta-arguments
| Argument | Description |
| depends_on | Explicit dependency |
| count | Create multiple resources |
| for_each | Iterate over map/set |
| lifecycle | Control resource behavior |
| provider | specifies which provider to use |
| providers | specify an alternate provider specification |
count → indexed list
for_each → map or set
Used to read existing resources:
data "aws_ami" "amazon_linux" {
most_recent = true
}
provisioner "local-exec" {
command = "echo Hello"
}
Requires SSH access.
⚠️ Not recommended for production
terraform import aws_instance.web i-123456
⚠️ Does NOT generate .tf code. Only updates the state file.
terraform workspace new dev
terraform workspace list
terraform workspace select dev
Each workspace has separate state.
https://developer.hashicorp.com/terraform/language/functions
max()
min()
ceil()
floor()
lower()
upper()
split()
join()
substr()
length()
contains()
element()
lookup()
terraform console
Used for testing expressions.
export TF_LOG=TRACE
export TF_LOG_PATH=/tmp/terraform.log
Levels:
TRACE
DEBUG
INFO
WARN
ERROR
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
}
Commands:
terraform get
Never commit terraform.tfstate
Use .gitignore
Encrypt remote state
Use least privilege
terraform init
terraform plan
terraform apply
terraform destroy
terraform fmt
terraform validate
terraform providers
terraform output
terraform graph
terraform workspace list
The HashiCorp Cloud Platform — https://developer.hashicorp.com/terraform/cloud-docs
In my experience in this exam, you have to know what they are; there is no need to dig deep, so briefly review these topics, and let me know your experience:
Users
Teams
Organizations
Permissions
Stacks & Workspaces
Integration with VCS (Version Control Systems)
Private registry
Automatic health checks
Run triggers