Open syntaqx opened 5 years ago
I would like to take a stab at this. Looking at other providers it seems like its either set the region at the provider level(AWS) or you can set the region at the provider level but still override the region at the resource level(GCP). I believe it would be a better experience to follow the GCP way of doing this. Basically, for each resource, the region argument would become optional. If the value is null, we use the value provided in the provider. Otherwise, we override the region.
I think I re-iterated what you said @syntaqx but just want to make my intentions explicit.
Sorry, I meant to update here and never got around to doing it.
I took a stab at implementing this and the code came out pretty messy—bunch of if checks and extra logic. There's also a nasty side effect because you have to mark the region
attribute on the resources as computed
/optional
. Doing so causes region
to be completely absent from the plan which to me is a no-go.
This spun off a conversation on the Terraform committers Slack because I think the right way for this to work is to either have multiple provider blocks per region or have proper support for inheriting provider level/default attributes into resources. I'm supposed to open an issue on Terraform core about this for research and discussion.
With all that said, @lfarnell, I'd be very interested in hearing/seeing your thoughts or implementation.
@eddiezane Let me hack on this tonight and see what I can figure out. I will try to see how the GCP folks accomplished this. I'll update this issue once I have a better understanding of the changes I envision.
So I did some hacking last night and found some interesting results similar to @eddiezane.
I did some additional digging around some other providers. AWS sets the region by default in the provider and that if multiple regions are needed that you can alias them and include them in the resources. I also noticed that the region(or equivalent to in AWS parlance) does not show up in the plan according to examples and documentation that I have seen. I still want to go down the rabbit hole a little more to see if anything more can be done.
Exciting updates, hoping this is something we're able to get working.
Feature request: Provider default
region
andproject
Similar to that of other Terraform providers, it would be fantastic to be able to provide default, overridable values for resource
region
andproject
.These variables are very often the same within a single state, I'd love to not have to specify them for each resource as well as not need to configure the value for modules relying on my provider.
As an added benefit, this also creates consistency between other DO integrations, such as
docker-machine
and how the environment variables are used when creating resources.Example
Usage
Arguments
region
The default region to manage resources in. If another region is specified on a resource, it will be used instead.project
The default project to associate resources to. If another project is specified on a resource, it will be used instead.PR Template stuff
Terraform Version
v0.11.13
Affect Resources(s)
region
digitalocean_cdn
digitalocean_database_cluster
digitalocean_droplet
digitalocean_firewall
digitalocean_floating_ip
digitalocean_loadbalancer
digitalocean_kubernetes_cluster
digitalocean_spaces_bucket
digitalocean_volume
project
digitalocean_droplet
digitalocean_loadbalancer
digitalocean_domain
digitalocean_volume
digitalocean_floating_ip
digitalocean_spaces_bucket
Let me know if I did this right!