grem11n / terraform-aws-vpc-peering

Terraform module to setup VPC peering connection
https://registry.terraform.io/modules/grem11n/vpc-peering/aws/latest
Apache License 2.0
126 stars 91 forks source link

The argument "region" is required, but no definition was found. #78

Closed az-z closed 1 year ago

az-z commented 3 years ago

hello, I'm getting the following error when attempting to use the module. :


terraform apply 
<skip output >
 Warning: Empty provider configuration blocks are not required
│ 
│   on .terraform/modules/vpc-peering/provider.tf line 11:
│   11: provider "aws" {
│ 
│ Remove the aws.this provider block from module.vpc-peering. Add aws.this to the list of configuration_aliases for aws in
│ required_providers to define the provider configuration name.
│ 
│ (and one more similar warning elsewhere)
╵
╷
│ Error: Missing required argument
│ 
│   on .terraform/modules/vpc-peering/provider.tf line 11, in provider "aws":
│   11: provider "aws" {
│ 
│ The argument "region" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│ 
│   on .terraform/modules/vpc-peering/provider.tf line 15, in provider "aws":
│   15: provider "aws" {
│ 
│ The argument "region" is required, but no definition was found.

im using another module to define VPCs . In the definition of that module the provider.tf:

provider "aws" {
  access_key = var.AWS_ACCESS_KEY
  secret_key = var.AWS_SECRET_KEY
  region     = var.AWS_REGION
}

the code: main.tf

module "vpc" {
  source   = "git::https://bitbucket.org/private_repo"
  AWS_REGION = "us-east-1"
  vpc_name = var.vpc_name
}

rds_vpc.tf:

module "rds_vpc" {
  source   = "git::https://bitbucket.org/private_repo"
  AWS_REGION = "us-east-1"
  vpc_name = var.rds_vpc_name
}

module "vpc-peering" {
  source = "grem11n/vpc-peering/aws"
  version = "3.1.0"
//  providers = {
//    aws.this = aws
//    aws.peer = aws
//  }

  this_vpc_id = module.vpc.vpc_id
  peer_vpc_id = module.rds_vpc.vpc_id

  auto_accept_peering = true

  tags = {
    Name        = "tf-single-account-single-region"
    Environment = "DEV"
  }
}

I'm not sure what to take out of this.

grem11n commented 3 years ago

Hello, @az-z ,

Could you advise which version of Terraform are you using as well as which version of the module, please? Also, you can refer to the examples of this repo. CI uses the code from that directory to run the tests. So, you can be sure that it works for matching TF & module versions

az-z commented 3 years ago

@grem11n , im using

terraform -v
Terraform v0.15.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v3.43.0

Your version of Terraform is out of date! The latest version
is 0.15.5. You can update by downloading from https://www.terraform.io/downloads.html

the module version is

module "vpc-peering" {
  source  = "grem11n/vpc-peering/aws"
  version = "3.1.0"
}
grem11n commented 3 years ago

It looks like, providers stanza is required. I ran the tests using your TF version 0.15.2 as well as the latest 0.15.5 here: https://github.com/grem11n/terraform-aws-vpc-peering/pull/79/checks?check_run_id=2767020979

So, you can see that the code from examples works

doryer commented 2 years ago

Try using default aws region as environment variable export AWS_REGION=""

grem11n commented 1 year ago

Closing old issues.