Terraform


Basic Commands

  1. Initialize with, terraform init
  2. Plan (check typo) terraform plan
  3. Apply (build/change) terraform apply
  4. Destroy build terraform destroy
  5. Output attributes (for example, invoke uri, api key) terraform output -json

With AWS VAULT

  1. aws-vault exec leo.leung -- terraform init
  2. aws-vault exec leo.leung -- terraform plan
  3. aws-vault exec leo.leung -- terraform apply
  4. aws-vault exec leo.leung -- terraform destroy
  5. Sometimes, you might create role and policy, it may give invalid credentials due to aws-vault. Then aws-vault exec leo.leung --no-session -- terraform apply
  6. To avoid manually typing yes, you can aws-vault exec leo.leung -- terraform apply -auto-approve

Basic Information in Terraform file

        
provider "aws" {
    region = "eu-west-2"
}
variable "abc" {
    default = "value"
}
resource "aws_instance" "abc" {

}
local "aaa" {
    variable = ""
}
output "sth_you_want_to_output" {
    
}
        
    

References