Terraform Associate (004) – Exam Cheat Sheet

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.
1. Terraform Core Workflow
Core Commands
terraform init # Initialize providers & backend
terraform plan # Preview execution plan
terraform apply # Apply changes
terraform destroy # Destroy resources
Typical Workflow
Write
.tffilesterraform initterraform planterraform apply
2. Terraform Configuration Basics
Blocks
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 |
3. Providers
Provider Types
Official
Partner
Community
Provider Configuration
provider "aws" {
region = "us-east-1"
}
Version Constraints
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
4. Variables
Declare Variables
variable "filename" {
type = string
description = "File name"
default = "/tmp/file.txt"
}
Types
string
number
bool
list(type)
map(type)
object({})
tuple([])
Variable Precedence (High → Low)
CLI
var.tfvarsorvar-fileEnvironment (
TF_VAR_name)Default
5. Resource Attributes & References
${resource_type.resource_name.attribute}
Example:
aws_instance.web.public_ip
6. Dependencies
Implicit
instance_id = aws_instance.web.id
Explicit
depends_on = [aws_instance.web]
7. Output Values
output "public_ip" {
value = aws_instance.web.public_ip
}
Commands:
terraform output
terraform output public_ip
8. Terraform State
Purpose
Maps config → real infrastructure
Tracks metadata & dependencies
State Storage
Local (default)
Remote (recommended):
S3
Terraform Cloud
GCS
Consul
Remote state locking is available, depending on whether the backend supports
Remote Backend (S3 Example)
terraform {
backend "s3" {
bucket = "tf-state-bucket"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
}
}
9. Terraform State Commands
terraform state list
terraform state show <resource>
terraform state mv
terraform state rm
terraform state pull
10. Lifecycle Rules
lifecycle {
create_before_destroy = true
prevent_destroy = true
ignore_changes = [tags]
}
11. Meta-Arguments
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 vs for_each
count→ indexed listfor_each→ map or set
12. Data Sources
Used to read existing resources:
data "aws_ami" "amazon_linux" {
most_recent = true
}
13. Provisioners (Use Sparingly)
Local Exec
provisioner "local-exec" {
command = "echo Hello"
}
Remote Exec
Requires SSH access.
⚠️ Not recommended for production
14. Terraform Import
terraform import aws_instance.web i-123456
⚠️ Does NOT generate .tf code. Only updates the state file.
15. Terraform Workspaces
terraform workspace new dev
terraform workspace list
terraform workspace select dev
Each workspace has separate state.
16. Terraform Functions (Important)
https://developer.hashicorp.com/terraform/language/functions
Numeric
max()min()ceil()floor()
String
lower()upper()split()join()substr()
Collection
length()contains()element()lookup()
17. Terraform Console
terraform console
Used for testing expressions.
18. Debugging
export TF_LOG=TRACE
export TF_LOG_PATH=/tmp/terraform.log
Levels:
TRACE
DEBUG
INFO
WARN
ERROR
19. Terraform Modules
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
}
Commands:
terraform get
20. Security Best Practices
Never commit
terraform.tfstateUse
.gitignoreEncrypt remote state
Use least privilege
21. Quick Commands Summary
terraform init
terraform plan
terraform apply
terraform destroy
terraform fmt
terraform validate
terraform providers
terraform output
terraform graph
terraform workspace list
22. HCP Terraform
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





