-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Interpolation for provider field does not work #3072
Comments
any idea for workaround? |
as workaround created this simple script
|
It would be great to have the interpolation of provider working. |
This is something we should address. Closing to consolidate around #1819. |
I see that there is an ongoing discussion on #1819, but that seems to take it to a deeper level. Wouldn't it make sense to add interpolation here and at least allow one to dynamically select a provider in a module? |
I was struggling with this today, and found an alternative workaround to the bash script. You could include in your module the provider with an interpolated region that then all of your resources within the module use. As an example, here would be a module for an AWS VPC: # module/vpc/vpc.tf
variable "aws_region" {}
provider "aws" {
alias = "aws_vpc"
region = "${var.aws_region}"
}
resource "aws_vpc" "vpc" {
provider = "aws.vpc_aws"
# Other vpc config here
}
resource "aws_subnet" "private_subnet" {
provider = "aws.vpc_aws"
# Other subnet config here
} And then if you need to create a cross region vpc in each region, you could then do in your # main.tf
module "vpc_east" {
source "path/to/module/vpc"
region "us-east-1"
}
module "vpc_west" {
source "path/to/module/vpc"
region "us-west-1"
} Might not work in all cases, but this would allow you to reuse the bulk of configuration code and just make it region specific... or at least as far as I can tell. I haven't actually run an Update: Based on the upstream issue and comment #1819 (comment) , it is possible that this might not work currently. Again, this would have to be tested. |
From my tests you don't need the alias in the submodule - terraform uses the closest provider. This seems to be backed up in the In the above sample, the vpc.tf can be written as: # module/vpc/vpc.tf
variable "aws_region" {}
provider "aws" {
region = "${var.aws_region}"
}
resource "aws_vpc" "vpc" {
# Other vpc config here
}
resource "aws_subnet" "private_subnet" {
# Other subnet config here
} |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
get error while trying to apply plan
Errors:
use case:
create same security group in all aws regions:
please let me know if there better solution to do cross region transformation
The text was updated successfully, but these errors were encountered: