Hashicorp Terraform

Get up and running with Terraform

What is Terraform?

  • Terraform is an open-source, declarative Infrastructure as Code language from HashiCorp.

  • Providers are used to define the resources to build. These abstract the underlying API calls made to build, modify, and destroy resources by wrapping this into HCL syntax. In other words, you just worry about writing Terraform code without having to understand and work with the underlying APIs.

Installation

# Installing via Homebrew on MacOS
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
brew update
brew upgrade hashicorp/tap/terraformh

# Enabling tab completion
terraform -install-autocomplete

# Restarting shell
. ~/.zshrc    # bash is ~/.bashrc

Commands

  • Initialize the directory where Terraform files are stored: terraform init

  • Verify the Terraform syntax is correct: terraform validate

  • View the resources the code would build if run: terraform plan

  • Build the resources: terraform apply

  • Destroy the resources created with Terraform: terraform destroy

Example

  • Typically, Terraform code is defined in a main.tf file and variables found in that file can be declared in variables.tf

  • Variables are not required and you could hard code everything into main.tf if desired.

  • Here's an example of configuring an AWS S3 bucket in Terraform utilizing the AWS Provider.

Last updated

Was this helpful?