https://pulumi.com logo
Title
f

flat-chef-39475

04/06/2021, 11:45 PM
So I got the image src working by using relative addressing which is a workaround. The interpolate still does not work and I don't really understand why. I suspect it is an async issue with promises.
l

little-cartoon-10569

04/06/2021, 11:48 PM
You have (had?) this code, which is the source of the issue:
const imgUrl = pulumi.interpolate`http://${bucket.bucketEndpoint}/roo.jpg`
const html = htmlTemplate.replace("{object}", imgUrl)
fs.writeFileSync("index.html", html)
imgUrl is an
Output<string>
, which you are then using as a
string
.
f

flat-chef-39475

04/06/2021, 11:50 PM
Hi tenwit, I thought pulumi.interpolate would return a string?
l

little-cartoon-10569

04/06/2021, 11:51 PM
As the error message says, you need to do this inside an apply, thus:
const indexObject = new aws.s3.BucketObject("index.html", {
    bucket,
    content: pulumi.all([htmlTemplate, bucket.bucketEndpoint]).apply(([template, endpoint]) => {
   // Stuff that builds your HTML
    });,
    acl: "public-read",
    contentType: "text/html"
})
No, interpolate returns an Output<string>.
It is not possible to access the contents of an Output from the "top level" code. It must be within an apply.
f

flat-chef-39475

04/06/2021, 11:52 PM
ok... that gives me a focus. Thanks mate.
r

red-match-15116

04/06/2021, 11:52 PM
@little-cartoon-10569 is generally right, but you can use
pulumi.interpolate
instead of
pulumi.all
there.
👍 1
l

little-cartoon-10569

04/06/2021, 11:53 PM
Ah, yes, any time you're using an Output<string>, then interpolate will work.
f

flat-chef-39475

04/06/2021, 11:54 PM
Hang on. What is the point of interpolate then. If
bucket.websiteEndpoint
is an Output<string>?
l

little-cartoon-10569

04/06/2021, 11:54 PM
It gets rid of the
all().apply()
boilerplate.
r

red-match-15116

04/06/2021, 11:55 PM
Link to docs if that’s helpful
f

flat-chef-39475

04/06/2021, 11:55 PM
OK, thanks again guys for the help. Is
bucket.websiteEndpoint
an Output<string>... I've read that doc a few times not.
now.
quote: All resource properties on the instance object itself are outputs.
👍🏽 1
l

little-cartoon-10569

04/06/2021, 11:56 PM
Always rely on intellisense over the docs.. a lot of docs are built from other sources which don't have concepts like Output...
r

red-match-15116

04/06/2021, 11:56 PM
Yeah my link is specifically to the piece that talks about why interpolate exists. But yes,
bucket.websiteEndpoint
(or any property of bucket) is an
Output
f

flat-chef-39475

04/06/2021, 11:58 PM
So, Interpolate is to remove some code around apply/all, so I can use interpolate, but it still does not return a string value....
quote: If you need to access an output’s raw value—for example, to compute a derived, new value, or because you want to log it—you have these options: • Apply: a callback that receives the raw value, and computes a new output • Lifting: directly read properties off an output value • Interpolation: concatenate string outputs with other strings directly
r

red-match-15116

04/06/2021, 11:59 PM
Correct,
interpolate
also returns an
Output
. The reason you can pass it in as a property to a resource is because
Input
can accept
Output<string>
as well as
string
f

flat-chef-39475

04/07/2021, 12:00 AM
ok, so lets simplify the issue. How do I log
bucket.websiteEndpoint
part way through the script?
r

red-match-15116

04/07/2021, 12:01 AM
bucket.websiteEndpoint.apply(endpoint => console.log(endpoint))
f

flat-chef-39475

04/07/2021, 12:02 AM
mmm... interpolate is no good in this case then.
r

red-match-15116

04/07/2021, 12:03 AM
No, interpolate is just a convenience function to join Output strings together.
f

flat-chef-39475

04/07/2021, 12:04 AM
OK, thanks guys. I'll run with this. You have helped a lot.
😛artypus-8bit: 2