Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"volume_ids" with counted volumes #28

Closed
mluscon opened this issue Jul 31, 2017 · 2 comments
Closed

"volume_ids" with counted volumes #28

mluscon opened this issue Jul 31, 2017 · 2 comments
Labels

Comments

@mluscon
Copy link

mluscon commented Jul 31, 2017

Hi,

I stumbled upon an issue with specifying volume ids for volumes created with count. I tried various ways e.g.:

volume_ids = ["${"${format("digitalocean_volume.docker_master.%d.id", count.index)}"}"]

Which doesn't work because of a nested interpolation or:

volume_ids = ["${digitalocean_volume.docker_master.*.id}"]

Which neither works since digitalocean doesn't support attaching one volume to more than one droplet.
Is there any way how I can achieve this?

@tombuildsstuff
Copy link
Contributor

Hey @mluscon

Given you're creating multiple volumes with count - you should be able to access the values using the element interpolation function

This can be used in code as shown:

volume_ids = [ "${element(digitalocean_volume.docker_master.*.id, count.index)}" ]

For example, the following example should work: :)

resource "digitalocean_volume" "docker_master" {
  region      = "nyc1"
  name        = "vol${count.index}"
  size        = 100
  count       = 3
  description = "an example volume"
}

resource "digitalocean_droplet" "docker_master" {
  name       = "docker${count.index}"
  size       = "1gb"
  count      = 3
  image      = "coreos-stable"
  region     = "nyc1"
  volume_ids = [ "${element(digitalocean_volume.docker_master.*.id, count.index)}" ]
}

Would it be possible for you to take a look and see if that solves your issue?

Thanks!

@mluscon
Copy link
Author

mluscon commented Jul 31, 2017

It works like a charm. Thank you!

@mluscon mluscon closed this as completed Jul 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants