digital-ocean - Terraform 和 DigitalOcean : assign volume to specific droplet created with count parameter

标签 digital-ocean terraform

刚刚开始探索地形以在 digital ocean 上旋转水滴和体积。

我的问题是知道执行以下操作的正确方法:

  • 在名为 ubuntu16digitalocean_droplet 资源中使用 count 创建一定数量的 Droplet 实例
  • 仅将 digitalocean_volume 分配给之前创建的 Droplet 的一个或子集。

如何做到这一点?我假设在 digitalocean_volume 资源上使用 droplets_id 属性。像这样的东西:

resource "digitalocean_volume" "foovolume" {
  ...
  droplet_ids = ["${digitalocean_droplet.ubuntu16.0.id}"]
}

使用terraform validate验证它,我得到:

错误:digitalocean_volume.foovolume:“droplet_ids”:无法设置此字段

有什么建议吗?感谢您的任何意见。

问候

最佳答案

DigitalOcean 的 Terraform 提供程序当前的实现方式要求您采取相反的方法。您可以通过定义 Droplet 资源的 volume_ids 来指定哪些卷附加到哪些 Droplet。例如:

resource "digitalocean_volume" "volume" {
    region      = "nyc3"
    count       = 3
    name        = "volume-${count.index + 1}"
    size        = 100
    description = "an example volume"
}

resource "digitalocean_droplet" "web" {
    count      = 3
    image      = "ubuntu-17-10-x64"
    name       = "web-${count.index + 1}"
    region     = "nyc3"
    size       = "1gb"
    volume_ids = ["${element(digitalocean_volume.volume.*.id, count.index)}"]
}

如果你看docs for the volume resource ,您会看到 droplet_ids 是一个“计算”字段。这意味着您无法设置该字段,并且其值由 Terraform 通过提供程序的 API 计算。

关于digital-ocean - Terraform 和 DigitalOcean : assign volume to specific droplet created with count parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47819285/

相关文章:

terraform - 在 local-exec-terraform 中调用 shell 脚本

node.js - 如何停止 Node.js 服务器?

linux - Jenkins 安装向导报错

digital-ocean - 将私钥添加到 FileZilla 时出现“无法从 fzputtygen 获得回复”错误

terraform - Terraform 可以在控制台输出中屏蔽变量吗?

terraform - 无法代入角色并验证指定的 targetGroupArn

go - 使资源架构依赖于另一个变量

ruby-on-rails - Rails 控制台无法在 Digital Ocean 上与 Dokku 一起使用

ruby-on-rails - 如何更改来自 DigitalOcean 的 One Click App for Ruby on Rails 图像中的默认项目

amazon-web-services - terraform refresh 到底有什么作用?