I want to create a new droplet, then add it to an existing project, which has other existing droplets in it already.
I can see how to create a new project and put the droplet in that - https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/project
I can see how to put the droplet in an existing project - https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/project_resources
But both of these options just sets the resources value to be a list of the single droplet, which is going to wipe out anything else that's already there, surely?
How do I append a new droplet to an existing project? Essentially what I want is something like
resources = resources.append(digitalocean_droplet.artbio_se.urn)
First of all please read about "state" concept in the terraform: https://developer.hashicorp.com/terraform/language/state
If you want to add something already existing, you need to:
But this will work only if your terraform provider support of existing infrastructure.
For example
digitalocean_projectsupport import, how described in their documentation:Also
digitalocean_dropletsupport import, like:And digitalocean have a resource
digitalocean_project_resourceswhich allow you to assign resources to a already existing DigitalOcean Project.And if you already have project and want to add existings droplets and create a new one you need:
terraform planand make sure that no new droplets will be created, that means your import worked correctly;terraform planand you will see that terraform wants create only the new droplet;