https://pulumi.com logo
c

clean-advantage-13612

09/03/2023, 10:29 PM
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

alert-nightfall-64120

09/03/2023, 11:13 PM
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

clean-advantage-13612

09/03/2023, 11:34 PM
Cheers Shadi, I’ll take a look 🙏
a

alert-nightfall-64120

09/03/2023, 11:41 PM
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

billowy-army-68599

09/03/2023, 11:46 PM
generally the easiest way is to
ctx.Export
it
a

alert-nightfall-64120

09/03/2023, 11:47 PM
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

clean-advantage-13612

09/04/2023, 12:34 AM
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 🙏