Passing multi providers to module

Hi Team, I have a module that requires dual AWS providers. However, I can’t seem to pass it to my module and it keeps complaining the missing module

## Terraform required 
from constructs import Construct
from cdktf import App, TerraformStack, S3Backend,TerraformHclModule
from cdktf_cdktf_provider_aws.provider import AwsProvider,AwsProviderAssumeRole
from imports.teamcity_server import TeamcityServer
from cdktf_cdktf_provider_aws.instance import Instance



class MyStack(TerraformStack):
    def __init__(self, scope: Construct, ns: str):
        super().__init__(scope, ns)

        # Setup aws provider
        # Version defined by requirements.txt package
        aws_provider = AwsProvider(self,
            "AWS",
            region="us-west-2",
            assume_role=[AwsProviderAssumeRole(
                role_arn = "arn:aws:iam::xxx:role/teamcity-management",
                session_name = "vpc"
            )],
        )

        aws_r53_provider = AwsProvider(self,
            "AWS_R53",
            region="us-west-2",
            alias = "r53_zones",
            assume_role=[AwsProviderAssumeRole(
                role_arn = "arn:aws:iam::xxx:role/route53-management",
                session_name = "teamcity-server-management-r53"
            )],
        )

        # S3 Remote Backend
        S3Backend(self,
            bucket="xx-terraform-state",
            key="sample-infra/xx/xx/devops/terraform.tfstate",
            encrypt=True,
            region="us-west-2",
            role_arn = "arn:aws:iam::xx:role/terraform",
            dynamodb_table="xx-terraform-lock-table"
        )

        module = TeamcityServer(self, "teamcity-server",
                                providers= [aws_provider, aws_r53_provider],
                                teamcity_server_instance_type         = "m7g.xlarge",
                                teamcity_server_instance_architecture = "arm64",
                                rds_postgres_version        = "15.5",
                                rds_instance_type           = "db.t4g.small",
                                rds_storage_type            = "gp2",
                                rds_storage_size            = 20, # min rds
                                rds_max_storage_size        = 40
                    )

        ## App setup
        app = App()
        MyStack(app, "first_project")

        ## generate the required files in cdktf.out
        app.synth()

Running cdktf deploy, it retuns the error

               │ Error: Provider configuration not present
               │ 
               │ To work with
               │ module.teamcity-server.aws_route53_record.teamcity_server_certificate_validation_record
               │ its original provider configuration at
               │ module.teamcity-server.provider["registry.terraform.io/hashicorp/aws"].r53_zones
               │ is required, but it has been removed. This occurs when a provider
               │ configuration is removed while objects created by that provider still exist
               │ in the state. Re-add the provider configuration to destroy
               │ module.teamcity-server.aws_route53_record.teamcity_server_certificate_validation_record,
               │ after which you can remove the provider configuration again.

On my cdk.tf.json, I can see the following providers

"provider": {
    "aws": [
      {
        "assume_role": [
          {
            "role_arn": "arn:aws:iam::xxx:role/teamcity-management",
            "session_name": "vpc"
          }
        ],
        "region": "us-west-2"
      },
      {
        "alias": "r53_zones",
        "assume_role": [
          {
            "role_arn": "arn:aws:iam::xxx:role/route53-management",
            "session_name": "teamcity-server-management-r53"
          }
        ],
        "region": "us-west-2"
      }
    ]
  },

Not sure what I did wrong here?

When passing an aliased provider, you need to provide the alias when passing it. You may be able to skip the struct name, but something along the lines of this should work:

providers = [aws_provider, TerraformModuleProvider(provider = aws_r53_provider, module_alias = "r53_zones")]

Thanks! that works well!

1 more question. Do you know how to overcome this warning?

 Warning: Reference to undefined provider
                 │ 
                 │   on cdk.tf.json line 31, in module.teamcity-server.providers:
                 │   31:         "aws": "aws",
                 │ 
                 │ There is no explicit declaration for local provider name "aws" in
                 │ module.teamcity-server, so Terraform is assuming you mean to pass a
                 │ configuration for "hashicorp/aws".
                 │ 
                 │ If you also control the child module, add a required_providers entry named
                 │ "aws" with the source address "hashicorp/aws".
                 │ 
                 │ (and 3 more similar warnings elsewhere)

Seems like the provider doesn’t explicit state hashicorp/aws which might contribute to this issue

Is the teamcity-server module one that you control or is it a 3rd party module?

The warning it letting you know that the module isn’t declaring a required provider named aws. If you control the module, you can do as it suggests and modify the module.

thanks! its controlled by us so should be able to fix it.

Thanks again for your help!