0%

DevOps-Terraform

Terraform[1]#

Command[2]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ terraform init
$ terraform fmt
$ terraform validate
$ terraform plan -out
$ terraform plan -detailed-exitcode
echo $?
0
drift
0 no drift
1 error
2 success ## infra drift,可能有人变更了infra并apply成功
$ terraform apply/destroy -target
## 下面两条命令是相反的操作
$ terraform state rm ## 从状态文件中删除一个或多个对象
$ terraform import ## 已经存在的手动创建的资源对象导入Terraform,由terraform来控制
Module [3] [4]#
  • 模块复用
    module 可以嵌套 module

参考#

  1. Terraform 简介
  2. alicloud_ecs example
  3. terraform-module
  4. aliyun提供的modules