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_project
support import, how described in their documentation:
Projects can be imported using the id returned from DigitalOcean, e.g.
terraform import digitalocean_project.myproject 245bcfd0-7f31-4ce6-a2bc-475a116cca97
Also digitalocean_droplet
support import, like:
terraform import digitalocean_droplet.mydroplet 100823
And digitalocean have a resource digitalocean_project_resources
which 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 plan
and make sure that no new droplets will be created, that means your import worked correctly;terraform plan
and you will see that terraform wants create only the new droplet;