terraform-provider-aws
terraform-provider-aws copied to clipboard
Add "Region" as argument reference for Data Source: aws_s3_bucket
It would be nice if we can have region reference when we are looking for a S3 bucket in data source. If the S3 bucket is in another region and your provider is defined for a different region, then getting the following error.
In my case: S3 bucket is created in: us-east-1
and provider has region = "us-west-2". I wanted to get the ARN of the bucket to get and use in the current terraform definition.
My Error:
data "aws_s3_bucket" "openvpn_bucket" { bucket = "seceng-terraform-statefiles" }
Error:
╷ │ Error: Failed getting S3 bucket (seceng-terraform-statefiles): BucketRegionError: incorrect region, the bucket is not in 'us-west-2' region at endpoint '' │ status code: 301, request id: , host id: │ │ with data.aws_s3_bucket.openvpn_bucket, │ on data.tf line 15, in data "aws_s3_bucket" "openvpn_bucket": │ 15: data "aws_s3_bucket" "openvpn_bucket" { │ ╵
Hey @GouravIN 👋 Thank you for taking the time to raise this! One option to achieve this functionality with the provider today would be to use a provider alias to allow you to access the separate region. The configuration would look something like the below configuration. Would this satisfy your needs?
provider "aws" {
alias = "usw2"
region = "us-west-2"
}
data "aws_s3_bucket" "openvpn_bucket" {
provider = aws.usw1
bucket = "seceng-terraform-statefiles"
}
The suggestion will not work in a module with for_each. Allowing a data source to query another region would be wonderful.
How about if we are trying to discover the region at deploy time and don't know it so can't create a provider ahead of time,
How about if we are trying to discover the region at deploy time and don't know it so can't create a provider ahead of time,
oh snap.. seriously how is this not a thing? Orchestrating across regions, accounts, etc is not an edge case.
this feature shouldnt just be for aws, all clouds need this, especially google cloud and ibm, which dont have region restricted global services or vpcs...