Hey all, Using gcp provider/python. I've got a wei...
# general
Hey all, Using gcp provider/python. I've got a weird thing going on with outputters where they seem to get stacked on each other. I'm doing a simple iteration over resources I want to be built. I'm creating disks and assigning them as dependencies to an instance's attached_disks. Strangely, upon the second iteration, when I attach new disks to the attached_disks list, the outputters from the previous iteration are already there, even though I've constructed a brand new object. In order to alleviate this problem, I'm first filtering the list of output objects before appending the new ones. Example below:
# 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:
# 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:
# 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 } )