-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Proposal to modify provider meta
to enable specifying the region
at each resource
#31517
base: main
Are you sure you want to change the base?
[WIP] Proposal to modify provider meta
to enable specifying the region
at each resource
#31517
Conversation
…gion at resource tests
Community NoteVoting for Prioritization
For Submitters
|
In the case of pilot light multi-region deployments, I think the approach presented here would generally work. There are some interesting concerns around resource types that inherently support multi-region via primary/replica attributes or global attributes. I also would want to address how Terraform would destroy resources in a region if the practitioner removes a region. Say they want to leave ap-south-1, how could they ensure that all resources were removed? See #27758 for some good comments. |
@AdamTylerLynch In the case of resources that support multiple regions, I think that this will simplify those implementations. Just looking at the example of If a user wanted to remove all resources from a region, they would need to remove the terraform configuration for those resources and allow terraform to destroy them, or run a targeted If a user wanted to move from say In the below basic example, a user would simply remove the region from the locals {
regions = [
"us-east-1",
"us-east-2"]
}
resource "aws_lb" "test" {
for_each = teset(local.regions)
region = each.key
name = "test-lb-tf"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.allow_tls.id]
subnets = data.aws_subnets.public.ids
tags = {
Environment = "production"
}
} In the event that the user updated the One thing I am still trying to figure out how to do is in the event a user was providing a |
…ption, and remove extra new lines
…ng and checking of a resource region
@AdamTylerLynch I have additionally added a central flex function in order to return a proper error to the client in the event they are attempting to deploy to a region that is not in the |
Thanks for all the thought and work you've put into this, @brittandeyoung. We're going to have some discussions on our team around the approach to take with this. We see some definite benefits to multiple regions with one providers, but also some areas for caution, especially around how regionally-separated AWS services are. |
@gdavison great! I will wait to hear from the provider team before I put any more work into this. |
I personally like this idea.
|
Hello! I work on Terraform Core rather than on the AWS provider so I'm just an interested onlooker here and not intending to speak on behalf of the AWS provider team. I've had a quiet hope for the AWS provider to adopt a model like this for a long time, so I'm very excited to see this proposal/prototype. 😀 This new approach could potentially also help with another long-standing oddity: if one changes the Here's one way I could imagine improving that region change situation:
The above is just one design idea and I listed out these details only in case they are useful; some parts of this are probably challenging to implement with the current capabilities of the plugin SDK, but I think it is all valid within and consistent with the spirit of Terraform's resource instance change lifecycle. The main thing I'd love to see, details aside, is that changing Again, I'm not speaking on behalf of the AWS provider team and so please don't take any actions based on this until the provider team has said something about it! I don't want anyone to spend time on implementing something like this if the provider team would eventually oppose it on principle anyway. |
Anything I could do to help move this along |
Description
The pains around multi-region deployments in terraform is an area where I feel a high impact could be made by improving this functionality. Currently today, you have to specify a separate provider per region, use provider aliases and define the same resource at least once per region you want to deploy it to (repeat code). I have been thinking about this issue from two sides.
This Pull request is a Proof of Concept with modifications to the core provider
meta
,tags_interceptor
, and two resources to show functionality. These modifications will enable for resources to be updated to allow specifying the region at each resource level, with a default region when one is not specified.This is accomplished by instead of having a single
AWSClient
inside of the provider meta, a map containing all regions and theirAWSClient
. This allows either defaulting to the region provided in the provider configuration, or allowing a region to be specified at the resource level to determine the region it will be deployed and managed in.The map of regions can be limited by providing a list to the newly added
allowed_regions
provider setting. egallowed_regions=["us-east-1", "us-east-2" ]
. If this setting is not provided a client will be established for all available regions for the account.This will accomplish the following:
aws
provider configuration.This PR only has modified two resources for testing so far.
aws_lightsail_bucket
- Has been modified to allow passing theregion
at the resource level and tests have been added to test that this works as intended when passing in a region other than the default.aws_lightsail_disk
- Has been modified to work with the new provider meta without adding support for region at the resource level, this allows testing and verifying that we can introduce this and still keep existing functionality for all resources and roll out theregion
at each resource level at its own pace.I am not an expert on how the provider meta is configured so I am sure optimization could be made, but I feel a solution similar to this would provide the best end user experience when deploying to multiple regions. I am sure there may be more modifications needed before this proposal would be ready for merge. Additionally every resource would need to be updated as well to use the new provider meta ( I only did the two for testing, but this is as easy as a massive find replace).
Relations
Relates #25308
References
Output from Acceptance Testing