Terraform Associate 004 - Blocks, Functions, & Meta-Args

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/75

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

76 Terms

1
New cards

terraform block

Top-level settings for Terraform like requiredversion, requiredproviders, backend, and cloud.

2
New cards

required_providers block

Declares provider sources and version constraints for the configuration.

3
New cards

provider block

Configuration for using the provider.

4
New cards

provider alias

Additional named provider configuration (alias = "x") used to target multiple regions/accounts/subscriptions.

5
New cards

providers meta-argument (module)

Passes specific provider configurations into a module (ex: aws = aws.west).

6
New cards

resource block

Declares infrastructure Terraform will create/manage (resource "TYPE" "NAME").

7
New cards

data block

Reads existing information from a provider API without creating resources.

8
New cards

module block

Calls a reusable module and passes input variables to it.

9
New cards

output block

Exposes a value from a module/workspace so other modules or tools can consume it.

10
New cards

variable block

Declares an input variable.

11
New cards

locals block

Defines local values (locals) used for reuse/clarity, computed from expressions.

12
New cards

terraform cloud block

Connects the config to an HCP Terraform/Terraform Cloud workspace for remote runs and state.

13
New cards

terraform backend block

Configures where Terraform stores state (S3, azurerm, gcs, local) and locking.

14
New cards

lifecycle block

Controls resource behavior like createbeforedestroy and ignore_changes.

15
New cards

moved block

Declares a resource was renamed or moved (from → to) so Terraform updates state and avoids recreate.

16
New cards

import block

Declaratively imports an existing real resource into state by mapping id to a resource address.

17
New cards

dynamic block

Generates repeated nested blocks inside a resource from a collection (not multiple resources).

18
New cards

precondition block

Lifecycle check that must be true before a resource is created/updated.

19
New cards

postcondition block

Lifecycle check that must be true after a resource is created/updated/refreshed.

20
New cards

variable validation block

Validates input variable values and errors early if conditions fail.

21
New cards

depends_on meta-argument

Forces explicit dependencies when Terraform can’t infer them from references.

22
New cards

count meta-argument

Creates multiple instances using an integer index (count.index), less stable than for_each.

23
New cards

for_each meta-argument

Creates multiple instances from a map or set with stable keys (each.key/each.value).

24
New cards

each.key

The instance key when using for_each (map key or set value).

25
New cards

each.value

The instance value when using for_each (map value or set value).

26
New cards

count.index

Zero-based index for instances created with count.

27
New cards

var.<variable_name>

References an input variable value.

28
New cards

local.

References a local value.

29
New cards

module.<MODULE_NAME>.<OUTPUT_NAME>

References an output value from a child module.

30
New cards

resource_type.resource_name.attribute

References a resource attribute (ex: aws_vpc.main.id).

31
New cards

data...

References a data source attribute (ex: data.aws_vpc.main.id).

32
New cards

splat expression [*]

Collects an attribute from all instances (ex: aws_instance.app[*].id).

33
New cards

full splat vs legacy splat

Use awsinstance.app[*].id (preferred) rather than awsinstance.app.*.id (legacy).

34
New cards

indexing list [0]

Accesses an element by numeric index (ex: var.subnets[0]).

35
New cards

map key access ["tags"]

Accesses a map value by key, useful when key is computed or has special characters.

36
New cards

attribute access .id

Reads the id attribute returned by provider (commonly exists for resources/data sources).

37
New cards

terraform console

Interactive REPL to evaluate expressions and inspect values.

38
New cards

toset()

Converts a list/tuple to a set (deduplicates, no ordering).

39
New cards

tolist()

Converts a set/tuple to a list (ordering may be arbitrary when source is a set).

40
New cards

tomap()

Converts an object to a map (or coerces compatible types).

41
New cards

format()

Builds a formatted string (format("%s-%s", var.env, var.name)).

42
New cards

join()

