1/75
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
terraform block
Top-level settings for Terraform like requiredversion, requiredproviders, backend, and cloud.
required_providers block
Declares provider sources and version constraints for the configuration.
provider block
Configuration for using the provider.
provider alias
Additional named provider configuration (alias = "x") used to target multiple regions/accounts/subscriptions.
providers meta-argument (module)
Passes specific provider configurations into a module (ex: aws = aws.west).
resource block
Declares infrastructure Terraform will create/manage (resource "TYPE" "NAME").
data block
Reads existing information from a provider API without creating resources.
module block
Calls a reusable module and passes input variables to it.
output block
Exposes a value from a module/workspace so other modules or tools can consume it.
variable block
Declares an input variable.
locals block
Defines local values (locals) used for reuse/clarity, computed from expressions.
terraform cloud block
Connects the config to an HCP Terraform/Terraform Cloud workspace for remote runs and state.
terraform backend block
Configures where Terraform stores state (S3, azurerm, gcs, local) and locking.
lifecycle block
Controls resource behavior like createbeforedestroy and ignore_changes.
moved block
Declares a resource was renamed or moved (from → to) so Terraform updates state and avoids recreate.
import block
Declaratively imports an existing real resource into state by mapping id to a resource address.
dynamic block
Generates repeated nested blocks inside a resource from a collection (not multiple resources).
precondition block
Lifecycle check that must be true before a resource is created/updated.
postcondition block
Lifecycle check that must be true after a resource is created/updated/refreshed.
variable validation block
Validates input variable values and errors early if conditions fail.
depends_on meta-argument
Forces explicit dependencies when Terraform can’t infer them from references.
count meta-argument
Creates multiple instances using an integer index (count.index), less stable than for_each.
for_each meta-argument
Creates multiple instances from a map or set with stable keys (each.key/each.value).
each.key
The instance key when using for_each (map key or set value).
each.value
The instance value when using for_each (map value or set value).
count.index
Zero-based index for instances created with count.
var.<variable_name>
References an input variable value.
local.
References a local value.
module.<MODULE_NAME>.<OUTPUT_NAME>
References an output value from a child module.
resource_type.resource_name.attribute
References a resource attribute (ex: aws_vpc.main.id).
data.
References a data source attribute (ex: data.aws_vpc.main.id).
splat expression [*]
Collects an attribute from all instances (ex: aws_instance.app[*].id).
full splat vs legacy splat
Use awsinstance.app[*].id (preferred) rather than awsinstance.app.*.id (legacy).
indexing list [0]
Accesses an element by numeric index (ex: var.subnets[0]).
map key access ["tags"]
Accesses a map value by key, useful when key is computed or has special characters.
attribute access .id
Reads the id attribute returned by provider (commonly exists for resources/data sources).
terraform console
Interactive REPL to evaluate expressions and inspect values.
toset()
Converts a list/tuple to a set (deduplicates, no ordering).
tolist()
Converts a set/tuple to a list (ordering may be arbitrary when source is a set).
tomap()
Converts an object to a map (or coerces compatible types).
format()
Builds a formatted string (format("%s-%s", var.env, var.name)).
join()
Joins a list of strings into one string with a delimiter (join("-", ["a","b"])).
split()
Splits a string into a list by delimiter (split(",", "a,b")).
lookup()
Safely fetches a value from a map with a default (lookup(var.tags, "env", "dev")).
try()
Returns the first non-error expression result (try(var.a, var.b, "default")).
can()
Returns true if an expression would succeed (can(regex("x", var.s))).
coalesce()
Returns the first non-null/non-empty value from arguments.
merge()
Merges multiple maps/objects into one. If keys overlap, the later value wins.
concat()
Concatenates lists into a single list.
length()
Returns the length of a list, set, or map.
keys()
Returns the keys of a map as a list.
values()
Returns the values of a map as a list.
for expression
Builds a new list/map from a collection (ex: [for x in var.list : upper(x)]).
conditional operator ? :
Chooses between two values based on a boolean (var.env == "prod" ? 3 : 1).
type constraint string
Forces the value to be a string (text). Terraform will error if a non-string is provided (unless it can be safely converted).
type constraint number
Variable type for numeric values.
type constraint bool
Variable type for true/false values.
type constraint list(TYPE)
Ordered collection of values of one type (ex: list(string)).
type constraint set(TYPE)
Unordered unique collection (ex: set(string)).
type constraint map(TYPE)
Map of string keys to values of one type (ex: map(string)).
type constraint object({…})
Structured object with named attributes and types.
type constraint tuple([…])
Fixed-length ordered collection with specified types.
optional() in object type
Marks an object attribute optional, can provide a default (Terraform versions that support it).
null
Represents “no value,” often used to conditionally omit arguments.
sensitive = true (variable/output)
Hides value from CLI output, but does not guarantee it won’t be stored in state.
depends_on (module)
Forces module to wait on resources/modules when references aren’t present.
path.module
Filesystem path of the current module directory.
path.root
Filesystem path of the root module directory.
path.cwd
Current working directory where Terraform is invoked.
file()
Reads a file from disk into a string.
templatefile()
Renders a template file with variables (safer than inline string building).
jsonencode()
Converts a value to a JSON string.
jsondecode()
Parses a JSON string into a Terraform value.
yamldecode()
Parses YAML into a Terraform value.
regex()
Applies a regex and returns matches (errors if no match).
regexall()
Returns all regex matches (empty list if none).