Skip to content

Latest commit

 

History

History
111 lines (69 loc) · 2.96 KB

terraform.md

File metadata and controls

111 lines (69 loc) · 2.96 KB

Terraform

Infrastructure-as-Code using HCL manifests to define cloud resources.

Idempotent, queries cloud APIs, detects what is missing or has changed and then applies the necessary changes to reconcile.

Install Terraform

Quick install script is found in the DevOps-Bash-tools repo:

install_terraform.sh

Optionally specify a version argument, otherwise defaults to finding out and installing the latest version.

Terraform Code

See the HariSekhon/Terraform repo for some Terraform code and templates for common files and settings to get you started, such as backend.tf, provider.tf, main.tf etc.

Running Terraform

Download the providers and create or connect to the terraform.tfstate file:

terraform init

Format you code:

terraform fmt

Validate your code:

terraform validate

See the plan of additions/deletions/modifications that Terraform would do:

terraform plan

Apply the changes:

terraform apply

Terraform State

Stored in a terraform.tfstate either locally or more usually in a cloud bucket to be shared among users or from a CI/CD system.

This is just a JSON file so you can read its contents to find out what version of Terraform it is using.

terraform_gcs_backend_version.sh is a convenience script to determine this straight from a GCS bucket.

tfenv

Install tfenv to manage multiple versions of Terraform.

When combined with direnv this will auto-switch to the saved version of Terraform recorded in .envrc to avoid updating the tfstate file and forcing all colleagues to upgrade their terraform versions or breaking CI/CD.

tfswitch is another option by the same author as tgswitch below.

asdf is another option - one tool for all runtime versions.

Terragrunt

Important for modularity and performance of Terraform code bases.

See Terragrunt for more details.

tgswtich

Install tgswitch to manage multiple versions of Terragrunt.

When combined with direnv this will auto-switch to the saved version of Terragrunt recorded in .envrc.

This is more recently updated than tgenv.

asdf is another option - one tool for all runtime versions.

Linting & Security