Search code examples
terraformdigital-oceandroplet

Add all DigitalOcean Droplet Instances to a Project in Terraform


I am trying to loop all instances from a DigitalOcean Droplet, that has an unknown amount of instances to add to a DigitalOcean project.

Something like the below but can't figure out how to

resource "digitalocean_droplet" "web" {
  count = var.droplet_count 
  name = "web-${var.name}-${var.region}-${count.index +1}"
  size   = "512mb"
  image  = "centos-7-x64"
  region = "nyc3"


}

resource "digitalocean_project_resources" "barfoo" {
  project = data.digitalocean_project.foo.id
  resources = [
     digitalocean_droplet.web.*.urn, # this part having issues with
     digitalocean_droplet.bastion.urn,
  ]
}

Solution

  • resources - a list of uniform resource names (URNs) for the resources associated with the project

    Try

    resources = flatten([digitalocean_droplet.web.*.urn, digitalocean_droplet.bastion.urn])