This message was deleted.
# general
s
This message was deleted.
l
You have (had?) this code, which is the source of the issue:
Copy code
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
Hi tenwit, I thought pulumi.interpolate would return a string?
l
As the error message says, you need to do this inside an apply, thus:
Copy code
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
ok... that gives me a focus. Thanks mate.
r
@little-cartoon-10569 is generally right, but you can use
pulumi.interpolate
instead of
pulumi.all
there.
👍 1
l
Ah, yes, any time you're using an Output<string>, then interpolate will work.
f
Hang on. What is the point of interpolate then. If
bucket.websiteEndpoint
is an Output<string>?
l
It gets rid of the
all().apply()
boilerplate.
r
Link to docs if that’s helpful
f
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
Always rely on intellisense over the docs.. a lot of docs are built from other sources which don't have concepts like Output...
r
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
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
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
ok, so lets simplify the issue. How do I log
bucket.websiteEndpoint
part way through the script?
r
bucket.websiteEndpoint.apply(endpoint => console.log(endpoint))
f
mmm... interpolate is no good in this case then.
r
No, interpolate is just a convenience function to join Output strings together.
f
OK, thanks guys. I'll run with this. You have helped a lot.
partypus 8bit 2