This cheat sheet is possible thanks to Kodekloud’s course
Terraform uses HCL (HashiCorp Configuration Language) which is a domain-specific language (DSL) and a declarative language used to define and configure infrastructure resources
Check Terraform’s docs about HCL to know more
When including a new provider, be sure to re-run terraform init
terraform.tfstate
is the state file, which contains the complete record of the infrastructure created by Terraform and works as the single source of truth
Check this guide to create a remote state setup for the backend
terraform_remote_state
data source to retrieve the root module output values from some other Terraform configurationThere can be constraints in provider versions, so make sure you’re using a consistent version. To be sure of the version you can do the following example which finds a version between 1.2.0 and 2.0.0 except for 1.4.0
terraform {
required_providers {
local = {
source: "hashicorp/local"
version = "> 1.2.0, < 2.0.0, != 1.4.0"
}
}
}
You can group or isolate mechanism using alias
(namespace) for resources
// provider.tf
provider "aws" {
region = "ca-central-1"
alias = "central"
}
// main.tf
resource "aws_key_pair" "alpha" {
key_name = "alpha"
public_key = "..."
provider = aws.central // <provider_name>.<alias_name>
}
A list (or tuple) is a sequence of values which can be of any type mixed together
A set is a collection of unique values
You can change log level when doing terraform plan or apply using export TF_LOG=TRACE
info
, warning
, error
, debug
, trace
export TF_LOG_PATH=/tmp/terraform.log
Terraform Cloud is a platform that helps with managing your Terraform code and collaboration between developers which simplifies workflow and improves security