Add security group to vFW, vLB
[demo.git] / heat / vFW / base_vfw.yaml
1 ##########################################################################
2 #
3 #==================LICENSE_START==========================================
4 #
5 #
6 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #        http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 #==================LICENSE_END============================================
20 #
21 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 #
23 ##########################################################################
24
25 heat_template_version: 2013-05-23
26
27 description: Heat template that deploys vFirewall demo app for ONAP
28
29 ##############
30 #            #
31 # PARAMETERS #
32 #            #
33 ##############
34
35 parameters:
36   vfw_image_name:
37     type: string
38     label: Image name or ID
39     description: Image to be used for compute instance
40   vfw_flavor_name:
41     type: string
42     label: Flavor
43     description: Type of instance (flavor) to be used
44   public_net_id:
45     type: string
46     label: Public network name or ID
47     description: Public network that enables remote connection to VNF
48   unprotected_private_net_id:
49     type: string
50     label: Unprotected private network name or ID
51     description: Private network that connects vPacketGenerator with vFirewall
52   protected_private_net_id:
53     type: string
54     label: Protected private network name or ID
55     description: Private network that connects vFirewall with vSink
56   onap_private_net_id:
57     type: string
58     label: ONAP management network name or ID
59     description: Private network that connects ONAP components and the VNF
60   onap_private_subnet_id:
61     type: string
62     label: ONAP management sub-network name or ID
63     description: Private sub-network that connects ONAP components and the VNF
64   unprotected_private_net_cidr:
65     type: string
66     label: Unprotected private network CIDR
67     description: The CIDR of the unprotected private network
68   protected_private_net_cidr:
69     type: string
70     label: Protected private network CIDR
71     description: The CIDR of the protected private network
72   onap_private_net_cidr:
73     type: string
74     label: ONAP private network CIDR
75     description: The CIDR of the protected private network
76   vfw_private_ip_0:
77     type: string
78     label: vFirewall private IP address towards the unprotected network
79     description: Private IP address that is assigned to the vFirewall to communicate with the vPacketGenerator
80   vfw_private_ip_1:
81     type: string
82     label: vFirewall private IP address towards the protected network
83     description: Private IP address that is assigned to the vFirewall to communicate with the vSink
84   vfw_private_ip_2:
85     type: string
86     label: vFirewall private IP address towards the ONAP management network
87     description: Private IP address that is assigned to the vFirewall to communicate with ONAP components
88   vpg_private_ip_0:
89     type: string
90     label: vPacketGenerator private IP address towards the unprotected network
91     description: Private IP address that is assigned to the vPacketGenerator to communicate with the vFirewall
92   vpg_private_ip_1:
93     type: string
94     label: vPacketGenerator private IP address towards the ONAP management network
95     description: Private IP address that is assigned to the vPacketGenerator to communicate with ONAP components
96   vsn_private_ip_0:
97     type: string
98     label: vSink private IP address towards the protected network
99     description: Private IP address that is assigned to the vSink to communicate with the vFirewall
100   vsn_private_ip_1:
101     type: string
102     label: vSink private IP address towards the ONAP management network
103     description: Private IP address that is assigned to the vSink to communicate with ONAP components
104   vfw_name_0:
105     type: string
106     label: vFirewall name
107     description: Name of the vFirewall
108   vpg_name_0:
109     type: string
110     label: vPacketGenerator name
111     description: Name of the vPacketGenerator
112   vsn_name_0:
113     type: string
114     label: vSink name
115     description: Name of the vSink
116   vnf_id:
117     type: string
118     label: VNF ID
119     description: The VNF ID is provided by ONAP
120   vf_module_id:
121     type: string
122     label: vFirewall module ID
123     description: The vFirewall Module ID is provided by ONAP
124   dcae_collector_ip:
125     type: string
126     label: DCAE collector IP address
127     description: IP address of the DCAE collector
128   dcae_collector_port:
129     type: string
130     label: DCAE collector port
131     description: Port of the DCAE collector
132   key_name:
133     type: string
134     label: Key pair name
135     description: Public/Private key pair name
136   pub_key:
137     type: string
138     label: Public key
139     description: Public key to be installed on the compute instance
140   repo_url_artifacts:
141     type: string
142     label: Repository URL
143     description: URL of the repository that hosts the demo packages
144   install_script_version:
145     type: string
146     label: Installation script version number
147     description: Version number of the scripts that install the vFW demo app
148   demo_artifacts_version:
149     type: string
150     label: Artifacts version used in demo vnfs
151     description: Artifacts (jar, tar.gz) version used in demo vnfs
152   nexus_artifact_repo:
153     type: string
154     description: Root URL for the Nexus repository for Maven artifacts.
155     default: "https://nexus.onap.org"
156   cloud_env:
157     type: string
158     label: Cloud environment
159     description: Cloud environment (e.g., openstack, rackspace)
160   sec_group:
161     type: string
162     description: ONAP Security Group
163
164 #############
165 #           #
166 # RESOURCES #
167 #           #
168 #############
169
170 resources:
171   random-str:
172     type: OS::Heat::RandomString
173     properties:
174       length: 4
175
176   my_keypair:
177     type: OS::Nova::KeyPair
178     properties:
179       name:
180         str_replace:
181           template: base_rand
182           params:
183             base: { get_param: key_name }
184             rand: { get_resource: random-str }
185       public_key: { get_param: pub_key }
186       save_private_key: false
187
188   unprotected_private_network:
189     type: OS::Neutron::Net
190     properties:
191       name: { get_param: unprotected_private_net_id }
192
193   protected_private_network:
194     type: OS::Neutron::Net
195     properties:
196       name: { get_param: protected_private_net_id }
197
198   unprotected_private_subnet:
199     type: OS::Neutron::Subnet
200     properties:
201       network_id: { get_resource: unprotected_private_network }
202       cidr: { get_param: unprotected_private_net_cidr }
203
204   protected_private_subnet:
205     type: OS::Neutron::Subnet
206     properties:
207       network_id: { get_resource: protected_private_network }
208       cidr: { get_param: protected_private_net_cidr }
209
210   # Virtual Firewall instantiation
211   vfw_private_0_port:
212     type: OS::Neutron::Port
213     properties:
214       network: { get_resource: unprotected_private_network }
215       fixed_ips: [{"subnet": { get_resource: unprotected_private_subnet }, "ip_address": { get_param: vfw_private_ip_0 }}]
216       security_groups:
217       - { get_param: sec_group }
218
219   vfw_private_1_port:
220     type: OS::Neutron::Port
221     properties:
222       allowed_address_pairs: [{ "ip_address": { get_param: vpg_private_ip_0 }}]
223       network: { get_resource: protected_private_network }
224       fixed_ips: [{"subnet": { get_resource: protected_private_subnet }, "ip_address": { get_param: vfw_private_ip_1 }}]
225       security_groups:
226       - { get_param: sec_group }
227
228   vfw_private_2_port:
229     type: OS::Neutron::Port
230     properties:
231       network: { get_param: onap_private_net_id }
232       fixed_ips: [{"subnet": { get_param: onap_private_subnet_id }, "ip_address": { get_param: vfw_private_ip_2 }}]
233       security_groups:
234       - { get_param: sec_group }
235
236   vfw_0:
237     type: OS::Nova::Server
238     properties:
239       image: { get_param: vfw_image_name }
240       flavor: { get_param: vfw_flavor_name }
241       name: { get_param: vfw_name_0 }
242       key_name: { get_resource: my_keypair }
243       networks:
244         - network: { get_param: public_net_id }
245         - port: { get_resource: vfw_private_0_port }
246         - port: { get_resource: vfw_private_1_port }
247         - port: { get_resource: vfw_private_2_port }
248       metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }}
249       user_data_format: RAW
250       user_data:
251         str_replace:
252           params:
253             __dcae_collector_ip__ : { get_param: dcae_collector_ip }
254             __dcae_collector_port__ : { get_param: dcae_collector_port }
255             __repo_url_artifacts__ : { get_param: repo_url_artifacts }
256             __demo_artifacts_version__ : { get_param: demo_artifacts_version }
257             __install_script_version__ : { get_param: install_script_version }
258             __vfw_private_ip_0__ : { get_param: vfw_private_ip_0 }
259             __vfw_private_ip_1__ : { get_param: vfw_private_ip_1 }
260             __vfw_private_ip_2__ : { get_param: vfw_private_ip_2 }
261             __unprotected_private_net_cidr__ : { get_param: unprotected_private_net_cidr }
262             __protected_private_net_cidr__ : { get_param: protected_private_net_cidr }
263             __onap_private_net_cidr__ : { get_param: onap_private_net_cidr }
264             __cloud_env__ : { get_param: cloud_env }
265             __nexus_artifact_repo__: { get_param: nexus_artifact_repo }
266           template: |
267             #!/bin/bash
268
269             # Create configuration files
270             mkdir /opt/config
271             echo "__dcae_collector_ip__" > /opt/config/dcae_collector_ip.txt
272             echo "__dcae_collector_port__" > /opt/config/dcae_collector_port.txt
273             echo "__repo_url_artifacts__" > /opt/config/repo_url_artifacts.txt
274             echo "__demo_artifacts_version__" > /opt/config/demo_artifacts_version.txt
275             echo "__install_script_version__" > /opt/config/install_script_version.txt
276             echo "__vfw_private_ip_0__" > /opt/config/vfw_private_ip_0.txt
277             echo "__vfw_private_ip_1__" > /opt/config/vfw_private_ip_1.txt
278             echo "__vfw_private_ip_2__" > /opt/config/vfw_private_ip_2.txt
279             echo "__unprotected_private_net_cidr__" > /opt/config/unprotected_private_net_cidr.txt
280             echo "__protected_private_net_cidr__" > /opt/config/protected_private_net_cidr.txt
281             echo "__onap_private_net_cidr__" > /opt/config/onap_private_net_cidr.txt
282             echo "__cloud_env__" > /opt/config/cloud_env.txt
283             echo "__nexus_artifact_repo__" > /opt/config/nexus_artifact_repo.txt
284
285             # Download and run install script
286             apt-get -y install unzip
287             if [[ "__install_script_version__" =~ "SNAPSHOT" ]]; then REPO=snapshots; else REPO=releases; fi
288             curl -k -L "__nexus_artifact_repo__/service/local/artifact/maven/redirect?r=${REPO}&g=org.onap.demo.vnf.vfw&a=vfw-scripts&e=zip&v=__install_script_version__" -o /opt/vfw-scripts-__install_script_version__.zip
289             unzip -j /opt/vfw-scripts-__install_script_version__.zip -d /opt v_firewall_install.sh
290             cd /opt
291             chmod +x v_firewall_install.sh
292             ./v_firewall_install.sh
293
294
295   # Virtual Packet Generator instantiation
296   vpg_private_0_port:
297     type: OS::Neutron::Port
298     properties:
299       network: { get_resource: unprotected_private_network }
300       fixed_ips: [{"subnet": { get_resource: unprotected_private_subnet }, "ip_address": { get_param: vpg_private_ip_0 }}]
301       security_groups:
302       - { get_param: sec_group }
303
304   vpg_private_1_port:
305     type: OS::Neutron::Port
306     properties:
307       network: { get_param: onap_private_net_id }
308       fixed_ips: [{"subnet": { get_param: onap_private_subnet_id }, "ip_address": { get_param: vpg_private_ip_1 }}]
309       security_groups:
310       - { get_param: sec_group }
311
312   vpg_0:
313     type: OS::Nova::Server
314     properties:
315       image: { get_param: vfw_image_name }
316       flavor: { get_param: vfw_flavor_name }
317       name: { get_param: vpg_name_0 }
318       key_name: { get_resource: my_keypair }
319       networks:
320         - network: { get_param: public_net_id }
321         - port: { get_resource: vpg_private_0_port }
322         - port: { get_resource: vpg_private_1_port }
323       metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }}
324       user_data_format: RAW
325       user_data:
326         str_replace:
327           params:
328             __fw_ipaddr__: { get_param: vfw_private_ip_0 }
329             __protected_net_cidr__: { get_param: protected_private_net_cidr }
330             __sink_ipaddr__: { get_param: vsn_private_ip_0 }
331             __repo_url_artifacts__ : { get_param: repo_url_artifacts }
332             __demo_artifacts_version__ : { get_param: demo_artifacts_version }
333             __install_script_version__ : { get_param: install_script_version }
334             __vpg_private_ip_0__ : { get_param: vpg_private_ip_0 }
335             __vpg_private_ip_1__ : { get_param: vpg_private_ip_1 }
336             __unprotected_private_net_cidr__ : { get_param: unprotected_private_net_cidr }
337             __onap_private_net_cidr__ : { get_param: onap_private_net_cidr }
338             __cloud_env__ : { get_param: cloud_env }
339             __nexus_artifact_repo__: { get_param: nexus_artifact_repo }
340           template: |
341             #!/bin/bash
342
343             # Create configuration files
344             mkdir /opt/config
345             echo "__fw_ipaddr__" > /opt/config/fw_ipaddr.txt
346             echo "__protected_net_cidr__" > /opt/config/protected_net_cidr.txt
347             echo "__sink_ipaddr__" > /opt/config/sink_ipaddr.txt
348             echo "__repo_url_artifacts__" > /opt/config/repo_url_artifacts.txt
349             echo "__demo_artifacts_version__" > /opt/config/demo_artifacts_version.txt
350             echo "__install_script_version__" > /opt/config/install_script_version.txt
351             echo "__vpg_private_ip_0__" > /opt/config/vpg_private_ip_0.txt
352             echo "__vpg_private_ip_1__" > /opt/config/vpg_private_ip_1.txt
353             echo "__unprotected_private_net_cidr__" > /opt/config/unprotected_private_net_cidr.txt
354             echo "__onap_private_net_cidr__" > /opt/config/onap_private_net_cidr.txt
355             echo "__cloud_env__" > /opt/config/cloud_env.txt
356             echo "__nexus_artifact_repo__" > /opt/config/nexus_artifact_repo.txt
357
358             # Download and run install script
359             apt-get -y install unzip
360             if [[ "__install_script_version__" =~ "SNAPSHOT" ]]; then REPO=snapshots; else REPO=releases; fi
361             curl -k -L "__nexus_artifact_repo__/service/local/artifact/maven/redirect?r=${REPO}&g=org.onap.demo.vnf.vfw&a=vfw-scripts&e=zip&v=__install_script_version__" -o /opt/vfw-scripts-__install_script_version__.zip
362             unzip -j /opt/vfw-scripts-__install_script_version__.zip -d /opt v_packetgen_install.sh
363             cd /opt
364             chmod +x v_packetgen_install.sh
365             ./v_packetgen_install.sh
366
367
368   # Virtual Sink instantiation
369   vsn_private_0_port:
370     type: OS::Neutron::Port
371     properties:
372       network: { get_resource: protected_private_network }
373       fixed_ips: [{"subnet": { get_resource: protected_private_subnet }, "ip_address": { get_param: vsn_private_ip_0 }}]
374       security_groups:
375       - { get_param: sec_group }
376
377   vsn_private_1_port:
378     type: OS::Neutron::Port
379     properties:
380       network: { get_param: onap_private_net_id }
381       fixed_ips: [{"subnet": { get_param: onap_private_subnet_id }, "ip_address": { get_param: vsn_private_ip_1 }}]
382       security_groups:
383       - { get_param: sec_group }
384
385   vsn_0:
386     type: OS::Nova::Server
387     properties:
388       image: { get_param: vfw_image_name }
389       flavor: { get_param: vfw_flavor_name }
390       name: { get_param: vsn_name_0 }
391       key_name: { get_resource: my_keypair }
392       networks:
393         - network: { get_param: public_net_id }
394         - port: { get_resource: vsn_private_0_port }
395         - port: { get_resource: vsn_private_1_port }
396       metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }}
397       user_data_format: RAW
398       user_data:
399         str_replace:
400           params:
401             __protected_net_gw__: { get_param: vfw_private_ip_1 }
402             __unprotected_net__: { get_param: unprotected_private_net_cidr }
403             __repo_url_artifacts__ : { get_param: repo_url_artifacts }
404             __install_script_version__ : { get_param: install_script_version }
405             __vsn_private_ip_0__ : { get_param: vsn_private_ip_0 }
406             __vsn_private_ip_1__ : { get_param: vsn_private_ip_1 }
407             __protected_private_net_cidr__ : { get_param: protected_private_net_cidr }
408             __onap_private_net_cidr__ : { get_param: onap_private_net_cidr }
409             __cloud_env__ : { get_param: cloud_env }
410             __nexus_artifact_repo__: { get_param: nexus_artifact_repo }
411           template: |
412             #!/bin/bash
413
414             # Create configuration files
415             mkdir /opt/config
416             echo "__protected_net_gw__" > /opt/config/protected_net_gw.txt
417             echo "__unprotected_net__" > /opt/config/unprotected_net.txt
418             echo "__install_script_version__" > /opt/config/install_script_version.txt
419             echo "__vsn_private_ip_0__" > /opt/config/vsn_private_ip_0.txt
420             echo "__vsn_private_ip_1__" > /opt/config/vsn_private_ip_1.txt
421             echo "__protected_private_net_cidr__" > /opt/config/protected_private_net_cidr.txt
422             echo "__onap_private_net_cidr__" > /opt/config/onap_private_net_cidr.txt
423             echo "__cloud_env__" > /opt/config/cloud_env.txt
424             echo "__nexus_artifact_repo__" > /opt/config/nexus_artifact_repo.txt
425
426             # Download and run install script
427             apt-get -y install unzip
428             if [[ "__install_script_version__" =~ "SNAPSHOT" ]]; then REPO=snapshots; else REPO=releases; fi
429             curl -k -L "__nexus_artifact_repo__/service/local/artifact/maven/redirect?r=${REPO}&g=org.onap.demo.vnf.vfw&a=vfw-scripts&e=zip&v=__install_script_version__" -o /opt/vfw-scripts-__install_script_version__.zip
430             unzip -j /opt/vfw-scripts-__install_script_version__.zip -d /opt v_sink_install.sh
431             cd /opt
432             chmod +x v_sink_install.sh
433             ./v_sink_install.sh