Does anyone know an easy way to print out a `pulum...
# general
c
Does anyone know an easy way to print out a
pulumi.MapOutput
object? Something similar to
pprint
from Python would be ideal, but I’ll take anything. Context: I’m trying to do this in Go.
a
Completely untested- but try this?
Copy code
test := pulumi.Map{
		"hello": pulumi.String("world"),
	}
	test.ToMapOutput().ApplyT(func(m map[string]interface{}) {
		b, err := json.MarshalIndent(m, "", "  ")
		if err != nil {
			return
		}
		<http://ctx.Log.Info|ctx.Log.Info>(string(b), &pulumi.LogArgs{Resource: component})
	})
c
Cheers Shadi, I’ll take a look 🙏
a
I just tried to test it and that did not work
Not sure what the value type is supposed to be for the map in ApplyT
b
generally the easiest way is to
ctx.Export
it
a
Actually this worked fine:
Copy code
test := pulumi.Map{
		"hello": pulumi.String("world"),
	}
	test.ToMapOutput().ApplyT(func(m map[string]interface{}) error {
		b, err := json.MarshalIndent(m, "", "  ")
		if err != nil {
			return err
		}
		<http://ctx.Log.Info|ctx.Log.Info>(string(b), &pulumi.LogArgs{Resource: component})
		return nil
	})
Just had to return a value from ApplyT
The log output when running pulumi preview:
Copy code
{
  "hello": "world"
}
c
generally the easiest way is to
ctx.Export
it
This ended up giving me exactly what I needed - definitely the easiest way to do it imo
Thanks both for your assistance 🙏