4

I have terraform script for deploying and provisioning DigitalOcean droplets and I wanna specify custom DO project for this instances instead of default one.

I couldn't find any references for project attribute in the documentation for digitalocean_droplet resource: https://www.terraform.io/docs/providers/do/r/droplet.html

I wanna be able to do something like this:

resource "digitalocean_droplet" "node" {
  ...
  project = "test"
  ...
}

So instances deployed with this terraform script will be allocated to test project in DO:

enter image description here

Dmitry T.
  • 464
  • 4
  • 12

3 Answers3

3

Hope you are safe.

Nowdays you can do that as following:

resource "digitalocean_droplet" "node" {
  name               = "ubuntu-nyc1-node-01"
  image              = "ubuntu-18-04-x64"
  region             = "nyc1"
  size               = "s-1vcpu-1gb"
  private_networking = true
}

resource "digitalocean_project" "project" {
  name        = "Project"
  description = "project description"
  purpose     = "Web Application"
  environment = "Production"
  resources   = [
      "${digitalocean_droplet.node.urn}"
    ]
}

Hope this code still can help you.

2

DigitalOcean projects are not implemented in the Terraform provider, yet. There's an open feature request for it.

It will most likely be an extra Terraform resource as they are an extra API object. You then could add other resources either

That depends how it will be implemented, though.

Dominik
  • 2,283
  • 1
  • 25
  • 37
0

If you want to put the droplet in a project that already exist and not create a new one you can do the following:

data "digitalocean_project" "myproj" {
  name        = "myprojname"
}

resource "digitalocean_droplet" "mydroplet" {
  image  = "debian-11-x64"
  name   = "newVM"
  region = "fra1"
  size   = "s-1vcpu-1gb"
}

resource "digitalocean_project_resources" "terraform_rs" {
  project = data.digitalocean_project.myproj.id
  resources = [
     digitalocean_droplet.mydroplet.urn
  ]
}

This uses the data api to query DO and get your project, then you don't create a new project but create a new project resource which means you just assign the resource to the project. Hope this helps someone in the future.

lwileczek
  • 2,084
  • 18
  • 27