Provider within module

terraform {

  required_version = "0.15.5"

  required_providers {

    aws = {

      source                = "hashicorp/aws"

      version               = "3.42.0"

      configuration_aliases = [ aws.est  ]




provider "aws" {

  region = "us-east-1"


provider "aws" {

  region = "us-east-2"

  alias  = "east2"


module "vpcest1" {

  source = "./vpcseast1"

  links  = [module.vpcest1.vpc1out, module.vpcest1.vpc2out]



module "vpcest2" {

  source = "./vpcseast2"

  links2 = [module.vpcest2.vpc10out, module.vpcest2.vpc20out]

  providers = {

    aws.est = aws.east2



module "east1site" {

  source           = "./projects-east1"

  links            = [module.vpcest1.vpc1out, module.vpcest1.vpc2out]

  networks         = [module.east1site.pblcsout1, module.east1site.pblcsout2, module.east1site.pblcsout3]

  webeast1         = [module.east1site.webs1out1, module.east1site.webs1out2, module.east1site.webs1out3]

  security         = [module.east1site.sec1east1out1, module.east1site.sec2east1out2, module.east1site.sec3east1out3, module.east1site.sec4east1out4]

  nacls            = [module.east1site.nacl1out, module.east1site.nacl2out, module.east1site.nacl3out]

  route1table      = [module.east1site.table1out, module.east1site.table2out, module.east1site.table3out]

  gateway          = [module.east1site.intgwout]

  route2table      = [module.east1site.table4out, module.east1site.table5out, module.east1site.table6out]

  tolnk1           = [module.east1site.lnk1out, module.east1site.lnk2out, module.east1site.lnk3out]

  tolnk2           = [module.east1site.lnk4out, module.east1site.lnk5out, module.east1site.lnk6out]

  eips             = [module.east1site.eip1, module.east1site.eip2, module.east1site.eip3]

  tonat1           = [module.east1site.nat1out, module.east1site.nat2out, module.east1site.nat1out]

  dblists          = [module.east1site.db1out, module.east1site.db2out, module.east1site.db3out]

  db_subnets       = [module.east1site.dbsbntgrpout]

  alb              = [module.east1site.alb1out]

  alb_listner      = [module.east1site.alblisnterout]

  alb_listner_rule = [module.east1site.lb_listner_ruleout]

  alb_target_grp   = [module.east1site.albtgrtout]

  s3buckets        = [module.east1site.bcketout]

  launch           = [module.east1site.scale1out, module.east1site.scale2out]

  scale10grp       = [module.east1site.scalegrp1out, module.east1site.scalegrp1out]

  attachgrp        = [module.east1site.scale_attachout]

  peering1         = [module.east1site.peer1out, module.east1site.peer1_accepter1_out]


module "east2site" {

  source = "./projects-east2"

  providers = {

    aws.est = aws.east2


  links2            = [module.vpcest2.vpc10out, module.vpcest2.vpc20out]

  networks2         = [module.east2site.pblcsout10, module.east2site.pblcsout20, module.east2site.pblcsout30]

  webeast2          = [module.east2site.webs2out10, module.east2site.webs2out20, module.east2site.webs2out30]

  security2         = [module.east2site.sec10east2out10, module.east2site.sec20east2out20, module.east2site.sec30east2out30, module.east2site.sec40east2out40]

  nacls2            = [module.east2site.nacl10out, module.east2site.nacl20out, module.east2site.nacl30out]

  route10table      = [module.east2site.table10out, module.east2site.table20out, module.east2site.table30out]

  gateway2          = [module.east2site.int2gwout]

  route20table      = [module.east2site.table40out, module.east2site.table50out, module.east2site.table60out]

  tolnk10           = [module.east2site.lnk10out, module.east2site.lnk20out, module.east2site.lnk30out]

  tolnk20           = [module.east2site.lnk40out, module.east2site.lnk50out, module.east2site.lnk60out]

  eips2             = [module.east2site.eip10, module.east2site.eip20, module.east2site.eip30]

  tonat2            = [module.east2site.nat10out, module.east2site.nat20out, module.east2site.nat30out]

  dblists2          = [module.east2site.db10out, module.east2site.db20out, module.east2site.db30out]

  db2_subnets       = [module.east2site.dbsbnt2grpout]

  alb2              = [module.east2site.alb2out]

  alb2_listner      = [module.east2site.alb2lisnterout]

  alb2_listner_rule = [module.east2site.lb_listner_rule2out]

  alb2_target_grp   = [module.east2site.alb2tgrtout]

  s3buckets2        = [module.east2site.bcket2out]

  launch2           = [module.east2site.scale10out, module.east2site.scale20out]

  scale20grp        = [module.east2site.scalegrp10out, module.east2site.scalegrp20out]

  attach2grp        = [module.east2site.scale2_attachout]

  peering2          = [module.east2site.peer2out, module.east2site.peer2_accepter2_out]

│ Warning: Provider aws.est is undefined
│   on line 28, in module "vpcest2":
│   28:     aws.est = aws.east2
│ Module module.vpcest2 does not declare a provider named aws.est.
│ If you wish to specify a provider configuration for the module, add an entry for aws.est in the required_providers block within the module.    
│ (and one more similar warning elsewhere)
Success! The configuration is valid, but there were some validation warnings as shown above.

im trying to applying module for two region and one of the region explicitly to provider along with alias . still i got warning with configuration is valid , using terraform 15.5

Hi @mohammedbanabila,

I cannot tell exactly what you are doing in the configuration here, perhaps it would be a little easier to read if you fixed the formatting.

The warning is indicating that you have not declared aws.est as a configuration alias within the module, therefor passing aws.est = aws.east2 is doing nothing. The module must declare and use that provider name in order to pass in the desired provider by that name.

having the same issue. how do we do that? i cant find anything in the documentation about declaring a “required provider” per module, only in the root terraform block which it looks like is configured correctly according to what the docs say.

Hi @aquaticpond, I suggest you start a new thread with a complete example of the problem you are having. The above issue is that aws.est is not defined in the module, so there’s no way to know what the intent was if the module was not going to use the provider at all.

yeah, same problem. how do i give it the intent that i want to use that provider? the documentation says define it in the top level terraform block which both of us have but its still giving the error. there is nothing in the documentation about defining a required provider within a module. thats what were asking about.

I would need to see an example to say for sure. If there is no provider with that alias within the module, there are no resources referring to that provider so it cannot be used in the first place.

The docs on Providers Within Modules should cover what’s needed, but if you still have questions, please start a new thread with an example of the problem you are facing.