---
title: "Terraform Cheatsheet"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/terraform
---

[Home](/)›[Cheatsheets](/cheatsheets)

Cheatsheets

# Terraform Cheatsheet

Practical Terraform cheatsheet covering the core CLI commands, state management, import, workspaces, and key HCL patterns for variables, locals, outputs, dynamic blocks, and more. Useful for daily IaC workflows.

12 Categories22 Sections45 ExamplesPublished: 28 Mar 2026

TerraformHCLstate managementIaCvariablesmodules

[Markdown for AI(opens in a new tab)](/terraform/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

Series

[Mastering Terraform](/series/mastering-terraform)1/1

All posts in this series (1)

Cheatsheets1

1.  [Terraform CheatsheetYou are here](/cheatsheets/terraform)

A practical cheatsheet covering the Terraform CLI commands engineers reach for constantly: init, plan, apply, import, taint, and state operations. It also covers the key HCL patterns for variables, locals, outputs, and dynamic blocks.

The sections below cover Terraform commands, syntax, and examples.

[Core CLI Commands](#category-core-cli-commands)

-   [Initialization & Validation](#section-initialization-and-validation)
-   [Plan & Apply](#section-plan-and-apply)
-   [Destroy](#section-destroy)

[State Management](#category-state-management)

-   [State Commands](#section-state-commands)
-   [Import & Taint](#section-import-and-taint)
-   [State Pull & Push](#section-pull-push)

[Workspaces](#category-workspaces)

-   [Workspace Commands](#section-workspace-commands)

[HCL Essentials](#category-hcl-essentials)

-   [Variables, Locals & Outputs](#section-variables-locals-outputs)
-   [Data Sources](#section-data-sources)

[Dynamic Blocks & for\_each](#category-dynamic-patterns)

-   [for\_each & Dynamic Blocks](#section-for-each-and-dynamic)

[Provider Configuration](#category-provider-config)

-   [Provider Patterns](#section-provider-patterns)

[Debugging](#category-debugging)

-   [Logging & Terraform Console](#section-logging-and-console)

[Modules](#category-modules)

-   [Calling a Module](#section-calling-modules)
-   [Source Types & terraform get](#section-module-sources)

[Variables & Outputs](#category-variables-outputs)

-   [Declaration, Types & Validation](#section-variable-declaration)
-   [Supplying Values & Outputs](#section-supplying-values)

[Backends & Remote State](#category-backends-remote-state)

-   [S3 Backend with Native Locking](#section-s3-backend)
-   [Remote State & Migration](#section-remote-state-migration)

[Functions & Expressions](#category-functions-expressions)

-   [Common Built-in Functions](#section-builtin-functions)
-   [for, Conditionals & Console](#section-expressions-console)

[Testing & Validation](#category-testing-validation)

-   [validate & fmt](#section-validate-fmt)
-   [terraform test & Assertions](#section-terraform-test)

No commands found

Try adjusting your search term

## Core CLI Commands

Core Terraform commands for initialization, validation, planning, applying, and destroying infrastructure.

### Initialization & Validation

Commands to set up your Terraform workspace and check configuration validity.

#### Accessibility

Always run terraform init after changing providers, modules, or backend configuration.

#### Best Practices

-   Run terraform init early and often. Commit .terraform.lock.hcl to version control.
-   Use -input=false in automation to avoid interactive prompts.

#### Common Errors

-   **Provider not found. Declare it in the required\_providers block.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** terraform init -migrate-state helps when changing backends.

#### Keywords

terraform init

[Learn more](https://developer.hashicorp.com/terraform/cli/commands/init)

#### Initializes the working directory, downloads providers and modules.

Code

Terminal window

```
terraform init
```

Output

```
1Terraform has been successfully initialized!
```

#### Checks whether the configuration is valid (run after init).

Code

Terminal window

```
terraform validate
```

Output

```
1Success! The configuration is valid.
```

#### Upgrades modules and providers to the latest allowed versions.

Code

Terminal window

```
terraform init -upgrade
```

### Plan & Apply

Preview and execute infrastructure changes safely.

#### Accessibility

Always review the plan output before applying changes.

#### Best Practices

-   Never run terraform apply in production without reviewing the plan first.
-   Use -target for surgical changes, but prefer smaller modules for isolation.

#### Common Errors

-   **Permission denied or authentication issues with the provider.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** terraform apply -replace=resource.address forces replacement without tainting.

#### Keywords

terraform planterraform apply

[Learn more](https://developer.hashicorp.com/terraform/cli/commands/plan)

#### Shows what Terraform will create, change, or destroy.

Code

Terminal window

```
terraform plan
```

#### Saves the plan to a file for later apply.

Code

Terminal window

```
terraform plan -out=plan.tfplan
```

#### Applies a saved plan without prompting.

Code

Terminal window

```
terraform apply plan.tfplan
```

#### Applies changes without confirmation (use in CI/CD).

Code

Terminal window

```
terraform apply -auto-approve
```

### Destroy

Safely remove all managed infrastructure.

#### Best Practices

-   Use with -auto-approve only in controlled environments.

#### Common Errors

-   **Resources with prevent\_destroy lifecycle rule will block destruction.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** terraform plan -destroy shows what will be removed.

#### Keywords

terraform destroy

#### Destroys all resources managed by Terraform.

Code

Terminal window

```
terraform destroy
```

#### Destroys only the targeted resource.

Code

Terminal window

```
terraform destroy -target=aws_instance.example
```

## State Management

Commands for inspecting, manipulating, and synchronizing Terraform state.

### State Commands

Core operations on the Terraform state file.

#### Accessibility

State commands are powerful, always back up state before using them.

#### Best Practices

-   Use terraform state mv when refactoring resource addresses or module structure.
-   Pull state before manual edits and push after.

#### Common Errors

-   **Moving resources incorrectly can lead to orphaned infrastructure.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** terraform state pull > state.tfstate && terraform state push state.tfstate for manual sync.

#### Keywords

state management

[Learn more](https://developer.hashicorp.com/terraform/cli/commands/state)

#### Lists all resources currently tracked in state.

Code

Terminal window

```
terraform state list
```

#### Shows detailed attributes of a specific resource in state.

Code

Terminal window

```
terraform state show aws_instance.example
```

#### Moves or renames a resource in state without recreating it.

Code

Terminal window

```
terraform state mv aws_instance.old aws_instance.new
```

#### Removes a resource from state (does not delete the actual infrastructure).

Code

Terminal window

```
terraform state rm aws_instance.example
```

### Import & Taint

Bring existing resources under management and force recreation.

#### Best Practices

-   After import, run terraform plan and update configuration to match imported state.
-   Prefer import blocks (Terraform 1.5+) for declarative imports.

#### Common Errors

-   **Import succeeds but plan shows drift. The configuration must match reality.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** For count/for\_each resources, use proper addressing like aws\_instance.example\["key"\].

#### Keywords

terraform import

[Learn more](https://developer.hashicorp.com/terraform/cli/commands/import)

#### Imports an existing EC2 instance into Terraform state.

Code

Terminal window

```
terraform import aws_instance.example i-1234567890abcdef0
```

#### Replaces (recreates) a resource on the next apply (preferred over taint).

Code

Terminal window

```
terraform apply -replace=aws_instance.example
```

### State Pull & Push

Synchronize local and remote state files.

#### Best Practices

-   Use only when necessary; let Terraform handle state automatically with backends.

#### Common Errors

-   **Pushing an outdated state can cause conflicts or data loss.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** Always backup state before push operations.

#### Keywords

state management

#### Downloads the current remote state.

Code

Terminal window

```
terraform state pull
```

#### Uploads a local state file to the remote backend.

Code

Terminal window

```
terraform state push state.tfstate
```

## Workspaces

Manage multiple isolated state environments (dev, staging, prod) with the same code.

### Workspace Commands

Create, switch, list, and delete workspaces.

#### Best Practices

-   Use workspaces for environment isolation when using the same configuration.
-   Combine with variable files: terraform apply -var-file=dev.tfvars

#### Common Errors

-   **Deleting a workspace with resources leaves orphaned infrastructure.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** Workspaces are not recommended for large team or complex environment separation. Consider modules or separate repositories.

#### Keywords

terraform workspace

[Learn more](https://developer.hashicorp.com/terraform/cli/commands/workspace)

#### Creates and switches to a new workspace named 'dev'.

Code

Terminal window

```
terraform workspace new dev
```

#### Lists all workspaces (\* indicates current).

Code

Terminal window

```
terraform workspace list
```

#### Switches to the 'prod' workspace.

Code

Terminal window

```
terraform workspace select prod
```

#### Deletes the 'dev' workspace (must not be current).

Code

Terminal window

```
terraform workspace delete dev
```

## HCL Essentials

Core HashiCorp Configuration Language patterns used in every Terraform project.

### Variables, Locals & Outputs

Input variables, computed locals, and exposed outputs.

#### Best Practices

-   Keep variables minimal and descriptive; use locals for derived values to reduce repetition.
-   Always add descriptions to outputs and sensitive = true where needed.

#### Common Errors

-   **Variable not defined. Declare it or pass it via -var or a .tfvars file.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** Use data sources to fetch dynamic values instead of hardcoding in variables.

#### Keywords

variables

#### Defines a variable with default, a local for reuse, and an output.

Code

Terminal window

```
variable "region" {  type = string  default = "us-east-1"}
locals {  common_tags = {    Environment = var.environment    ManagedBy   = "Terraform"  }}
output "vpc_id" {  value       = aws_vpc.main.id  description = "The ID of the VPC"}
```

### Data Sources

Read-only queries for external data.

#### Best Practices

-   Use data sources to avoid hardcoding IDs or dynamic values.

#### Common Errors

-   **Data source returns empty. Check filters and permissions.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** Data sources run during plan and can depend on resources.

#### Keywords

data sources

[Learn more](https://developer.hashicorp.com/terraform/language/data-sources)

#### Fetches the latest Ubuntu AMI for use in resources.

Code

Terminal window

```
data "aws_ami" "ubuntu" {  most_recent = true  owners      = ["099720109477"] # Canonical
  filter {    name   = "name"    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]  }}
```

## Dynamic Blocks & for\_each

Advanced HCL patterns for repeatable configuration.

### for\_each & Dynamic Blocks

Create multiple resource instances and nested blocks dynamically.

#### Best Practices

-   Use for\_each over count for readability and stability (keys instead of indices).
-   Limit dynamic blocks to improve readability; prefer explicit blocks when possible.

#### Common Errors

-   **for\_each value must be a map or set. Convert lists with toset().:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** Nested dynamic blocks are supported with different iterator names.

#### Keywords

for\_each

[Learn more](https://developer.hashicorp.com/terraform/language/expressions/dynamic-blocks)

#### Creates one IAM user per item in the set using for\_each.

Code

Terminal window

```
resource "aws_iam_user" "users" {  for_each = toset(["alice", "bob"])  name     = each.key}
```

#### Generates multiple ingress blocks dynamically from a list/map.

Code

Terminal window

```
resource "aws_security_group" "example" {  name = "example"
  dynamic "ingress" {    for_each = var.ingress_rules    content {      from_port   = ingress.value.from_port      to_port     = ingress.value.to_port      protocol    = ingress.value.protocol      cidr_blocks = ingress.value.cidr_blocks    }  }}
```

## Provider Configuration

Common patterns for configuring Terraform providers.

### Provider Patterns

Declaring and configuring providers, including aliases.

#### Best Practices

-   Declare required\_providers in the root module. Avoid configuring providers inside child modules.
-   Use aliases for multi-region or multi-account deployments.

#### Common Errors

-   **Provider not initialized. Run terraform init after adding providers.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** Pass aliased providers to modules explicitly via the providers = { ... } meta-argument.

#### Keywords

modules

#### Required providers block and basic + aliased configuration.

Code

Terminal window

```
terraform {  required_providers {    aws = {      source  = "hashicorp/aws"      version = "~> 5.0"    }  }}
provider "aws" {  region = var.region}
# Aliased provider for multi-regionprovider "aws" {  alias  = "west"  region = "us-west-2"}
```

## Debugging

Tools and techniques for troubleshooting Terraform issues.

### Logging & Terraform Console

Enable detailed logs and test expressions interactively.

#### Best Practices

-   Start with DEBUG or TRACE only when needed; logs can be extremely verbose.
-   Use terraform console to validate complex expressions before using them in code.

#### Common Errors

-   **No output from console. Make sure you are in a directory with an initialized Terraform config.:** Review documentation or configuration.

#### Advanced Notes

-   **Note:** Set TF\_LOG\_PATH to write logs to a file.

#### Keywords

terraform console

[Learn more](https://developer.hashicorp.com/terraform/internals/debugging)

#### Enables the most verbose logging (TRACE, DEBUG, INFO, WARN, ERROR).

Code

Terminal window

```
TF_LOG=TRACE terraform plan
```

#### Interactive REPL to test expressions and functions.

Code

Terminal window

```
terraform console
```

Output

```
1> join(", ", ["a", "b"])2"a, b"
```

## Modules

Package and reuse configurations with module blocks sourced from local paths, Git, or public/private registries with version pinning.

### Calling a Module

A module block instantiates reusable config; source is required and version applies only to registry sources.

#### Best Practices

-   Keep module interfaces small. Expose IDs and ARNs via output, take everything configurable via variable, and never reach into a module's internal resources from the caller.

#### Common Errors

-   **Module not installed or "Module source has changed" on plan.:** Run terraform init (or terraform get) to fetch modules. After changing source or version you must re-run terraform init. Plain terraform get will not update the lock.

#### Keywords

modulesourceoutputs

#### Call a registry module with a version constraint

Instantiates a child module from the public registry; version is honored only for registry sources.

Code

```
1module "vpc" {2  source  = "terraform-aws-modules/vpc/aws" # NAMESPACE/NAME/PROVIDER3  version = "~> 5.0"                        # pessimistic constraint4  name    = "prod-vpc"5  cidr    = "10.0.0.0/16"6}
```

-   Modules also accept count, for\_each, depends\_on, and an explicit providers mapping.

#### Reference a module output

A module exposes only values declared as output blocks; reach them as module.<name>.<output>.

Code

```
1resource "aws_instance" "web" {2  subnet_id = module.vpc.private_subnet_ids[0] # module.<NAME>.<OUTPUT>3}
```

### Source Types & terraform get

Modules load from local paths, Git, or registries; terraform get and init keep them current.

#### Best Practices

-   Use terraform init -upgrade when intentionally bumping versions and commit the updated lock; use plain terraform init in CI to enforce the locked versions.

#### Keywords

gitregistryterraform get

#### Source a module from Git at a pinned tag

Git source with a subdirectory and a pinned ref for reproducible init.

Code

```
1module "network" {2  # // separates the repo from a subdirectory, ?ref pins a tag/branch/commit3  source = "git::https://github.com/org/repo.git//modules/vpc?ref=v1.4.0"4}
```

-   The GitHub shorthand github.com/org/repo//modules/vpc?ref=v1.4.0 expands to this HTTPS form.

#### Download and upgrade modules

terraform get fetches modules only; init -upgrade also handles providers and rewrites .terraform.lock.hcl.

Code

Terminal window

```
terraform get            # download modules into .terraform/modulesterraform get -update    # upgrade modules to the newest allowedterraform init -upgrade  # upgrade modules AND providers, rewrite the lock
```

## Variables & Outputs

Parameterize configurations with typed, validated inputs and expose results through outputs, supplied via tfvars, flags, or environment.

### Declaration, Types & Validation

Declare typed input variables with optional defaults and custom validation rules checked at plan time.

#### Best Practices

-   Give every input a type and a description, and use validation to reject bad input up front rather than letting the provider fail mid-apply.

#### Keywords

variablevalidationtype

#### Typed variable with a default

Without a default the variable is required; complex types use list(...), map(...), object({...}).

Code

```
1variable "instance_count" {2  type    = number # string | number | bool | list()/set()/map()/object()3  default = 2      # omit default to make the variable required4}
```

#### Enforce allowed values with validation

The validation block fails fast at plan time; error\_message must be a full sentence ending in a period.

Code

```
1variable "env" {2  type = string3  validation {4    condition     = contains(["dev", "staging", "prod"], var.env)5    error_message = "env must be dev, staging, or prod."6  }7}
```

### Supplying Values & Outputs

Values come from tfvars, -var flags, or TF\_VAR\_ env vars by precedence; outputs expose results and can be marked sensitive.

#### Best Practices

-   Mark credential outputs sensitive = true, but remember state is plaintext, so protect the backend rather than relying on sensitive as encryption.

#### Common Errors

-   **"No value for required variable" in non-interactive CI.:** Pass -var/-var-file or set TF\_VAR\_\*, and add -input=false so the run fails fast instead of hanging on a prompt.

#### Keywords

tfvarsTF\_VARoutput

#### Pass variables by flag, file, or environment

Precedence low to high, TF\_VAR\_\* < terraform.tfvars < \*.auto.tfvars < -var/-var-file (last on the line wins).

Code

Terminal window

```
terraform apply -var="instance_count=3"   # inline (highest precedence)terraform apply -var-file="prod.tfvars"    # from a fileexport TF_VAR_instance_count=3             # environment form
```

-   terraform.tfvars and \*.auto.tfvars load automatically; named files need -var-file.

#### Declare an output and read it for scripts

\-raw and -json are the scripting-friendly forms; mark secrets sensitive = true to redact them from CLI and plan output.

Code

Terminal window

```
# output "db_endpoint" { value = aws_db_instance.main.address }terraform output                  # all outputs, human-readableterraform output -json            # machine-readableterraform output -raw db_endpoint # raw string, no quotes
```

## Backends & Remote State

Store state remotely with locking (S3, HCP Terraform) and consume other stacks' outputs via the terraform\_remote\_state data source.

### S3 Backend with Native Locking

Store state in S3 with encryption and a native lockfile (Terraform 1.10+), replacing the deprecated DynamoDB lock table.

#### Best Practices

-   Back up state before any backend change with terraform state pull > backup.tfstate.

#### Common Errors

-   **Error acquiring the state lock (stale lock).:** Resolve the interrupted run, then terraform force-unlock <LOCK\_ID>. Never force-unlock while another apply may still be live.

#### Keywords

backends3locking

#### S3 backend with native lockfile (TF 1.10+)

use\_lockfile uses an S3 conditional-write lock object; requires bucket versioning. dynamodb\_table is deprecated as of 1.11.

Code

```
1terraform {2  backend "s3" {3    bucket       = "my-tf-state"4    key          = "prod/network/terraform.tfstate"5    region       = "us-east-1"6    encrypt      = true7    use_lockfile = true # native S3 lock, no DynamoDB (TF 1.10+)8  }9}
```

-   Enable bucket versioning and encrypt = true; you can run use\_lockfile and dynamodb\_table together during migration, then drop DynamoDB.

### Remote State & Migration

Read another config's outputs with terraform\_remote\_state, connect to HCP Terraform, and migrate between backends.

#### Best Practices

-   Use the cloud block (HCP Terraform, renamed from Terraform Cloud) for managed runs; it is mutually exclusive with a backend block. Run terraform login first.

#### Keywords

terraform\_remote\_statecloudmigrate-state

#### Consume another stack's outputs

Read-only access to another configuration's published outputs; only declared output values are visible.

Code

```
1data "terraform_remote_state" "network" {2  backend = "s3"3  config = {4    bucket = "my-tf-state"5    key    = "prod/network/terraform.tfstate"6    region = "us-east-1"7  }8}9# use: data.terraform_remote_state.network.outputs.private_subnet_ids[0]
```

#### Migrate or reconfigure the backend

\-migrate-state copies existing state into the new backend; -reconfigure discards the old association without copying.

Code

Terminal window

```
terraform init -migrate-state   # copy state into a newly changed backendterraform init -reconfigure     # reinit backend, ignore existing stateterraform init -backend-config=backend.hcl # partial config from a file
```

## Functions & Expressions

Transform and compute values with built-in functions, for/conditional/splat expressions, and the interactive console.

### Common Built-in Functions

Encode/decode data, merge maps, provide defaults, and compute network ranges with built-in functions.

#### Best Practices

-   Reach for try() to handle optional nested attributes, but do not let it silently mask real configuration errors.

#### Keywords

functionstemplatefilejsonencode

#### Everyday functions

templatefile renders external templates (use it instead of the removed template\_file data source); try swallows evaluation errors.

Code

```
1user_data = templatefile("${path.module}/init.tftpl", { port = var.port })2config    = jsonencode({ name = var.name, tags = var.tags })3merged    = merge(var.default_tags, var.extra_tags) # right map wins4name      = coalesce(var.name, "unnamed")           # first non-empty5port      = try(var.settings.port, 8080)            # first that succeeds6subnet    = cidrsubnet("10.0.0.0/16", 8, 4)         # -> 10.0.4.0/24
```

-   jsondecode/yamldecode parse strings back into HCL values; lookup(map, key, default) reads a map with a fallback.

### for, Conditionals & Console

Reshape collections with for expressions, choose with conditionals, collect with splat, and prototype in terraform console.

#### Best Practices

-   Prototype tricky for and function expressions in terraform console before wiring them into config. It evaluates against actual state values.

#### Keywords

forsplatconsole

#### for, conditional, and splat expressions

\[...\] yields a list, {...} yields a map; splat \[\*\] pulls one attribute across every instance.

Code

```
1upper_names   = [for n in var.names : upper(n) if n != ""] # list + filter2by_id         = { for s in var.subnets : s.id => s.cidr }  # produce a map3instance_type = var.env == "prod" ? "m5.large" : "t3.micro" # ternary4all_ips       = aws_instance.web[*].private_ip             # splat
```

#### Prototype expressions in the console

Evaluates functions, variables, and resource attributes against real state without running a plan.

Code

Terminal window

```
terraform console                                  # interactive REPLecho 'cidrsubnet("10.0.0.0/16", 8, 2)' | terraform console # pipe input
```

## Testing & Validation

Validate, format, and test configurations with the native test framework, lifecycle assertions, check blocks, and ecosystem linters.

### validate & fmt

Check syntax and enforce canonical style, with non-mutating forms for CI gates.

#### Best Practices

-   Run terraform fmt -check -recursive and terraform validate as required PR checks so style and basic errors never reach review.

#### Common Errors

-   **terraform validate reports "Backend initialization required".:** Run terraform init -backend=false first, since validate needs providers and modules installed but not a live backend.

#### Keywords

validatefmtci

#### Validate and format

validate needs init first; fmt -check -recursive is the CI-friendly, non-mutating form.

Code

Terminal window

```
terraform validate              # syntax + internal consistencyterraform fmt -check -recursive  # exit non-zero if anything is unformattedterraform fmt -diff              # show changes without writing
```

### terraform test & Assertions

Write native tests in .tftest.hcl and enforce invariants with precondition, postcondition, and check blocks.

#### Best Practices

-   Layer the tools rather than expecting one to cover everything, using terraform validate for correctness, tflint for provider-aware linting, and checkov for security policy.

#### Keywords

testpreconditioncheck

[Learn more](https://developer.hashicorp.com/terraform/language/tests)

#### A native test file (TF 1.6+)

The native framework is stable in Terraform 1.6+; run terraform test to execute every \*.tftest.hcl file.

Code

tests/vpc.tftest.hcl

```
1run "creates_vpc" {2  command   = plan # "plan" (fast) or "apply" (real infra)3  variables { cidr = "10.0.0.0/16" }4  assert {5    condition     = aws_vpc.this.cidr_block == "10.0.0.0/16"6    error_message = "VPC CIDR did not match input."7  }8}
```

-   Prefer command = plan for fast unit-style assertions; command = apply creates then destroys real infrastructure.

#### Lifecycle and check assertions

precondition/postcondition (TF 1.2+) hard-stop on failure; check blocks (TF 1.5+) only warn, good for post-deploy validation.

Code

```
1lifecycle {2  precondition {3    condition     = data.aws_ami.selected.architecture == "x86_64"4    error_message = "AMI must be x86_64."5  }6}7# check "health" { ... } -> failed check is a WARNING, not an error (TF 1.5+)
```

Was this useful?

## Tags

#Terraform#HCL#State management#IaC#Variables#Modules

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fterraform "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=Terraform%20Cheatsheet&url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fterraform "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fterraform&title=Terraform%20Cheatsheet&summary=Practical%20Terraform%20cheatsheet%20covering%20the%20core%20CLI%20commands%2C%20state%20management%2C%20import%2C%20workspaces%2C%20and%20key%20HCL%20patterns%20for%20variables%2C%20locals%2C%20outputs%2C%20dynamic%20blocks%2C%20and%20more.%20Useful%20for%20daily%20IaC%20workflows.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=Terraform%20Cheatsheet%20https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fterraform "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fterraform&text=Terraform%20Cheatsheet "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fterraform&title=Terraform%20Cheatsheet "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fterraform&t=Terraform%20Cheatsheet "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fterraform&media=&description=Practical%20Terraform%20cheatsheet%20covering%20the%20core%20CLI%20commands%2C%20state%20management%2C%20import%2C%20workspaces%2C%20and%20key%20HCL%20patterns%20for%20variables%2C%20locals%2C%20outputs%2C%20dynamic%20blocks%2C%20and%20more.%20Useful%20for%20daily%20IaC%20workflows. "Share on Pinterest")[Email](<mailto:?subject=Terraform%20Cheatsheet&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fterraform>)

## Comments

## You might also enjoy

More posts on similar topics

## [AWS CLI](/cheatsheets/aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   Cloud Computing
-   AWS
-   DevOps
-   CLI
-   Automation

The AWS Command Line Interface (CLI) lets you orchestrate infrastructure, move cloud data, and configure security entirely from the terminal. This reference covers configuring identity profiles, manag

#AWS CLI#EC2#S3+4 tags

[read more](/cheatsheets/aws-cli)

## [Docker Swarm](/cheatsheets/docker-swarm)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   DevOps
-   Docker
-   Containers
-   Orchestration
-   Deployment

This cheatsheet is a reference for managing Docker Swarm clusters, services, and stacks. It covers the commands and best practices for scaling, updating, and monitoring your swarm applications.

#Docker Swarm#Orchestration#Containers+4 tags

[read more](/cheatsheets/docker-swarm)

## [kubectl](/cheatsheets/kubectl)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   DevOps
-   Kubernetes
-   CLI
-   Container Orchestration
-   Cloud Native

kubectl is the command-line tool you use to talk to a Kubernetes cluster. Whatever you can do through a dashboard, you can do faster here: deploy apps, inspect resources, stream logs, run commands ins

#Kubectl#Kubernetes#K8s+5 tags

[read more](/cheatsheets/kubectl)

## [Linux Networking](/cheatsheets/linux-networking)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   Linux
-   Networking
-   DevOps
-   CLI
-   SysAdmin

Every Linux box speaks the network through a small set of tools, and knowing them turns "the network is broken" into a specific, fixable answer. This cheatsheet covers the modern stack: ip for inter

#Linux networking#Ip command#Tcpdump+5 tags

[read more](/cheatsheets/linux-networking)

## [GitHub Actions](/cheatsheets/github-actions)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   CI/CD
-   DevOps
-   GitHub
-   Automation
-   YAML

GitHub Actions runs your CI/CD directly from YAML files in .github/workflows/, and most of the job is knowing which key does what. A workflow reacts to events, splits into jobs that run on runners,

#GitHub Actions#Workflow#CI/CD+5 tags

[read more](/cheatsheets/github-actions)

## [Docker](/cheatsheets/docker)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   DevOps
-   Docker
-   Containers
-   Deployment

Docker is a containerization platform that packages applications with their dependencies into isolated, portable environments called containers. It enables developers to build, ship, and run applicati

#Docker#Containers#Images+3 tags

[read more](/cheatsheets/docker)

6 related posts
