How to create db in same account but different region

Hi all, we need to create several db’s in the same aws account but different region.
I understand that the secret lies in the providers.tf file where we got

provider "aws" {
  access_key = var.AWS_ACCESS_KEY_ID
  secret_key = var.AWS_SECRET_ACCESS_KEY
  region     = var.aws_region
}

and that makes all db’s to be created within 1 region, how can i have different region per db?

i tried to work with aliases,

provider "aws" {
  alias      = "fr"
  access_key = "${var.AWS_ACCESS_KEY_ID}"
  secret_key = "${var.AWS_SECRET_ACCESS_KEY}"
  region     = "eu-central-1"

Then i tried to call it within the module - but i cannot call the provider from within the module

 module "db1" {
  source  = "terraform-aws-modules/rds/aws"
  version = "3.3.0"
  providers {
    aws = "aws.fr"
  }
  identifier = "db1"

This is the detailed error

│ Error: Unsupported block type
│
│   on main.tf line 221, in module "db1":
│  221:   providers {
│
│ Blocks of type "providers" are not expected here.

Thank you!

Hi @Carlos,

I think the problem here is that providers is an argument which takes a map-like expression (though it’s not actually a map value), rather than a nested block:

  providers = {
    aws = aws.fr
  }

Note also that neither of the provider config references ought to be in quotes because these are direct references to the provider configurations, rather than arbitrary expressions. (Notice that aws and aws.fr would not be valid in any other context in the language, because provider configurations aren’t values in the same sense that other objects are.)

1 Like