This error happens when Terraform finds AWS resources in your configuration but there’s no explicit provider "aws" block in the root module, or the block exists but no region is set.
Add a provider configuration in the root module, for example in providers.tf or main.tf:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
provider "aws" {
region = "us-east-1"
}
If you prefer to use a variable instead of hardcoding the region:
variable "aws_region" {
type = string
default = "us-east-1"
}
provider "aws" {
region = var.aws_region
}
The second error, invalid AWS Region:, is the same underlying issue: the AWS provider received an empty region value. The AWS provider always needs a region, either from the provider block, a Terraform variable, or the AWS_REGION environment variable.
You can also fix it without editing the Terraform files by exporting the region before running Terraform:
export AWS_REGION=us-east-1
terraform plan
After adding the provider block or changing provider requirements, run:
terraform init
terraform plan
If a provider block already exists, check that its region argument isn’t accidentally set to an empty variable or an undefined variable. Also keep the provider configuration in the root module; configs placed only inside child modules won’t satisfy the root module requirement.