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
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
#jinja2: lstrip_blocks: "True"
---
heat_template_version: 2018-03-02
 
description: Nested HOT for creating instances, ports, & floating IPs. This template relies is called by a top level template that is resposible for common resources such as network, router, etc.
 
parameters:
 
  network_private:
    type: string
    description: The name of the network created by the top level HOT.
 
  security_groups:
    type: json
    description: The list of security groups created by the top level HOT. Passed as a list or string?
 
  provider_network:
    type: string
    description: The provider network where floating IPs will be provisioned from.
 
  instance_name:
    type: string
    description: The instance name is passed from the top level HOT. It should be appended with an index value if there will be more than one of this type of instance deployed.
 
  instance_image:
    type: string
 
  instance_flavor:
    type: string
 
  instance_metadata:
    type: json
    description: Metadata in OpenStack is the equivilent to tags in a cloud provider such as AWS
 
  instance_fip:
    type: boolean
    description: When passed from top level HOT, this will determine whether the FIP and FIP association resources are created based on condition.
 
  volume_size:
    type: number
    description: The size in GB of the volume being created from an image.
 
  key_name:
    type: string
    description: The SSH key that will be added to the instance.
 
{% for instance in instances %}
{% if instance.volumes is defined %}
{% for volume in instance.volumes %}
  {% set loopvolume = loop %}
  {% for myinstanceindex in range(instance.count|int) %}
    {% set iname = instance.name if instance.count == 1 else instance.name + loop.index0 %}
    {% set vname = ["volume", iname, loopvolume.index] | join('_') %}
  add_vol_{{ vname }}:
    type: string
  {% endfor %}
{% endfor %}
{% endif %}
{% endfor %}
 
conditions:
 
  create_fip:
    get_param: instance_fip
 
resources:
 
  port:
    type: OS::Neutron::Port
    properties:
      network: { get_param: network_private }
      security_groups: { get_param: security_groups }
 
  fip:
    type: OS::Neutron::FloatingIP
    condition: create_fip
    properties:
      floating_network: { get_param: provider_network }
 
  fip_association:
    type: OS::Neutron::FloatingIPAssociation
    condition: create_fip
    properties:
      floatingip_id: { get_resource: fip }
      port_id: { get_resource: port }
 
  instance:
    type: OS::Nova::Server
    properties:
      name: { get_param: instance_name }
      flavor: { get_param: instance_flavor }
      key_name: { get_param: key_name }
      block_device_mapping_v2:
        - image: { get_param: instance_image }
          delete_on_termination: true
          volume_size: { get_param: volume_size }
          boot_index: 0
{% for instance in instances %}
{% if instance.volumes is defined %}
{% for volume in instance.volumes %}
  {% set loopvolume = loop %}
  {% for myinstanceindex in range(instance.count|int) %}
    {% set iname = instance.name if instance.count == 1 else instance.name + loop.index0 %}
    {% set vname = ["volume", iname, loopvolume.index] | join('_') %}
        - volume_id: { get_param: add_vol_{{ vname }} }
          boot_index: -1
  {% endfor %}
{% endfor %}
{% endif %}
{% endfor %}
      user_data: |
        #cloud-config
        ssh_authorized_keys: {{ all_ssh_authorized_keys | to_json }}
      user_data_format: RAW
      networks:
        - port: { get_resource: port }
      metadata:
        get_param: instance_metadata