> ## 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 Terraform Foundations

> Introductory guide to Terraform fundamentals, why teams use it, core concepts, common commands, workflows, state management, modules, and hands-on exam preparation

Welcome to the Terraform Foundations section.

Now that you've reviewed the [HashiCorp Certified: Terraform Associate 004](https://learn.kodekloud.com/user/courses/hashicorp-certified-terraform-associate-004) exam objectives and installed Terraform and Visual Studio Code on your local machine, it's time to begin the hands-on material.

This lesson covers the core fundamentals of Terraform: what it is, why organizations adopt it, and how it improves infrastructure workflows compared with manually clicking through provider consoles or running ad-hoc CLI commands. You will learn the foundational concepts that explain how Terraform works and why it’s widely used for reproducible, automated infrastructure.

<Callout icon="lightbulb" color="#1CB2FE">
  This section focuses on the essential Terraform concepts you need early in your study path. If you're preparing for the HashiCorp Certified: Terraform Associate exam, these topics map closely to the exam's foundational objectives.
</Callout>

## What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool by HashiCorp that lets you define cloud and on-prem resources declaratively using configuration files (typically with the `.tf` extension). Terraform transforms those declarative files into an execution plan and then applies that plan to create, update, or destroy resources across multiple providers (AWS, Azure, GCP, and many others).

Key verbs you’ll use frequently:

* `terraform init` — initialize a working directory
* `terraform plan` — preview changes before applying
* `terraform apply` — execute the planned changes
* `terraform destroy` — remove managed infrastructure

## Why organizations use Terraform

Terraform introduces consistent, reproducible, and auditable infrastructure automation. Instead of manual clicks or scattered CLI scripts, Terraform gives you:

* Declarative configuration: describe desired state, not imperative steps.
* Multi-cloud and provider support: one tool for many platforms.
* Versionable configurations: treat infrastructure like code in git.
* Predictable change plans: preview changes with `terraform plan`.
* Reusable modules: encapsulate and share architecture patterns.

## Core Terraform concepts

| Concept       | Purpose                         | Example/Notes                                                 |
| ------------- | ------------------------------- | ------------------------------------------------------------- |
| Configuration | Declare resources and settings  | Files with `.tf` using HCL (HashiCorp Configuration Language) |
| Provider      | Plugin for a target platform    | `provider "aws" { region = "us-east-1" }`                     |
| Resource      | A managed infrastructure object | `resource "aws_instance" "web" { ... }`                       |
| State         | Maps config to real resources   | Stored locally or remotely (S3, Terraform Cloud)              |
| Plan/Apply    | Preview and enact changes       | `terraform plan` → `terraform apply`                          |
| Module        | Reusable configuration unit     | Local or registry-based modules for reuse                     |

<Callout icon="warning" color="#FF6B6B">
  Terraform state contains the authoritative mapping of resources. Protect and manage state carefully (use remote backends and locking for teams) to avoid resource drift and corruption.
</Callout>

## How Terraform improves workflows

* Automation and CI/CD: Integrate Terraform into pipelines to provision and update infrastructure automatically.
* Collaboration: Use remote state backends and workspaces to coordinate changes among teams.
* Drift detection: `terraform plan` surfaces differences between configuration and real infrastructure.
* Idempotence: Reapplying the same configuration converges the environment to the declared state.

## Common usage pattern

1. Write configuration (`*.tf` files).
2. Initialize the working directory:
   * `terraform init`
3. Validate and preview changes:
   * `terraform validate`
   * `terraform plan`
4. Apply changes:
   * `terraform apply`
5. Maintain and update through version control and CI.

## Next steps and references

* Official Terraform documentation: [https://www.terraform.io/docs](https://www.terraform.io/docs)
* HashiCorp Learn: [https://learn.hashicorp.com/terraform](https://learn.hashicorp.com/terraform)
* Course link (exam prep): [HashiCorp Certified: Terraform Associate 004](https://learn.kodekloud.com/user/courses/hashicorp-certified-terraform-associate-004)

Suggested next hands-on exercises:

* Create a simple provider configuration and one resource.
* Initialize with `terraform init`, plan with `terraform plan`, and apply with `terraform apply`.
* Configure a remote backend (e.g., S3 with DynamoDB locking for AWS) to experiment with team workflows.

This section prepares you for deeper topics such as modules, state backends, remote operations, and workspace strategies that follow in the next lessons.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/hashicorp-certified-terraform-associate-004/module/be082b2a-db28-4bed-84e4-233393a3aafa/lesson/25dc89b6-200b-4c5d-971a-2eb6d7c7abcc" />
</CardGroup>
