Guillaume Coré
2020-03-11 1d970fbaa4bd88c9d094d9587db59fdf9cd0239a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
= VPC Peering in AWS
 
A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them using private IPv4 addresses or IPv6 addresses. Instances in either VPC can communicate with each other as if they are within the same network. You can create a VPC peering connection between your own VPCs, or with a VPC in another AWS account. The VPCs can be in different regions (also known as an inter-region VPC peering connection).
 
Upstream documentation about VPC Peering: https://docs.aws.amazon.com/vpc/latest/peering/what-is-vpc-peering.html
 
 
== Role Input variables
 
|=================
| Variable | Usage
| `vpc_region`
| The region of the requester, for example `us-east-1`
| `peer_region`
| The other region to connect to, for example `eu-central-1`
| `vpc_private_zone` (optional)
| The name of the private zone of the first region. For example: `na.guid.internal.`
 
If you set a value for this variable, the *second* VPC will be associated to the private zone of first region. This way, second VPC can resolve names of the first private DNS zone.
| `peer_private_zone` (optional)
| The name of the private zone of the second region. For example: `emea.guid.internal.`
 
If you set a value for this variable, the *first* VPC will be associated to the private zone of *second* region. This way, first VPC can resolve names of the second private DNS zone.
| `project_tag`
| Name of the Cloudformation stacks to connect. Most of the time, this variable is already defined at top level in AgnosticD runs. Both stacks must have the same name.
|=================
 
 
== Examples
 
[source,yaml]
.Simple example.
----
- include_role:
    name: infra-ec2-vpc-peering
  vars:
    vpc_region: us-east-1
    peer_region: eu-central-1
    vpc_private_zone: na.guid.internal.
    peer_private_zone: emea.guid.internal.
----
 
[source,yaml]
.Complex example to connect every regions to each others.
----
- include_role:
    name: infra-ec2-vpc-peering
  vars:
    vpc_region: "{{ _region[0].region }}"
    peer_region: "{{ _region[1].region }}"
    vpc_private_zone: "{{ _region[0].name }}.{{ guid }}.internal."
    peer_private_zone: "{{ _region[1].name }}.{{ guid }}.internal."
  loop: "{{ target_regions | product(target_regions) | list }}"
  loop_control:
    loop_var: _region
  when:
    - _region[0].region != _region[1].region
    - _region[0].region < _region[1].region
----