Terraform
-
Terraform is most popular infra provisioning tool
- Terraform works with many on-prem hypervisors and cloud providers (virtual)
- Terraform is from Hashicorp and is developed in Golang.
- Terraform installation is all about downloading one simple executable.
Terraform components
- Providers: This refers to where we are trying to create infra
- Resource: This is infra element which we are trying to provision
- Arguments: refers to the inputs
- Attributes: refers to the outputs
How Terraform manages infra (First Version)
- User creates terraform templates where the desired state is expressed. Terraform templates are files with
.tfextension in a folder. - Terraform when installed is a single executable and it doesn’t know how to create infra. Depending on the providers defined used terraform will download the necessary providers into
.terraformfolder, Terraform executable can communicate with this provider. - When providers communicate to the cloud they need to be authenticated.
- Terraform keeps track of what it has provisioned in a state file
.tfstate
Creating infra once template is ready
- Terraform providers need to be downloaded for that cd into the folder
terraform init - To Create infra
terraform apply - To delete
terraform destroy
Expressing Desired State with Terraform
- Terraform using HCL (Haschicorp configuration language)
- step 1: Manually know how to create resources
Findout how to create aws s3 bucket
- Prompt:
You are an aws expert, I want to know the steps involved in creating a simple s3 bucket from aws console. Give me step by step instructions
- provider: aws
- region: us-west-2
- resource: s3 bucket
- input:
- bucket-name
In Terraform
- Create a new folder
awshellotf -
open this folder in vs code and ensure visual studio code has terraform extension.
-
create a file called as
main.tf - we need to configure provider now google for
terraform aws provider

- copy the highlighted section into main.tf
- Now we need to create resource. now search for
terraform aws s3 bucket
