> For the complete documentation index, see [llms.txt](https://asafahmadov.gitbook.io/cloud-and-devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://asafahmadov.gitbook.io/cloud-and-devops/devops-bootcamp/infrastructure-as-code-with-terraform/terraform-commands.md).

# Terraform commands

#### auto approve

```
terraform apply -auto-approve
```

#### initialize

```
terraform init
```

#### preview terraform actions <a href="#user-content-preview-terraform-actions" id="user-content-preview-terraform-actions"></a>

The `terraform plan` command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure. By default, when Terraform creates a plan it:

* Reads the current state of any already-existing remote objects to make sure that the Terraform state is up-to-date.
* Compares the current configuration to the prior state and noting any differences.
* Proposes a set of change actions that should, if applied, make the remote objects match the configuration.

```
terraform plan
```

#### apply configuration with variables <a href="#user-content-apply-configuration-with-variables" id="user-content-apply-configuration-with-variables"></a>

```
terraform apply -var-file terraform-dev.tfvars
```

#### destroy a single resource <a href="#user-content-destroy-a-single-resource" id="user-content-destroy-a-single-resource"></a>

```
terraform destroy -target aws_vpc.myapp-vpc
```

#### destroy everything fromtf files <a href="#user-content-destroy-everything-fromtf-files" id="user-content-destroy-everything-fromtf-files"></a>

```
terraform destroy
```

#### show resources and components from current state <a href="#user-content-show-resources-and-components-from-current-state" id="user-content-show-resources-and-components-from-current-state"></a>

```
terraform state list
```

#### show current state of a specific resource/data <a href="#user-content-show-current-state-of-a-specific-resourcedata" id="user-content-show-current-state-of-a-specific-resourcedata"></a>

```
terraform state show aws_vpc.myapp-vpc    
```

#### set avail\_zone as custom tf environment variable - before apply <a href="#user-content-set-avail_zone-as-custom-tf-environment-variable-before-apply" id="user-content-set-avail_zone-as-custom-tf-environment-variable-before-apply"></a>

```
export TF_VAR_avail_zone="eu-west-3a"
```
