Terraform
Basic Commands
- Initialize with,
terraform init
- Plan (check typo)
terraform plan
- Apply (build/change)
terraform apply
- Destroy build
terraform destroy
- Output attributes (for example, invoke uri, api key)
terraform output -json
With AWS VAULT
aws-vault exec leo.leung -- terraform init
aws-vault exec leo.leung -- terraform plan
aws-vault exec leo.leung -- terraform apply
aws-vault exec leo.leung -- terraform destroy
- 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
- 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