DEV Community

Cover image for Top 10 Terraform Commands
Hasan Elsherbiny
Hasan Elsherbiny

Posted on

Top 10 Terraform Commands

Terraform provides a set of commands to manage your infrastructure and perform various tasks.
in this article we are listing the top 10 commonly used Terraform commands.

terraform init
Enter fullscreen mode Exit fullscreen mode

Initializes a new or existing Terraform configuration. It downloads provider plugins and initializes the working directory.

terraform plan
Enter fullscreen mode Exit fullscreen mode

Generates an execution plan that shows what Terraform will do when you apply your configuration. This is a dry run and helps you understand the changes Terraform will make.

terraform apply
Enter fullscreen mode Exit fullscreen mode

Applies the changes described in your Terraform configuration to your infrastructure. It creates, updates, or deletes resources as needed.

terraform destroy
Enter fullscreen mode Exit fullscreen mode

Destroys all resources created by Terraform in your configuration. Use with caution, as it can lead to data loss and service disruption.

terraform validate
Enter fullscreen mode Exit fullscreen mode

Checks the validity of your Terraform configuration files. It ensures that the syntax is correct and references to resources are valid.

terraform fmt
Enter fullscreen mode Exit fullscreen mode

Rewrites Terraform configuration files to a canonical format. This command helps maintain consistent code formatting.

terraform show
Enter fullscreen mode Exit fullscreen mode

Displays the current state or plan in a human-readable format. It can be useful for reviewing the details of your infrastructure.

terraform refresh

Enter fullscreen mode Exit fullscreen mode

Updates the state file with the real-world resources that exist in your infrastructure. This is useful if changes were made outside of Terraform's control.

terraform state

Enter fullscreen mode Exit fullscreen mode

Provides advanced state management functionality. You can use this command to inspect, modify, or remove items from the state file.

terraform import
Enter fullscreen mode Exit fullscreen mode

Imports existing infrastructure into Terraform. It allows you to manage existing resources using Terraform.

Top comments (4)

Collapse
 
hectorlaris profile image
Héctor Serrano

Excellent!

Collapse
 
hasanelsherbiny profile image
Hasan Elsherbiny

thanks, glad you like it

Collapse
 
robertraff1 profile image
RobertRaff1

great article as always

Collapse
 
giovannimatteo1 profile image
Giovanni Matteo

good explanation