andrelohmann.terrahelper
terrahelper
terrahelper 包含了适合小团队的 Terraform 和 Terrahelp 的最佳实践。
最佳实践:
- 为你的 Terraform 模板文件创建一个仓库
- 为对应的 Terraform 状态创建一个仓库
- 将状态与 Terraform 模板文件夹分开(这就是需要第二个仓库的原因)
工作流程:
- 创建/编辑你的模板
- 从状态仓库获取最新状态
- 使用 Terrahelp 和你的状态密钥解密状态
- 运行 Terraform 的 plan/apply 命令
- 使用 Terrahelp 加密新的状态
- 将新状态提交到状态仓库
需求
此角色需要 Ubuntu。
示例剧本
- hosts: terrahelper
roles:
- { role: andrelohmann.terraform }
- { role: andrelohmann.terrahelp }
- { role: andrelohmann.terrahelper }
用法
terrahelper 集成了对 Terraform 模板的状态进行解密和加密的步骤,并结合 Terraform 命令来初始化、计划、应用和销毁你的栈。
因此你需要一个状态密钥来进行 Terraform 状态的解/加密,并且需要两个单独的仓库(一个用于模板,一个用于状态)。
以和从 Terraform 模板目录运行 Terraform 命令的方式运行 terrahelper。
用法:terrahelper init | plan | apply | destroy | output [-s | --statesecret SECRET] [-d | --statedirectory STATEDIRECTORY] [-f | --statefile terraform.tfstate] [-b | --statefilebackup terraform.tfstate.backup] [-e | --echo] [-h | --help] [其他 Terraform 参数]
如果设置了以下环境变量,相应的参数将不再需要:
TH_SECRET - 用于解/加密状态的 Terrahelp 密钥
TH_STATE_DIRECTORY - Terraform 状态目录的绝对路径或相对路径(从 Terraform 模板目录)
TH_STATE_FILE - Terraform 状态文件(默认为 terraform.tfstate)
TH_STATE_FILE_BACKUP - Terraform 状态文件备份(默认为 terraform.tfstate.backup)
你也可以在最后添加任何特定于 Terraform 命令的参数。这些参数将被附加到 Terraform 命令上。
许可证
MIT
作者信息
ansible galaxy role to wrap a terraform best practice, that uses a separate state repository, that is encrypted by terrahelp.
ansible-galaxy install andrelohmann.terrahelper