1
votes

I wrote a CloudFormation template, which among other stuff also creates a VPC peering connection.

If you are familiar with VPC peerings then you know that after the creation, a request is created and waiting for approval.

I'd like to add to the outputs portion of the CloudFormation template the VPC peering connection request id.

Is that possible? I couldn't find the way...

Edit:

This is the relevant portion of the template:

"Resources" : {
  "VPC": {
    "Type" : "AWS::EC2::VPC",
    "Description" : "Choose which VPC the security groups should be deployed to",
    "Properties" : {
      "CidrBlock" : "172.51.0.0/16",
      "EnableDnsSupport" : "true",
      "EnableDnsHostnames" : "true",
      "InstanceTenancy" : "default"
    }
  },

  "VPCPeering" : {
    "Type" : "AWS::EC2::VPCPeeringConnection",
    "Properties" : {
      "PeerVpcId" : "vpc-2XXXXXb",
      "VpcId" : { "Ref" : "VPC" }
    }
  },

I'm using Jenkins with the CloudFormation plugin to issue the creation of a new stack.

I want the new stack to automatically create peering between the VPC that the stack creates and the existing management VPC.

My plan was to issue the creation through the template, and then once the creation completes, I intended to use AWS Cli (from Jenkins) to accept the peering request and since this step requires me to know the vpc peering request id, then I wanted to output it using the "Outputs" : {} section of the template.

Can it be done?

2

2 Answers

1
votes

No it is not possible. CloudFormation only supports VPC Peering where peering is automatically approved (i.e. within the same account) or where you specify a role you can assume to automatically approve the peer.

1
votes

This AWS article describes the workaround

"This article describes a procedure that allows a requester_account to both request and approve the peering connection. To do so, the peer_account must create a cross-account role that the requester_account can use to accept the peering request..."