0% found this document useful (0 votes)
8 views2 pages

Terraform Commands

Terraform command

Uploaded by

Satish Jaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Terraform Commands

Terraform command

Uploaded by

Satish Jaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Commands Description When to Use

Initializes the Terraform working directory. First step before running any Terraform
terraform init Downloads required providers and commands in a new project or after
modules. making changes.

Creates an execution plan showing what Before applying changes to preview and
terraform plan
changes Terraform will make. verify the modifications.

terraform Provisions or updates infrastructure To create or modify resources based on


apply according to the execution plan. the configuration.

When you want to tear down all


terraform Destroys all resources managed by
infrastructure to save costs or after
destroy Terraform in the current workspace.
testing

terraform Destroys a specific resource without When you need to selectively remove
destroy -target removing the entire infrastructure. individual resources.

terraform Validates the syntax and consistency of To ensure the configuration is correct
validate Terraform configuration files. before running plan or apply.

Formats Terraform files to standard To maintain readability and consistent


terraform fmt
formatting style. formatting across files.

Displays details of the current state or To inspect the current infrastructure


terraform show
the latest execution plan. state or plan output in detail.

terraform Displays the values of output variables To extract useful information (e.g., IPs,
output from the last apply or plan. endpoints) after applying infrastructure.

Use it to list, show, or manipulate the


Manages and inspects Terraform’s state
terraform state state file directly (e.g., renaming
file.
resources).

terraform Imports existing resources into Terraform When you need to bring external
import state. resources under Terraform management.

When a resource needs to be recreated


terraform Recreates a specific resource by replacing
due to errors, configuration changes, or
apply -replace it during the next apply..
maintenance.
terraform Generates a visual graph of the To visualize how resources are related or
graph dependencies in the configuration. dependent on one another.

Manages multiple environments When working with different


terraform
(workspaces) like dev, staging, and environments using the same
workspace
production. configuration.

Updates the state file with the latest If the state file and real infrastructure are
terraform
information from the actual out of sync (e.g., manual changes were
refresh
infrastructure. made).

Authenticates Terraform with Terraform Use it to log into Terraform Cloud or


terraform login
Cloud or remote backends. other remote backends.

terraform Lists all providers used in the When you need to see what cloud
providers configuration. services or providers are required.

Acquires a state lock to prevent other Use in collaborative environments to


terraform lock
operations from modifying the state file. avoid conflicts.

terraform Releases a state lock if the lock was left When a lock needs to be manually
unlock by an interrupted process. released.

You might also like