Joins a list of strings into one string with a delimiter (join("-", ["a","b"])).

43
New cards

split()

Splits a string into a list by delimiter (split(",", "a,b")).

44
New cards

lookup()

Safely fetches a value from a map with a default (lookup(var.tags, "env", "dev")).

45
New cards

try()

Returns the first non-error expression result (try(var.a, var.b, "default")).

46
New cards

can()

Returns true if an expression would succeed (can(regex("x", var.s))).

47
New cards

coalesce()

Returns the first non-null/non-empty value from arguments.

48
New cards

merge()

Merges multiple maps/objects into one. If keys overlap, the later value wins.

49
New cards

concat()

Concatenates lists into a single list.

50
New cards

length()

Returns the length of a list, set, or map.

51
New cards

keys()

Returns the keys of a map as a list.

52
New cards

values()

Returns the values of a map as a list.

53
New cards

for expression

Builds a new list/map from a collection (ex: [for x in var.list : upper(x)]).

54
New cards

conditional operator ? :

Chooses between two values based on a boolean (var.env == "prod" ? 3 : 1).

55
New cards

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).

56
New cards

type constraint number

Variable type for numeric values.

57
New cards

type constraint bool

Variable type for true/false values.

58
New cards

type constraint list(TYPE)

Ordered collection of values of one type (ex: list(string)).

59
New cards

type constraint set(TYPE)

Unordered unique collection (ex: set(string)).

60
New cards

type constraint map(TYPE)

Map of string keys to values of one type (ex: map(string)).

61
New cards

type constraint object({…})

Structured object with named attributes and types.

62
New cards

type constraint tuple([…])

Fixed-length ordered collection with specified types.

63
New cards

optional() in object type

Marks an object attribute optional, can provide a default (Terraform versions that support it).

64
New cards

null

Represents “no value,” often used to conditionally omit arguments.

65
New cards

sensitive = true (variable/output)

Hides value from CLI output, but does not guarantee it won’t be stored in state.

66
New cards

depends_on (module)

Forces module to wait on resources/modules when references aren’t present.

67
New cards

path.module

Filesystem path of the current module directory.

68
New cards

path.root

Filesystem path of the root module directory.

69
New cards

path.cwd

Current working directory where Terraform is invoked.

70
New cards

file()

Reads a file from disk into a string.

71
New cards

templatefile()

Renders a template file with variables (safer than inline string building).

72
New cards

jsonencode()

Converts a value to a JSON string.

73
New cards

jsondecode()

Parses a JSON string into a Terraform value.

74
New cards

yamldecode()

Parses YAML into a Terraform value.

75
New cards

regex()

Applies a regex and returns matches (errors if no match).

76
New cards

regexall()

Returns all regex matches (empty list if none).

Explore top flashcards

Period 3 WHAP Vocab
Updated 745d ago
flashcards Flashcards (244)
BIS 2B Midterm 1
Updated 722d ago
flashcards Flashcards (157)
Baron - Cohen
Updated 1017d ago
flashcards Flashcards (60)
1920s
Updated 1080d ago
flashcards Flashcards (101)
Linear Algebra Vocab
Updated 985d ago
flashcards Flashcards (40)
Clustering Analysis
Updated 1168d ago
flashcards Flashcards (38)
Topic 3 Computers
Updated 975d ago
flashcards Flashcards (35)
Period 3 WHAP Vocab
Updated 745d ago
flashcards Flashcards (244)
BIS 2B Midterm 1
Updated 722d ago
flashcards Flashcards (157)
Baron - Cohen
Updated 1017d ago
flashcards Flashcards (60)
1920s
Updated 1080d ago
flashcards Flashcards (101)
Linear Algebra Vocab
Updated 985d ago
flashcards Flashcards (40)
Clustering Analysis
Updated 1168d ago
flashcards Flashcards (38)
Topic 3 Computers
Updated 975d ago
flashcards Flashcards (35)