Terraform Associate 004 - Commands & Env Variables

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/39

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.

40 Terms

1
New cards
terraform init
Initializes the directory (backend setup, downloads providers/modules, creates .terraform/ and lock file).
2
New cards
terraform init -upgrade
Upgrades providers/modules to the newest versions allowed by constraints and updates .terraform.lock.hcl.
3
New cards

terraform init -backend-config=KEY=VALUE

Supplies backend settings at init time (repeatable), avoids hardcoding backend values in HCL.

4
New cards
terraform init -backend-config=FILE
Loads backend settings from a file (commonly backend.hcl).
5
New cards
terraform fmt
Formats Terraform files to standard style and rewrites the files.
6
New cards
terraform fmt -recursive
Formats Terraform files in the current directory and all subdirectories.
7
New cards
terraform validate
Validates the configuration (syntax + internal consistency). No remote calls, no state changes.
8
New cards
terraform init -reconfigure
Reinitializes the backend/provider setup, ignoring any previously saved init settings (useful after changing backend config).
9
New cards
terraform plan -out=FILE
Saves the plan to a file for later review/apply.
10
New cards
terraform apply FILE
Applies a previously saved plan file.
11
New cards
terraform apply -auto-approve
Applies without prompting for confirmation.
12
New cards
terraform workspace list

Lists workspaces.

13
New cards

terraform workspace new <NAME>

Creates and switches to a new workspace.
14
New cards

terraform workspace delete <NAME>

Deletes a workspace (if allowed by backend, and typically only when empty/safe).
15
New cards
terraform plan
Builds an execution plan by comparing config to state and refreshing from provider (drift detection happens here).
16
New cards
terraform plan -refresh-only
Updates state to match real infrastructure without proposing changes to infrastructure.
17
New cards
terraform apply
Applies the planned changes and updates state.
18
New cards
terraform apply -refresh-only
Refreshes state only, no infrastructure changes.
19
New cards
terraform apply -replace="ADDR"
Forces Terraform to destroy and recreate the specific resource instance at that address on the next apply.
20
New cards
terraform show
Displays state or a saved plan file in human-readable form.
21
New cards
terraform show -json
Outputs state/plan in JSON for tooling.
22
New cards
terraform output
Prints outputs from the current state.
23
New cards
terraform output
Prints a single output value.
24
New cards
terraform output -json

print your Terraform outputs as machine-readable JSON instead of the pretty human format

25
New cards
terraform graph
Outputs a DOT graph of the dependency graph (pipe to Graphviz to render).
26
New cards
terraform state list
Lists resources tracked in the current state.
27
New cards
terraform state show
Shows details for one resource instance in state.
28
New cards
terraform state mv
Moves/renames a resource address in state (no infra change by itself).
29
New cards
terraform state rm
Removes a resource from state only (resource still exists in the provider).
30
New cards
terraform state pull
Downloads and prints the current remote state.
31
New cards
terraform state push
Uploads a local state file to the configured backend (dangerous, used for recovery/migration).
32
New cards
TF_LOG
Sets Terraform log verbosity (TRACE/DEBUG/INFO/WARN/ERROR) to enable debugging output.
33
New cards

TF_LOG_PATH

File path where Terraform writes logs (used with TF_LOG so logs go to a file instead of the terminal).

34
New cards

TF_VAR_<NAME>

Sets an input variable from the environment (ex: TFVARregion="us-west-2" maps to var.region).

35
New cards
TF_INPUT
Controls interactive prompts (set to 0/false to disable prompting, like -input=false).
36
New cards

TF_IN_AUTOMATION

Tells Terraform it’s running in CI/automation so output and prompts are automation-friendly.

37
New cards
TF_WORKSPACE
Selects the active workspace via environment variable (instead of terraform workspace select).
38
New cards

TF_DATA_DIR

Changes where Terraform stores its working directory data (the .terraform directory contents).

39
New cards

terraform fmt -check

Validates formatting and exits with status code 3 if files are not properly formatted (useful in CI/CD)

40
New cards

terraform init -migrate-state

Re-initializes Terraform and migrates the existing state from the old backend to the new/changed backend configuration