Let me try again.
I've got a complex UserData script, and cannot get the TailnetKey to output.
For a simple UserData it works fine e.g,
import * as tailscale from "@pulumi/tailscale";
import * as aws from "@pulumi/aws";
const tn_key = new tailscale.TailnetKey("tailnet-key", {
});
new aws.ec2.Instance(`instance1`, {
tags: {
Name: "slartibartfast"
},
instanceType: "t3.small",
ami: "ami-01e2093820bf84df1",
// NOTE the .apply() is being set on the Input<string> at the top level
userData: tn_key.key.apply(v => `
#!/bin/sh
curl -fsSL <https://tailscale.com/install.sh> | sh
tailscale up --auth-key=${v}
`),
})
But for a more complex one, where the key needs to be outputted first, the response is always
Calling [toString] on an [Output<T>] is not supported. ...
.
e.g.
import * as tailscale from "@pulumi/tailscale";
import * as aws from "@pulumi/aws";
const tn_key2 = new tailscale.TailnetKey("tailnet-key", {
});
new aws.ec2.Instance(`instance2`, {
tags: {
Name: "slartibartfast2"
},
instanceType: "t3.small",
ami: "ami-01e2093820bf84df1",
// NOTE the .apply() is inside the string interpolation
userData: `
#!/bin/sh
curl -fsSL <https://tailscale.com/install.sh> | sh
tailscale up --auth-key=${tn_key2.key.apply(v => v)}
`,
})
Please don't respond is you are simply going to suggest
use apply or pulumi.interpolate.
The code above is complete, ie. with run if you put it in a index.ts.
If you are not 110% sure you answer will solve the problem, please run it on with
pulumi up -d
.
If get
ailscale up --auth-key=Calling [toString] on an [Output<T>] is not supported....
, then you have not solved the problem.
I have tried many alternatives (multiple versions of creating a custom ComponentResource, putting the tn_key in the dependsOn opts, ...)
My guess the issue has something to do how pulumi manages dependancies, but
I could really do with some expert help. (
@joeduffy)
Thanks in advance
Gary