polite-portugal-60022
04/08/2020, 3:22 PM# Note, I'm abstracting a lot of what we do with simple wrapper classes since 99% of our instances will follow the same patterns. The second reason is to easily load/write templates automagically from provided inputs to script(s)
for resource_objs in template_objs:
# Build all non-disk/non-instance objects first in case there are dependencies later
objs = list( filter( lambda obj: not 'disk' in obj[1].lower() and not 'instance' in obj[1].lower(), resource_objs) )
for obj in objs:
obj[0].build()
# Extract and build all "disk" objects
disk_objs = list( filter( lambda obj: 'disk' in obj[1].lower(), resource_objs) )
for disk_obj in disk_objs:
disk_obj[0].build()
# Extract instance object
instance_obj = list( filter( lambda obj: 'instance' in obj[1].lower(), resource_objs) ).pop()
# Some kind of bug?, need to filter out pulumi.output.Output objects from attached_disks attr
# else, will try to add ALL previously created disks. Not just the disks created in this iteration!!!
instance_obj[0].attached_disks = list( filter(lambda disk: not isinstance(disk, pulumi.output.Output),
instance_obj[0].attached_disks) )
# Append disks to be attached_disks attr and build instance
for disk_obj in disk_objs:
instance_obj[0].attached_disks.append( { 'device_name': disk_obj[0].result.name,
'source': disk_obj[0].result.name } )
instance_obj[0].build()