digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
508 stars 277 forks source link

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

Open Kayli opened 6 years ago

Kayli commented 6 years ago

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"
}
Amygos commented 6 years ago

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

andrewsomething commented 6 years ago

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?

holms commented 6 years ago

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? :)

nikolay commented 6 years ago

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

csinge commented 6 years ago

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

nikolay commented 6 years ago

@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!)

csinge commented 6 years ago

@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

atrigubov commented 6 years ago

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

ianmuscat commented 6 years ago

@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!

nikolay commented 6 years ago

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

hmazter commented 6 years ago

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

marcuslind90 commented 5 years ago

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.

ghost commented 5 years ago

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)

knpwrs commented 5 years ago

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
}
k8martian commented 5 years ago

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?

KeithWilliamsGMIT commented 5 years ago

@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 commented 5 years ago

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.

trinhx commented 5 years ago

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

BnMcG commented 4 years ago

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

jonpurdy commented 4 years ago

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

tdyas commented 4 years ago

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.

Madh93 commented 4 years ago

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

briandoesdev commented 1 year ago

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?

andrewsomething commented 1 year ago

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

briandoesdev commented 1 year ago

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