Skip to content

mirrorweb/terraform-aws-vpc-peering

 
 

Repository files navigation

AWS VPC Peering Connection Module

Build Status

Terraform module, which creates a peering connection between two VPCs and adds routes to the local VPC. Routes on the Peer VPC side should be configured separately.

This module is designed to work with VPC module from the Terraform Registry

Preamble

Always make sure you pinned the module version! Please, be aware that any new code in master may intorduce some regressions. Moreover, sometimes I can easily miss some of them because I personally doen't use all the VPC peering features on daily basis.

Terraform versions / Contributions

Terraform 0.12. Pin module version to ~> v2.0. Submit pull-requests to master branch.

Terraform 0.11. Pin module version to ~> v1.0. Submit pull-requests to terraform011 branch.

Changelog

Changelog is in the CHANGELOG.md

Note

These types of resources are supported:

Usage

Examples

Sample configuration is located in examples directory.

Single Region Peering

Notice: You need to declare both providers even with single region peering.

module "single_account_single_region" {
  source = "../../"

  providers = {
    aws.this = aws
    aws.peer = aws
  }

  this_vpc_id = var.this_vpc_id
  peer_vpc_id = var.peer_vpc_id

  auto_accept_peering = true

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

Usage with already created peering connection:

module "vpc_single_region_peering" {
  source = "./terraform-aws-vpc-peering"

  providers = {
    aws.this = aws
    aws.peer = aws
  }

  peer_region             = "eu-west-1"
  this_vpc_id             = "vpc-00000000"
  peer_vpc_id             = "vpc-11111111"
  cross_region_peering    = false
  auto_accept_peering     = true
  peering_id              = "pcx-00000000"

}

Cross Region Peering / Cross Account Peering

In order to setup cross-region or cross-account peering connection, you must configure providers for Terraform. You can find an example here.

Medium post, which might be useful.

module "vpc_cross_region_peering" {
  source = "github.com/grem11n/terraform-aws-vpc-peering?ref=cross-region-peering"

  providers = {
    aws.this = aws.src
    aws.peer = aws.dst
  }

  peer_region             = "us-east-1"
  this_vpc_id             = "vpc-00000000"
  peer_vpc_id             = "vpc-11111111"
  cross_region_peering    = true
  auto_accept_peering     = true

  tags = {
    Name        = "my-peering-connection"
    Environment = "prod"
  }
}

Testing

This module is tested with Terratest You can find existing tests in the test/ directory.

Authors

Module managed by Yurii Rochniak

License

Apache 2 Licensed. See LICENSE for full details.

About

Terraform module to setup VPC peering connection

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 78.2%
  • Go 21.8%