[Heat] Reg accessing variables of resource group heat api

Harald Jensås hjensas at redhat.com
Mon Feb 11 14:16:53 UTC 2019


On Wed, 2019-02-06 at 06:12 +0000, NANTHINI A A wrote:
> Hi ,
>     We are developing heat templates for our vnf deployment .It
> includes multiple resources .We want to repeat the resource and hence
> used the api RESOURCE GROUP .
>     Attached are the templates which we used
>  
> Set1.yaml -> has the resources we want to repeat
> Setrepeat.yaml -> has the resource group api with count .
>   
>      We want to access the variables of resource in set1.yaml while
> repeating it with count .Eg . port name ,port fixed ip address we
> want to change in each set .
>    Please let us know how we can have a variable with each repeated
> resource .
>  

Sounds like you want to use the index_var variable[1] to prefix/suffix
reource names?

 I.e in set1.yaml you can use:

   name: 
    list_join:
      - '_'
      - {get_param: 'OS::stack_name'}
      - %index%
      - <resource_name>


The example should resulting in something like:
  stack_0_Network3, stack_0_Subnet3
  stack_1_Network0, stack_1_Subnet0
  [ ... ]


If you want to be more advanced you could use a list parameter in the
set1.yaml template, and have each list entry contain a dictionaly of
each resource name. The %index% variable would then be used to pick the
correct entry from the list.


parameters:
  resource_name_map:
    - network1: foo_custom_name_net1
      network2: foo_custom_name_net2
    - network1: bar_custom_name_net1
      network2: bar_custom_name_net2    - 

resources:
  neutron_Network_1:
    type: OS::Neutron::Net
    properties:
      name: {get_param: [resource_name_map, %index%, network1]}
  neutron_Network_2:
    type: OS::Neutron::Net
    properties:
      name: {get_param: [resource_name_map, %index%, network2]}


 %index% is the "count" picking the 'foo' entries when %index% is 0,
and 'bar' entries when %index% is 1 and so on.





[1] 
https://docs.openstack.org/heat/latest/template_guide/openstack.html#OS::Heat::ResourceGroup-props-opt






More information about the openstack-discuss mailing list