Search code examples
terraformdigital-oceaninfrastructure

Set DigitalOcean project in Terraform script


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


Solution

  • 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.