Tomer
Tomer

Reputation: 21

OpenStack - how to iterate comma_delimited_list using %index% from OS::Heat::ResourceGroup?

I have a comma_delimited_list which represents list of fixed IPs and in my OS::Heat::ResourceGroup I want that each node will get one fixed ip based on his current index.

I have the following heat template (I've pasted only the relevant):

my_fixed_ips:
    type: comma_delimited_list

resources:
  MyResource:
    type: OS::Heat::ResourceGroup
    properties:
      count: { get_param: my_node_count }
      resource_def:
        type: MyTemplate.yaml
        properties:
          fixed_ip: { get_param: [ my_fixed_ips, %index% ] }
          name: myName%index%

when i run the command:

openstack stack create TomerProtected -e Environment.env -t Template.yaml -f yaml

I'm getting the error: found character '%' that cannot start any token

I've tried to set index_var to something else (index and not %index%) but still i can not get any specific value from the comma_delimited_list.

my question is - how to iterate comma_delimited_list using %index% from OS::Heat::ResourceGroup?

any ideas?

UPDATE:

I've found a solution by myself but it doesn't pleases me:

Ive changed index_var to: index Passed the comma_delimited_list and the current index from this template to MyTemplate.yaml. From MyTemplate.yaml I could get specific value from the comma_delimited_list:

fixed_ips: [ { "ip_address": { get_param: [ my_fixed_ips, get_param: index ] } } ]

but there most be a way to do this from OS::Heat::ResourceGroup

Upvotes: 2

Views: 3306

Answers (1)

Soleco
Soleco

Reputation: 191

Try to use '%index%' insetad of %index%. An example what worked for me:

heat_template_version: rocky
parameters:
  my_node_count:
    type: number
    default: 2
  my_fixed_ips:
    type: comma_delimited_list
    default: [10.2.0.1, 10.2.0.2]
  my_name_param:
    type: string
    default: "myname"

resources:
  MyResource:
    type: OS::Heat::ResourceGroup
    properties:
      count: { get_param: my_node_count }
      resource_def:
        type: MyTemplate.yaml
        properties:
          fixed_ip: { get_param: [ my_fixed_ips, '%index%' ] }
          name:
            list_join:
              - ''
              - [ { get_param: my_name_param } , '%index%' ]

Upvotes: 1

Related Questions