Allow a way to pass per-instance data to ResourceGroup instances

Registered by Steve Lipinski

Currently, it seems that instances of resources created by a ResourceGroup must be identical.

If there was a way to pass per-instance data that could be used when each resource is instantiated, that could be very helpful.
This could be helpful regarding these other blueprints also:
https://blueprints.launchpad.net/heat/+spec/resource-group-index
https://blueprints.launchpad.net/heat/+spec/override-resource-name-in-resource-group

One idea would be to be able to pass a list of parameters for a resource.

For example, a Group of Nova Servers:
resources:
  NonPilots:
    type: OS::Heat::ResourceGroup
    properties:
      count: 3
      resource_def:
        type: OS::Nova::Server
        properties:
            name: [ 'server1', 'server2', 'server3' ]
            availability_zone: [ 'zone1', 'zone2' ]
            image: some_image
            flavor: some_flavor
            ...

When the ResourceGroup spins up the instances, it would do so as follows:
instance_1:
  properties:
    name: server1
    availability_zone: zone1
    image: some_image
    flavor: some_flavor

instance_2:
  properties:
    name: server2
    availability_zone: zone2
    image: some_image
    flavor: some_flavor

instance_3:
  properties:
    name: server3
    availability_zone: zone1
    image: some_image
    flavor: some_flavor

The only catch would be that if a resource required a list as a parameter, that would have to be known beforehand - e.g., to pass a list of items through as a list, or to loop on each list item and pass as individual item. A list of lists could be used for a resource that requires a list parameter.

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
Steve Lipinski
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

Was able to prototype this with the following change:

--- resource_group.py.orig 2014-03-25 16:22:59.370000115 -0400
+++ resource_group.py 2014-03-25 16:18:13.603000518 -0400
@@ -145,14 +145,22 @@
     def _assemble_nested(self, count, include_all=False):
         child_template = copy.deepcopy(template_template)
         resource_def = self.properties[self.RESOURCE_DEF]
+
         if resource_def[self.RESOURCE_DEF_PROPERTIES] is None:
             resource_def[self.RESOURCE_DEF_PROPERTIES] = {}
         if not include_all:
             resource_def_props = resource_def[self.RESOURCE_DEF_PROPERTIES]
             clean = dict((k, v) for k, v in resource_def_props.items() if v)
             resource_def[self.RESOURCE_DEF_PROPERTIES] = clean
- resources = dict((str(k), resource_def)
+
+ resources = dict((str(k), copy.deepcopy(resource_def))
                          for k in range(count))
+
+ for i in range(count):
+ for k,v in resources[str(i)][self.RESOURCE_DEF_PROPERTIES].items():
+ if isinstance(v, list):
+ resources[str(i)][self.RESOURCE_DEF_PROPERTIES][k] = v[i % len(v)]
+
         child_template['resources'] = resources
         return child_template

Again, one shortcoming of this is that if one of the template parameters is supposed to be a list, this will break that. I'm not sure of how to look up a resource template to determine if the property is defined as a list.

This provides a lot of flexibility to ResourceGroups from what I have found.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.