In certain scenarios, when using an aliased AWS provider, you may get the following error:
│ Error: Invalid provider configuration │ │ Provider "registry.terraform.io/hashicorp/aws" requires explicit configuration. Add a provider block to the root module and configure the │ provider's required arguments as described in the provider documentation. │ ╵
This can be confusing, as there is an AWS provider configuration present, e.g.
provider "aws" { alias = "secondary" region = "us-east-2" }
If you have resources that are not using the aliased provider with the provider = aws.secondary argument, they will fallback to using a provider that is not aliased, and if that provider config is missing, you will get the error mentioned above.
An example configuration where this can be exhibited is
/* provider "aws" { region = "us-east-1" }*/ provider "aws" { alias = "secondary" region = "us-east-2" } resource "aws_vpc" "main" { cidr_block = "10.0.0.0/16" } resource "aws_vpc" "main2" { provider = aws.secondary cidr_block = "10.0.0.0/16" }
Running this configuration results in the above error.
Uncommenting and running the configuration again works as expected.
This can be hard to notice in a much more complex configuration, as sometimes the provider argument in a resource is missed by mistake and the error is contradicting what is configured, which can lead to confusion.