Examples for terraform usage.
-
在 https://www.terraform.io/downloads 下载对应的可执行文件
-
把
terraform
可执行程序添加到PATH
-
配置 Provide Cache - Windows
-
新增 Provide Cache 目录,例如:
D:\terraform\cache
-
在系统
%APPDATA%
目录下新增/编辑terraform.rc
文件,内容如下:
-
plugin_cache_dir = "D:\\terraform\\cache"
provider_installation {
filesystem_mirror {
path = "D:\\terraform\\cache"
}
}
-
配置 Provide Cache - Linux
-
新增 Provide Cache 目录,例如:
$HOME/plugin-cache
-
在
$HOME
下新增/编辑.terraformrc
文件,内容如下:
-
plugin_cache_dir = "$HOME/plugin-cache"
provider_installation {
filesystem_mirror {
path = "$HOME/plugin-cache"
}
}
- 初始化
terraform init
- 查看执行计划
terraform plan -var-file="values.tfvars"
- 安装
terraform apply -var-file="values.tfvars" -auto-approve
- 修改
# 查看修改内容
terraform plan -var-file="values.tfvars"
# 执行修改
terraform apply -var-file="values.tfvars" -auto-approve
- 卸载
terraform destroy -var-file="values.tfvars" -auto-approve
- 添加/修改指定模块
terraform apply -target="module.xxx" -var-file="values.tfvars"
- 卸载指定模块
terraform apply -destroy -target="module.xxx" -var-file="values.tfvars"