forked from GoogleCloudPlatform/professional-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcp-vpn.jinja
130 lines (120 loc) · 3.63 KB
/
gcp-vpn.jinja
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{#
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#}
{% set id = env["deployment"] %}
{% set region = properties["region"] %}
{% set bgp = true if properties["asn"] else false %}
resources:
- name: {{ id }}
type: compute.v1.targetVpnGateway
properties:
network: {{ properties["network"] }}
region: {{ region }}
{% if bgp %}
- name: {{ id }}-router
type: compute.v1.router
properties:
network: {{ properties["network"] }}
region: {{ region }}
bgp:
asn: {{ properties["asn"] }}
{% endif %}
- name: {{ id }}-rule-esp
type: compute.v1.forwardingRule
properties:
IPAddress: {{ properties["address"] }}
IPProtocol: ESP
region: {{ region }}
target: $(ref.{{ id }}.selfLink)
- name: {{ id }}-rule-udp500
type: compute.v1.forwardingRule
properties:
IPAddress: {{ properties["address"] }}
IPProtocol: UDP
portRange: 500
region: {{ region }}
target: $(ref.{{ id }}.selfLink)
- name: {{ id }}-rule-udp4500
type: compute.v1.forwardingRule
properties:
IPAddress: {{ properties["address"] }}
IPProtocol: UDP
portRange: 4500
region: {{ region}}
target: $(ref.{{ id }}.selfLink)
{% for i in properties["tunnels"] %}
{% set oindex = loop.index %}
- name: {{ id }}-tunnel{{oindex}}
type: compute.v1.vpnTunnel
properties:
peerIp: {{ i["peerIp"] }}
region: {{ region }}
sharedSecret: {{ i["secret"] }}
# AWS supports only ike 1 https://forums.aws.amazon.com/thread.jspa?messageID=777039
ikeVersion: 1
targetVpnGateway: $(ref.{{ id }}.selfLink)
{% if bgp %}
router: $(ref.{{ id }}-router.selfLink)
{% endif %}
{% if "localTrafficSelector" in i%}
localTrafficSelector:
{% for j in i["localTrafficSelector"] %}
- {{ j }}
{% endfor %}
{% endif %}
{% if "remoteTrafficSelector" in i%}
remoteTrafficSelector:
{% for j in i["remoteTrafficSelector"] %}
- {{ j }}
{% endfor %}
{% endif %}
metadata:
dependsOn:
- {{ id }}-rule-esp
- {{ id }}-rule-udp500
- {{ id }}-rule-udp4500
{% if "remoteTrafficSelector" in i%}
{% for j in i["remoteTrafficSelector"] %}
- name: {{ id }}-tunnel{{oindex}}-route{{loop.index}}
type: compute.v1.route
properties:
network: {{ properties["network"] }}
destRange: {{ j }}
nextHopVpnTunnel: $(ref.{{ id }}-tunnel{{oindex}}.selfLink)
priority: 1000
tags: []
{% endfor %}
{% endif %}
{% endfor %}
{% if bgp %}
- name: {{ id }}-patch-router
action: gcp-types/compute-v1:compute.routers.patch
properties:
router: {{ id }}-router
region: {{ region }}
project: {{ env["project"] }}
name: {{ id }}-router
bgpPeers:
{% for i in properties["tunnels"] %}
- interfaceName: {{ id }}-int{{loop.index}}
ipAddress: {{ i["bgpIpAddress"] }}
name: {{ id }}-peer{{loop.index}}
peerAsn: {{ i["peerAsn"] }}
peerIpAddress: {{ i["peerBgpIpAddress"] }}
{% endfor %}
interfaces:
{% for i in properties["tunnels"] %}
- ipRange: {{ i["bgpIpAddress"] }}/30
linkedVpnTunnel: $(ref.{{ id }}-tunnel{{loop.index}}.selfLink)
name: {{ id }}-int{{loop.index}}
{% endfor %}
{% endif %}