https://pulumi.com logo
#golang
Title
q

quiet-restaurant-29133

11/26/2020, 5:04 AM
is it possible to convert
pulumi.StringOutout
to a
string
?, the
applyString
is just a transformer. I have templates that need outputs from a pulumi
resource
output that takes in a
string
only
c

clever-byte-21551

11/26/2020, 6:40 AM
Did you try and use
pulumi.Sprintf
?
q

quiet-restaurant-29133

11/26/2020, 6:41 AM
it also returns
pulumi.StringOutput
i

important-appointment-55126

11/27/2020, 4:54 PM
I wrote some helper code that takes outputs, uses
ApplyT
to wait for them to resolve and then renders a Go template from that… i’ll clean it up a bit and push it to Github
i then can do things like this:
Copy code
// Grant Cloudfront access to the content bucket
		_, err = s3.NewBucketPolicy(ctx, "staticSitePolicy-"+host, &s3.BucketPolicyArgs{
			Bucket: bucket.Bucket.Bucket,
			Policy: pulutil.JSONTemplate(map[string]interface{}{
				"BucketARN":   bucket.BucketArn,
				"IdentityARN": identity.IamArn,
			}, `{
						"Version": "2012-10-17",
						"Id": "PolicyForCloudFrontPrivateContent",
						"Statement": [
							{
								"Effect": "Allow",
								"Principal": {
									"AWS": "{{ .IdentityARN }}"
								},
								"Action": "s3:GetObject",
								"Resource": "{{ .BucketARN }}/*"
							}
						]
					}`),
		})
the template there is just a normal Go template..
JSONTemplate
just does an additional check at the end to make sure the output is valid JSON before handing it off to Pulumi; get more useful error messages that way
q

quiet-restaurant-29133

11/27/2020, 5:25 PM
Thanks @important-appointment-55126 🤞
meanwhile I can try
ApplyT
i

important-appointment-55126

11/29/2020, 4:21 PM
Uploaded my code with an example that i hope is useful: https://pkg.go.dev/github.com/gwatts/pulutil/template/#example-NewJSON
❤️ 1
3 Views