[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  #### How Terraform works?  #### Terraform Workflow :::warning - terraform init - terraform plan - terraform apply - terraform destroy :::  ### 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.7.4 on linux_amd64 ```` or ````yaml= sudo snap install terraform --classic ```` :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:   #### 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  ### References :::info - https://chocolatey.org/install - https://developer.hashicorp.com/terraform/downloads :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up