> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Section Introduction Preparing Your Environment

> Guide to install and verify Terraform, configure VS Code, set cloud provider credentials for AWS Azure GitHub, and run basic Terraform workflow commands

Welcome to this lesson on preparing your local machine to run Terraform. This guide walks you through the minimal, practical steps required to get a working Terraform environment for exercises and labs, with verification commands so you can confirm each step completed successfully.

What you'll get from this lesson

* Clear installation options for Terraform across macOS, Linux, and Windows
* Recommended code editor setup (Visual Studio Code) and useful extensions
* How to configure cloud provider credentials (AWS, Azure, GitHub) so Terraform can authenticate securely
* A short checklist of basic Terraform workflow commands to validate your environment

## Installing Terraform

You can install Terraform either via your platform's package manager or by downloading the official binary from HashiCorp: [https://developer.hashicorp.com/terraform/downloads](https://developer.hashicorp.com/terraform/downloads).

Use the method that suits your environment (package managers keep Terraform up to date; manual downloads give you more control).

Package-manager examples

| Platform               | Recommended approach                          | Example command / notes                                    |
| ---------------------- | --------------------------------------------- | ---------------------------------------------------------- |
| macOS                  | Homebrew                                      | `brew install terraform`                                   |
| Ubuntu / Debian        | HashiCorp apt repository or manual binary     | Follow HashiCorp's repo instructions to enable apt updates |
| RHEL / CentOS / Fedora | HashiCorp yum/dnf repository or manual binary | Configure HashiCorp yum/dnf repo for updates               |
| Windows                | Chocolatey or official MSI/zip                | `choco install terraform` or download MSI from HashiCorp   |

After installation, verify Terraform is available:

```bash theme={null}
# Verify Terraform installation
terraform -version
```

You should see Terraform's version and the installed provider plugin versions. If you see "command not found", confirm the binary is on your `PATH`.

## Editor: Visual Studio Code (recommended)

I recommend Visual Studio Code as a lightweight, extensible editor for Terraform HCL files.

Suggested extensions and formatting

* HashiCorp Terraform extension for syntax highlighting, snippets, and formatting: [https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform)
* EditorConfig and/or Prettier for consistent formatting (if your team uses them)
* Configure VS Code to run `terraform fmt` on save, or run formatting manually:

```bash theme={null}
terraform fmt
```

## Setting up cloud provider credentials

Terraform uses provider plugins to interact with cloud APIs. Before executing Terraform code that targets a cloud provider, configure credentials on the machine where you run Terraform.

Credential patterns and examples

| Provider | Typical local auth method                                                 | Environment variables / files                                                                                  |
| -------: | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
|      AWS | Configure AWS CLI or set env vars                                         | `~/.aws/credentials` via `aws configure`, or `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN` |
|    Azure | Use `az login` for interactive sessions; service principal for automation | Service principal vars: `ARM_CLIENT_ID`, `ARM_CLIENT_SECRET`, `ARM_SUBSCRIPTION_ID`, `ARM_TENANT_ID`           |
|   GitHub | Create a Personal Access Token (PAT)                                      | Set `GITHUB_TOKEN` or `GH_TOKEN` in the environment, or use provider block config                              |

Examples and notes

* AWS: Run `aws configure` to create `~/.aws/credentials`. The Terraform AWS provider reads the default profile automatically; you can also specify a `profile` in the provider block.
* Azure: Run `az login` for interactive work. For CI/CD, create a service principal and export `ARM_CLIENT_ID`, `ARM_CLIENT_SECRET`, `ARM_SUBSCRIPTION_ID`, and `ARM_TENANT_ID`.
* GitHub: Create a PAT with the minimum scopes required (for example, `repo` and `workflow`) and export it as `GITHUB_TOKEN` for use by the GitHub Terraform provider.

<Callout icon="lightbulb" color="#1CB2FE">
  When possible, prefer using CLI tools (for example `aws`, `az`) to authenticate locally and use environment variables or credential files for automation. This avoids hard-coding secrets in your Terraform configuration.
</Callout>

## Basic Terraform workflow checks

Once Terraform is installed and credentials are configured, validate your environment by running these commands inside an empty working directory (or a directory with your Terraform configurations).

1. Initialize the working directory (downloads providers and configures the backend):

```bash theme={null}
terraform init
```

2. Format and validate your configuration files:

```bash theme={null}
terraform fmt
terraform validate
```

3. Preview changes:

```bash theme={null}
terraform plan
```

4. Apply changes (prompts for confirmation by default):

```bash theme={null}
terraform apply
```

Quick verification checklist

| Command              | Purpose                                   | Expected result                                      |
| -------------------- | ----------------------------------------- | ---------------------------------------------------- |
| `terraform -version` | Confirms Terraform binary is installed    | Displays Terraform and provider plugin versions      |
| `terraform init`     | Fetches providers and initializes backend | Completed initialization without errors              |
| `terraform fmt`      | Formats HCL files                         | Files are formatted (or no changes)                  |
| `terraform validate` | Static validation of configs              | No errors reported                                   |
| `terraform plan`     | Shows proposed changes                    | Plan output lists resources to create/update/destroy |

<Callout icon="warning" color="#FF6B6B">
  Never commit provider credentials, personal access tokens, or other secrets to version control. Use environment variables, CLI-authenticated sessions, or a secrets manager for automation.
</Callout>

## Wrapping up

This lesson covered the essentials to prepare your machine for Terraform exercises:

1. Install Terraform (package manager or HashiCorp binary)
2. Configure a code editor (Visual Studio Code + extensions)
3. Set up cloud provider credentials (AWS, Azure, GitHub)
4. Verify the basic Terraform workflow (`init`, `fmt`, `validate`, `plan`, `apply`)

You're now ready to start the lab exercises. Begin by installing Terraform on your platform, then configure your editor and authenticate to your target cloud provider.

## Links and references

* Terraform downloads: [https://developer.hashicorp.com/terraform/downloads](https://developer.hashicorp.com/terraform/downloads)
* Visual Studio Code: [https://code.visualstudio.com/](https://code.visualstudio.com/)
* HashiCorp Terraform VS Code extension: [https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform)
* AWS CLI configuration quickstart: [https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html)
* Azure CLI authentication: [https://learn.microsoft.com/cli/azure/authenticate-azure-cli](https://learn.microsoft.com/cli/azure/authenticate-azure-cli)
* GitHub PATs: [https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/hashicorp-certified-terraform-associate-004/module/df5b5815-c1ea-45f5-ba18-7a5c53ded28a/lesson/c15b7a1b-a0b7-40ab-982a-d1a3c660b57f" />
</CardGroup>
