AWS Amazon EC2 Peering Connection Accepter

This page shows how to write Terraform and CloudFormation for Amazon EC2 Peering Connection Accepter and write them securely.

aws_vpc_peering_connection_accepter (Terraform)

The Peering Connection Accepter in Amazon EC2 can be configured in Terraform with the resource name aws_vpc_peering_connection_accepter. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L3062
resource "aws_vpc_peering_connection_accepter" "us-east-2-us-east-1" {
provider = aws.us-east-2
vpc_peering_connection_id = aws_vpc_peering_connection.us-east-1-us-east-2.id
auto_accept = true
}
resource "aws_vpc_peering_connection" "us-east-1-us-west-1" {
main.tf#L118
resource "aws_vpc_peering_connection_accepter" "bastion_connectivity_dr" {
  provider                  = aws.us-east-1
  vpc_peering_connection_id = aws_vpc_peering_connection.bastion_connectivity_dr.id
  auto_accept               = true

}
peer.tf#L22
resource "aws_vpc_peering_connection_accepter" "east2_east1_accepter" {
  provider                  = aws
  vpc_peering_connection_id = aws_vpc_peering_connection.east2_to_east1.id
  auto_accept               = true

  tags = {
main.tf#L39
resource "aws_vpc_peering_connection_accepter" "accepter_connection_one" {
  vpc_peering_connection_id = aws_vpc_peering_connection.peering_connection_one.id
  auto_accept               = true

  tags = {
    Side = "VPC Peering A Accepter"
main.tf#L1
resource "aws_vpc_peering_connection_accepter" "this" {
  vpc_peering_connection_id = var.id
  auto_accept               = true
  tags = {
      Name = var.name
  }

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides a resource to manage the accepter's side of a VPC Peering Connection. When a cross-account (requester's AWS account differs from the accepter's AWS account) or an inter-region VPC Peering Connection is created, a VPC Peering Connection resource is automatically created in the accepter's account. The requester can use the aws_vpc_peering_connection resource to manage its side of the connection and the accepter can use the aws_vpc_peering_connection_accepter resource to "adopt" its side of the connection into management.

Tips: Best Practices for The Other AWS Amazon EC2 Resources

In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

aws_ebs_volume

Ensure to use a customer-managed key for EBS volume encryption

It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).

risk-label

aws_instance

Ensure to avoid storing AWS access keys in user data

It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::EC2::VPCPeeringConnection (CloudFormation)

The VPCPeeringConnection in EC2 can be configured in CloudFormation with the resource name AWS::EC2::VPCPeeringConnection. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

PEERING-RULES.yml#L9
    Type: AWS::EC2::VPCPeeringConnection
    Condition: IfUSWestRegion
    Properties:
      VpcId:
        Fn::ImportValue: VPCUsaId
      PeerRegion: eu-central-1
three-vpcs.template.yml#L152
  #   Type: AWS::EC2::VPCPeeringConnection
  #   Properties:
  #     VpcId:  !GetAtt VPCAlpha.Outputs.VPC
  #     PeerVpcId: !GetAtt VPCBeta.Outputs.VPC
  #     Tags:
  #     - Key: Name
vpc.yml#L15
    Type: AWS::EC2::VPCPeeringConnection
    Properties:
      PeerOwnerId: ${env:AWS_COGNITO_ACCOUNT_ID}
      PeerRoleArn: arn:aws:iam::${env:AWS_COGNITO_ACCOUNT_ID}:role/calcutta-${self:custom.stage}-peer-role
      PeerVpcId: ${env:AWS_COGNITO_VPC_ID}
      VpcId:
vpc-peer.yml#L13
    Type: "AWS::EC2::VPCPeeringConnection"
    Properties:
      PeerVpcId:
        Fn::ImportValue: !Sub
          - ${Sandbox2VpcStackName}-VPCID
          - Sandbox2VpcStackName: !Ref Sandbox2StackName
SimpleVPCPeer.yml#L11
    Type: AWS::EC2::VPCPeeringConnection
    Properties:
      PeerOwnerId: 442771530490
      PeerRoleArn: arn:aws:iam::880898370811:role/create-role-peerRole-X3ZNCOH3368Z
      PeerVpcId: !Ref LnCustomVPC2
      VpcId: !Ref LnCustomVPC1
resources1.json#L9
    "Type": "AWS::EC2::VPCPeeringConnection",
     "Properties" : {
        "PeerVpcId" : {
          "Ref": "PeerVpcId"
        },
        "VpcId": ""
peersonly.json#L7
        "Type" : "AWS::EC2::VPCPeeringConnection",
        "Properties" : {
            "PeerVpcId" : { "Ref" : "ProductionVPC" },
            "VpcId" : { "Ref" : "DevelopmentVPC" },
            "Tags" : [
                {
VPC_Peering.json#L43
            "Type": "AWS::EC2::VPCPeeringConnection",
            "Condition" : "PROD_VPC",
            "Properties": {
            "VpcId": {"Fn::ImportValue" : {"Fn::Sub" : "MGMT-VPCId"}},
            "PeerVpcId": {"Ref": "VPCID"}
            }
cdk-blog-vpc-peer2.template.json#L4
      "Type": "AWS::EC2::VPCPeeringConnection",
      "Properties": {
        "PeerVpcId": {
          "Fn::ImportValue": "cdk-blog-vpc-staging:ExportsOutputRefvpcstagingF0BF23A463A94C5D"
        },
        "VpcId": {
Core-VPCPeeringConnections.json#L104
      "Type" : "AWS::EC2::VPCPeeringConnection",
      "Properties" : {
        "VpcId" : { "Fn::ImportValue" : { "Fn::Sub" : "${CoreVPCStackName}-VPC" }},
        "PeerVpcId" : { "Fn::ImportValue" : { "Fn::Sub" : "${BuildVPCStackName}-VPC" }},
        "Tags" : [
          { "Key" : "Name", "Value" : { "Fn::Sub" : "Core-BuildVPCPeeringConnection" }}

Parameters

Explanation in CloudFormation Registry

Requests a VPC peering connection between two VPCs: a requester VPC that you own and an accepter VPC with which to create the connection. The accepter VPC can belong to another AWS account and can be in a different Region to the requester VPC.

The requester VPC and accepter VPC cannot have overlapping CIDR blocks. If you create a VPC peering connection request between VPCs with overlapping CIDR blocks, the VPC peering connection has a status of failed.

For more information, see Walkthough: Peer with a VPC in another AWS account.

Frequently asked questions

What is AWS Amazon EC2 Peering Connection Accepter?

AWS Amazon EC2 Peering Connection Accepter is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon EC2 Peering Connection Accepter?

For Terraform, the huanwlisa/terraform, bstascavage/terraform-vault-consul-deployment and brucehvn/edify source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the elnurm/aws_cloudformation_templates, kennyk65/aws-teaching-demos and burke1791/march-madness-calcutta-api source code examples are useful. See the CloudFormation Example section for further details.