https://pulumi.com logo
Title
l

lemon-intern-77136

10/21/2022, 7:51 PM
I’m trying to create a YAML file that is made of regular python and Output objects. I’m currently doing it like this:
d = {}
d['user'] = ['default'] + [aDictWithAnOutputInstance] + [anotherDictWithOutputInstances]
d['other_stuff'] = ...
d['more_things'] = {'more_things_1': againAnOutputInstance, 'more_things_2': 'regular string'}
y = yaml.dump(d, Dumper=yaml.Dumper)
Any ideas how to make this work? The
.apply
and
.concat
idioms don’t seem to work here…
My first thought is to basically move the entire thing into a function that I call with apply… but the function doesn’t necessarily know where the Output objects are (as they could be inside dictionaries that are passed to that function), so there would be a lot of bookkeeping there.
Another thought was to create a new YAML Dumper, but the docs on that are pretty poor, so I’m not sure if that is the best option.
(this is also relevant when using Jinja templates)
b

billowy-army-68599

10/21/2022, 9:00 PM
you have to do it inside an
apply
if you have multiple output objects, use
output.all
what exactly are you dumping to YAML?
l

lemon-intern-77136

10/21/2022, 10:00 PM
I’m trying to create a custom userdata file for use with cloudinit
Can I use
Output.format
?
It appears to be in the docs: https://www.pulumi.com/docs/reference/pkg/python/pulumi/#pulumi.Output.format … but I’m getting
AttributeError: type object 'Output' has no attribute 'format'
when I try and use it.
So, I ultimately ended up writing a function to replace everything in a container (dict/dataclass/list/etc) that is a Output object with a uid and then pass the container through the yaml/jinja templating process, and then use apply and .format to re-enter those items.
But this is really awkward.
Putting secrets or computed values into config files (like yaml or jinja templates) I would think is pretty fundamental… but right now it is pretty broken.
b

billowy-army-68599

10/21/2022, 11:12 PM
this is a really common practice, I’m not sure where you think it’s broken. here’s an example of interpolating an output inside a JSON string which should be applicable to your user case: https://github.com/jaxxstorm/pulumi-examples/blob/55a9c8e4c5a058f1a1017b4b74d1a5c26881aee6/python/aws/s3_bucket_cloudflare/__main__.py#L31-L72 We also have the cloudinit package: https://www.pulumi.com/registry/packages/cloudinit/ if you can share exactly what you’re trying to do, I can try repro on Monday
l

lemon-intern-77136

10/24/2022, 3:29 PM
I’m sorry, I was wrong. I was just frustrated by the time I had spent on this whole process. Thanks for that link.