terraform init
:Purpose: Initializes a new or existing Terraform working directory.
Use: You run this command in the directory where your Terraform configuration files are located. It initializes the plugins and modules necessary for your configuration.
terraform init -upgrade
:Purpose: Upgrade the provider plugins to the latest versions.
Use: Adding the
-upgrade
flag when runningterraform init
will check for and install the latest available versions of the provider plugins. It's useful for keeping your infrastructure up-to-date.
terraform plan
:Purpose: Creates an execution plan showing what Terraform will do when
apply
is run.Use: Running
terraform plan
helps you preview the changes Terraform will make to your infrastructure. It doesn't make any actual changes but provides a summary of what's going to happen.
terraform apply
:Purpose: Applies the changes defined in your configuration to the infrastructure.
Use: After reviewing the execution plan with
terraform plan
, you can apply the changes to create or modify infrastructure resources as per your configuration.
terraform validate
:Purpose: Validate the configuration files for syntax and other basic errors.
Use: This command helps ensure that your Terraform configuration files are correctly formatted and free from common errors before attempting to apply changes.
terraform fmt
:Purpose: Rewrite configuration files to a canonical format.
Use:
terraform fmt
automatically restructures your configuration files to adhere to a consistent style guide. This command helps maintain clean and readable code.
terraform destroy
:Purpose: Destroys all the resources defined in your configuration.
Use: This command is used when you want to tear down the infrastructure created by Terraform. It's essential for de-provisioning resources when they are no longer needed.
These basic Terraform commands are fundamental to working with Terraform and managing your infrastructure as code. They allow you to initialize, plan, apply, validate, format, and destroy infrastructure resources efficiently.
Also along with these tasks, it's important to know about Terraform in general-
Who are Terraform's main competitors? The main competitors are:
Ansible Packer Cloud Foundry Kubernetes
Want a Free video Course for Terraform? Click here
Thank you so much for reading
Follow me on LinkedIn to see interesting posts like this : )