# Commands

| Command                                          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `terraform init`                                 | When you create a new configuration — or check out an existing configuration from version control — you need to initialize the directory with this command. Initializing a configuration directory downloads and installs the providers defined in the configuration, which in this case is the aws provider. Terraform downloads the aws provider and installs it in a hidden subdirectory of your current working directory, named .terraform. The terraform init command prints out which version of the provider was installed. Terraform also creates a lock file named .terraform.lock.hcl which specifies the exact provider versions used, so that you can control when you want to update the providers used for your project. |
| `terraform fmt`                                  | This command automatically updates configurations in the current directory for readability and consistency.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `terraform validate`                             | To make sure your configuration is syntactically valid and internally consistent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `terraform apply`                                | Apply the configuration with this command as per [this](../00_introduction#core-terraform-workflow). Before it applies any changes, Terraform prints out the execution plan which describes the actions Terraform will take in order to change your infrastructure to match the configuration. Terraform will now pause and wait for your approval before proceeding. If anything in the plan seems incorrect or dangerous, it is safe to abort here with no changes made to your infrastructure.                                                                                                                                                                                                                                       |
| `terraform show`                                 | When you applied your configuration, Terraform wrote data into a file called `terraform.tfstate`. Terraform stores the IDs and properties of the resources it manages in this file, so that it can update or destroy those resources going forward. The Terraform state file is the only way Terraform can track which resources it manages, and often contains sensitive information, so you must store your state file securely and restrict access to only trusted team members who need to manage your infrastructure. In production, we recommend storing your state remotely with Terraform Cloud or Terraform Enterprise. Terraform also supports several other remote backends you can use to store and manage your state.      |
| `terraform plan`                                 | Prints out the plan terraform will execute to update or create the final state of the world _(infrastructure)_.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `terraform destroy`                              | Terminates resources managed by your Terraform project, specified in the current terraform state file. Multiple resources in the state file will be destroyed in a suitable order to respect dependencies.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `terraform output [output_variable_name]`        | Query/Inspect the outputs with the terraform output command, once you have applied the configurations.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `terraform login`                                | Used to login to a terrafom cloud account.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `terraform get`                                  | To install the module from public registry to the `.terraform/modules` directory within your configuration's working directory. For local modules, Terraform will create a symlink to the module's directory. Because of this, any changes to local modules will be effective immediately, without having to re-run terraform get.                                                                                                                                                                                                                                                                                                                                                                                                      |
| `terraform state <sub command> [options] [args]` | Shows the state of terraform. It has sub commands such as `list`, `show`, `pull`, etc to manage the state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `terraform refresh`                              | To refresh terraform state without deploying changes (i.e terraform apply)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

> Note: `terraform apply` and `terraform destroy` has -target option which allows to target resources specifically.
