[toc] ### Introduction to Infrastructure-as-Code #### IaC tools/Software :::warning - Terraform (HCL) - AWS CloudFormation (JSON/YAML) - AWS CDK - Azure ARM Templates - HEAT templates (OpenStack) - Pulumi ::: ### Introduction to Terraform ![](https://i.imgur.com/estWHbg.png) #### How Terraform works? ![](https://i.imgur.com/GmqDxmM.png) #### Terraform Workflow :::warning - terraform init - terraform plan - terraform apply - terraform destroy ::: ![](https://i.imgur.com/0ZF47DF.png) ### Installation and configuration #### Installation steps (tested on Ubuntu 20.04): ````yaml= wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install terraform Validation command: terraform -v Expected output: Terraform v1.5.4 on linux_amd64 ```` :mag: Above mentioned installation steps are for Ubuntu OS. For other Operating systems checkout the **[Terraform downloads](https://www.terraform.io/downloads)** page. Refer screenshots below: ![](https://hackmd.io/_uploads/BJ7_RZKL2.png) ![](https://hackmd.io/_uploads/SkkK0WtU3.png) #### Classroom activity (Update the Terraform version on Simplilearn lab machine) ````yaml= Put installation commands in a small script: ## vi terra.sh wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install terraform Make the script executable: chmod +x terra.sh Run the script: sh terra.sh Validation: terraform -v ```` ### Terraform Concepts #### Terraform Commands ````yaml= Initialize Terraform: terraform init Check if the config is right (dry run): terraform plan Create resources: terraform apply Create resources (auto approve): terraform apply -auto-approve Destroy resources: terraform destroy # same as "terraform apply -destroy" Additional Commands: terraform show terraform state terraform fmt terraform validate ```` #### Hashicorp Configuration Language ![](https://i.imgur.com/elGKx5g.png) ### References :::info - https://chocolatey.org/install - https://developer.hashicorp.com/terraform/downloads :::