Terraform Training

Use Infrastructure as Code to provision and manage any cloud, infrastructure, or service


Best video for learn terraform: Terraform Course - Automate your AWS cloud infrastructure https://www.youtube.com/watch?v=SLB_c_ayRMo


https://www.terraform.io/ offical docs
https://www.alibabacloud.com/help/zh/doc-detail/91285.htm?spm=a2c63.p38356.b99.372.8b994d00YwQjZI 中文版,阿里云文档
https://learn.hashicorp.com/terraform/getting-started/intro Get Started - AWS

Why not use ansible ? because changes to resources aren’t tracked.
Why didn’t we choose CloudFormation? Its support is limited to AWS.

Terraform config is code we write, state file is a json file. store these on the remote.
Plan is safe to do any where, apply we don’t comment any want. don’t apply locally, don’t apply locally, don’t apply locally!

Commands Description
terraform init Initiate Terraform. Terraform must be initiated before you plan/apply terraform.
terraform plan You will be able to examine Terraform’s execution plan before you deploy it to AWS.
terraform apply Deploy your final execution plan to AWS.
terraform init -upgrade Update providers.
terraform state show Inspect the current state.
terraform graph Displays the visual dependency graph of Terraform resources according to configuration files in DIR (or the current directory if omitted).
terraform destroy Destroy all resources created by terraform and also destroy the changes in your state file.
terraform plan-out To save the displayed plan (from the ‘terraform plan’ command) for reference.

precedence 优先级


Local Values



This is a good multi-version control tools for terraform. https://github.com/aaratn/terraenv

verbose debug

特别是在遇到权限不足的时候,如果想检查是具体哪个 service 权限不足。就需要 debug 输出详细的过程

input variables 几种方式