Let me try again. I've got a complex UserData script, and cannot get the TailnetKey to output. For ...
g

Gary Miller

8 months ago
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
``` pulumi:pulumi:Stack testproject-test-dev 1 warning pulumi:providers:gcp default_7_32_0 **fa...
s

Sasiru Ravihansa

10 months ago
pulumi:pulumi:Stack testproject-test-dev  1 warning
    pulumi:providers:gcp default_7_32_0 **failed** 1 error
Diagnostics:
  pulumi:pulumi:Stack (testproject-test-dev):
    warning: failed to get regions list: failed to create compute service: google: could not find default credentials. See <https://cloud.google.com/docs/authentication/external/set-up-adc> for more information

  pulumi:providers:gcp (default_7_32_0):
    error: rpc error: code = Unknown desc = failed to load application credentials.
    To use your default gcloud credentials, run:
    	`gcloud auth application-default login`
    See <https://www.pulumi.com/registry/packages/gcp/installation-configuration/> for details.
    Expanded error message: Attempted to load application default credentials since neither `credentials` nor `access_token` was set in the provider block.  No credentials loaded. To use your gcloud credentials, run 'gcloud auth application-default login'.  Original error: google: could not find default credentials. See <https://cloud.google.com/docs/authentication/external/set-up-adc> for more information

Outputs:

Resources:
    ~ 1 updated
    1 unchanged

Duration: 1m20s
I am getting this error. I didn't use gcloud auth activate-service-account --key-file=/gcp_key.json because i want to have different keys for different gcloud resources ( like cloud build, or compute). I just use separate pulumi
gcp.NewProvider
to create providers based on the resources. What can i do here ?