> For the complete documentation index, see [llms.txt](https://notes.nomanaziz.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.nomanaziz.me/devops/infrastructure-as-a-code-iac/terraform/1.-overview.md).

# 1. Overview

### Introduction

* Terraform is tool for building, changing, and versioning infrastructure safely and efficiently
* It enables application software best practices to infrastructure
* Compatible with many clouds and services
* Written in hashicorp configuration language in a file that has **.tf** extension

***

### Architecture

<figure><img src="/files/9lb30F4YDvDiwOCCQL1J" alt=""><figcaption></figcaption></figure>

### Providers

* It is a plugin that allows us to talk to set of APIs
* For instance, to interact with AWS, we have to download the AWS provider
* Similarly, in order to interact with Kubernetes, we have to download the Kubernetes provider

***

### Data

* Used to reference the existing resources in the cloud

***

### Basic Commands

1. `terraform init` - looks for all the providers in all config files in current directory and downloads the necessary plugins
2. `terraform plan` - does a dry run of your code
3. `terraform apply` - to run our code

***

### Sample Activity Code

```hcl
#####################
# Setting up provider
# Hard coded autentication credentials, non recommended way
#####################
provider "aws" {
  region = "us-east-1"
  access_key = "<access_key>"
  secret_key = "<secret_key>"
}

#####################
# Making a resource
# Same syntax for every provider
#
# resource "<provider>_<resource_type>" "name" {
#   config options.....
#   key = "value"
# }
#####################

#####################
# Deploying EC2 Instance
#####################
resource "aws_instance" "my-first-server" {
    ami = "ami-052efd3df9dad4825"
    instance_type = "t2.micro"

```
