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.
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.
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.
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
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.
Installs multiple versions of Terraform to ~/.tfenv
in order to maintain compatability with different Terraform code
bases.
Otherwise using a newer globally installed version of Terraform will upgrade the terraform.tfstate
file and break
other clients who will be forced to upgrade to the same version in order to run again.
On Mac, install tfenv:
brew instal tfenv
List available versions:
tfenv list-remote
Install specific version to match the existing terraform.tfstate
file.
tfenv install <version>
or if you don't care about a specific version and just quickly want the latest:
tfenv install latest
Ensure ~/.tfenv/bin/
is early in your shell $PATH
(automatically sourced in [DevOps-Bash-tools]
(devops-bash-tools.md)
shell).
Then just use terraform
like usual.
Once you have more than one version of Terraform installed, switch to another version: another version:
tfenv use <version>
Important for modularity and performance of Terraform code bases.
See Terragrunt for more details.