Basic Terraform Commands

Basic Terraform Commands

Day 61 of #90DaysOfDevOps

Task:

Find the purpose of basic Terraform commands that you'll use often.

terraform init

  • terraform init command initializes the terraform working directory.

  • It needs to be performed whenever there is a new resource or provider added to the terraform file.

terraform init -upgrade

  • terraform init -upgrade command upgrades all providers to the latest version that's consistent with the version constraints in the configuration.

terraform plan

  • The terraform plan command compares the current state of resources with the desired state of a configuration file.

  • It then generates a plan of action to achieve the desired state. The plan shows which resources will be created, modified, or destroyed, and how their attributes will change.

terraform apply

  • The terraform apply command executes the actions proposed in a Terraform plan. It is used to deploy infrastructure and is typically run after Terraform init and Terraform plan.

terraform validate

  • The terraform validate command verifies the correctness of Terraform configuration files. It checks the syntax of the files, ensures the correct usage of attributes and values, and validates the configuration based on the core syntax of Terraform.

terraform fmt

  • The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style. This command applies a subset of the Terraform language style conventions, along with other minor adjustments for readability.

terraform destroy

  • The terraform destroy command is a convenient way to destroy all remote objects managed by a particular Terraform configuration.