terraform-provider-digitalocean icon indicating copy to clipboard operation
terraform-provider-digitalocean copied to clipboard

Feature request: allowing to specify project name property in provider configuration section

Open Kayli opened this issue 7 years ago • 25 comments

DigitalOcean "projects" feature have recently been added, see more details here: https://blog.digitalocean.com/organizing-your-infrastructure-with-projects/

Proposal is to add an optional project name field to the list of provider properties:

provider "digitalocean" {
  token = "${var.do_token}"
  project = "my-project"
}

Kayli avatar Aug 27 '18 23:08 Kayli

This can be very useful, in this way you can for example associate terraform's workspaces and DigitalOcean's projects, but projects are not currently supported by DigitalOcean's API: http://disq.us/p/1u9vz79

Amygos avatar Aug 28 '18 10:08 Amygos

Thanks for the request. We absolutely want to bring project support into Terraform. Once the DigitalOcean API itself has support, we will add it here as well.

Adding it to the provider properties is an interesting idea. I'd love to here any feedback other might have. Would people expect to create resources in multiple projects from a single Terraform configuration?

andrewsomething avatar Aug 28 '18 15:08 andrewsomething

I'd personally would want just a separate directive for this like digitalocean_project, and just include list of resources in there. This depends on how DO will implement their API probably right? :)

holms avatar Aug 29 '18 08:08 holms

@andrewsomething Maybe on the provider level it would define a global default, which can be overridden in resources.

nikolay avatar Sep 03 '18 20:09 nikolay

Instead of specifying a project, could we have tokens specific to a project. That way we can have better access control and requires no change to terraform

csinge avatar Sep 19 '18 23:09 csinge

@csinge Even one token is hard to deal with in Terraform (you can't have it in a variable if the provider has a version and an alias), and multiple will be even worse. The project ID needs to be a parameter, and possibly tokens could be limited to a subset of projects (plural!)

nikolay avatar Sep 20 '18 01:09 nikolay

@nikolay I haven't encountered those problems since my usage is a little bit more simplistic. My uses case would be to represent environments as separate projects, so that I can keep those resources logically grouped. In this way I only need to change the token for the different environments

csinge avatar Sep 20 '18 01:09 csinge

It's really important feature, please add support of project in terraform asap.

atrigubov avatar Oct 04 '18 14:10 atrigubov

@andrewsomething, personally, my use-case isn’t really to have Droplets created in different projects from the same TF config (at least currently), but rather to make sure that resources of a specific TF config are created in the correct project inside DO. I hope that helps and thanks for your work on the project!

ianmuscat avatar Oct 04 '18 22:10 ianmuscat

@ianmuscat We all have different use cases and this should work well for project big and small. If we dumb this down, then this module is useless for the enterprise users, which I think are who HashiCorp makes money from and funds this project's development.

nikolay avatar Oct 04 '18 22:10 nikolay

The API for Projects is in Beta now https://developers.digitalocean.com/documentation/v2/#projects---beta

hmazter avatar Oct 26 '18 14:10 hmazter

I also think this would be a great addition. When I was looking for it I was expecting the Access Tokens to be on a Project basis, that's what felt most "obvious". It makes sense that you can have different Access Tokens for different Projects.

marcuslind90 avatar Dec 22 '18 12:12 marcuslind90

The API for Projects is in Beta now https://developers.digitalocean.com/documentation/v2/#projects---beta

Wonder if it makes sense to have a beta provider, much like Google (ref: https://www.terraform.io/docs/providers/google/provider_versions.html#google-beta)

ghost avatar Dec 25 '18 23:12 ghost

It seems like the projects API is no longer in beta (the beta header is not there, which breaks the link above, but the API is listed).

The way the API is constructed it appears that you have to create the project and then move resources into that project. I'm not sure how the internals of Terraform are set up, but I think the most natural way to model this would be something like this:

resource "digitalocean_project" {
  name = "project name"
  resources = ["${digitalocean_foo.bar.urn}"] # for instance
}

knpwrs avatar Jan 06 '19 23:01 knpwrs

I am new terraform user, before this, how did you guys created droplet to a specific project? Manually move droplet/s in to project from console?

k8martian avatar Jan 09 '19 05:01 k8martian

@k8martian I usually make the project I want to provision resources for the default project before running Terraform so that the resources will be created in that project. It removes the need to manually move resources.

Personally I would like a different access token per project as others have suggested. It doesn't make a whole lot of sense to me to have a single token for multiple environments such as development or production as there's no way to manage access. Or as @nikolay has mentioned, possibly have a mix of the project ID as a parameter (in a different directive maybe) AND different access tokens for different projects. However, this decision is probably up to DigitalOcean and how they implement support for different projects.

KeithWilliamsGMIT avatar Jan 09 '19 11:01 KeithWilliamsGMIT

Having checked this today, for the first time in a while, it now looks like support for this feature has been added through digitalocean_project. It seems that it has been implemented as suggested by @knpwrs above where the resources are defined within the new digitalocean_project directive. For a full run down you can read the docs.

@Kayli - I suggest to close this issue if the original request was fulfilled.

KeithWilliamsGMIT avatar Jun 13 '19 21:06 KeithWilliamsGMIT

The digitalocean_project only seems create a new project. How can we move resources into an already existing project?

trinhx avatar Aug 28 '19 06:08 trinhx

This seems to be done now: https://www.terraform.io/docs/providers/do/r/project.html, so this issue can probably be closed.

BnMcG avatar Jan 04 '20 18:01 BnMcG

Project can be created, but you can't create a droplet and add to an existing project yet.

jonpurdy avatar Feb 27 '20 19:02 jonpurdy

FYI https://github.com/terraform-providers/terraform-provider-digitalocean/pull/396 adds a digitalocean_project_resources resource that can add droplets to an existing project not managed by Terraform.

tdyas avatar Apr 09 '20 04:04 tdyas

Thank you very much @tdyas. It works like a charm :smiley:

Madh93 avatar Apr 11 '20 17:04 Madh93

FYI https://github.com/terraform-providers/terraform-provider-digitalocean/pull/396 adds a digitalocean_project_resources resource that can add droplets to an existing project not managed by Terraform.

This link does not exist anymore, has this been added to the DigitalOcean provider yet?

briandoesdev avatar Mar 14 '23 18:03 briandoesdev

Not sure why that isn't redirected, but the correct link would now be: https://github.com/digitalocean/terraform-provider-digitalocean/pull/396

The docs can be found here: https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/project_resources

andrewsomething avatar Mar 14 '23 18:03 andrewsomething

@andrewsomething Perfect, thanks! Don't know how I missed that in the documentation when I was looking through.

briandoesdev avatar Mar 14 '23 18:03 briandoesdev