我正在通过构建一个模板来在 Hetzner 云中创建我的基础设施来学习 terraform。为此,我使用 hcloud 提供商。
我创建一个映射变量主机来创建> 1个具有不同配置的服务器。
variable "hosts" {
type = map(object({
name = string
serverType = string
serverImage = string
serverLocation = string
serverKeepDisk = bool
serverBackup = bool
ip = string
}))
}
Run Code Online (Sandbox Code Playgroud)
这工作正常。但我还需要配置卷。我只需要 2 个服务器额外的卷,并且 terraform 必须检查变量卷是否为真。如果为 true,则应创建具有给定详细信息的新卷并将其附加到服务器。为此,我编辑我的变量主机:
variable "hosts" {
type = map(object({
name = string
serverType = string
serverImage = string
serverLocation = string
serverKeepDisk = bool
serverBackup = bool
ip = string
volume = bool
volumeName = string …Run Code Online (Sandbox Code Playgroud)