Introduction to Terraform

Helpful Commands

Terraform Logo One of the best things about Terraform is that you can use it everywhere - AWS, Azure, GCP, and many more cloud providers. This helps prevent having to learn the nuances that the underlying API will have. You can just learn HCL (HashiCorp Configuration Language). Start with installing Terraform using your OS of choice.

Getting Started

  1. From your working directory initialize Terraform - this will download the plugin for the cloud provider you intend on using:
    terraform init
    
  2. Lint your code with a validate:

    terraform validate
    
  3. Review HCL with a plan:

    terraform plan
    

    Write the plan to an out file for the apply to consume:

    terraform plan -out out.terraform
    
  4. Apply the Terraform code:

    terraform apply
    

    Apply the code using a plan:

    terraform apply out.terraform
    
  5. Show current state:

    terraform show
    

    You can also read the Terraform state file:

    cat terraform.tfstate