Home » linux-commands » Terraform commands cheat-sheet-Important commands

Terraform commands cheat-sheet-Important commands

Terraform is a powerful Infrastructure as Code (IaC) tool that utilizes a set of commands to manage and provision infrastructure. Here are some of the most commonly used Terraform commands:
Core Workflow Commands:
terraform init:
Initializes a working directory containing Terraform configuration files. This command downloads necessary provider plugins and modules.
terraform validate:
Checks whether the configuration is syntactically valid and internally consistent.
terraform plan:
Generates an execution plan, showing what actions Terraform will take to achieve the desired state defined in your configuration. This is a read-only operation and does not make any changes to your infrastructure.
terraform apply:
Executes the actions proposed in a terraform plan to create or update infrastructure resources. It typically prompts for confirmation before proceeding.
terraform destroy:
Destroys all resources managed by the current Terraform configuration. This command also prompts for confirmation.
Other Useful Commands:
terraform fmt: Rewrites Terraform configuration files to a canonical format and style.
terraform get: Downloads and installs modules specified in the configuration.
terraform output: Displays the values of output variables defined in your root module.
terraform state: A set of subcommands for advanced state management, including:
o terraform state list: Lists all resources managed by Terraform in the current state file.
o terraform state show : Shows details stored in the Terraform state for a specific resource.
o terraform state mv: Moves a resource instance from one address to another within the state.
o terraform state rm: Removes a resource from the Terraform state, effectively unmanaging it.
terraform import : Imports existing infrastructure resources into your Terraform state, allowing Terraform to manage them.
terraform workspace: A set of sub commands for managing workspaces, which allow you to manage multiple distinct state files for different environments (e.g., dev, staging, prod) within the same configuration.
o terraform workspace new : Creates a new workspace.
o terraform workspace select : Selects an existing workspace.
terraform console: Provides an interactive console for evaluating Terraform expressions.
terraform login / terraform logout: Authenticates with and removes credentials for remote hosts like Terraform Cloud.

About

I am founder and webmaster of www.linuxpcfix.com and working as a Sr. Linux Administrator (Expertise on Linux/Unix & Cloud Server) and have been in the industry since more than 14 years.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Time limit is exhausted. Please reload the CAPTCHA.

Categorized Tag Cloud