https://pulumi.com logo
Title
m

microscopic-zoo-3564

05/16/2021, 10:07 PM
I'm sure I'm missing something simple here, but how can I use an external stack reference inside the following:
const secret = pulumi.output(
      aws.secretsmanager.getSecret(
        {
          name: stackReferenceToSecretName,
        },
        { async: true }
      )
    )
I keep running into a typescript error
Type 'string | Output<any>' is not assignable to type 'string | undefined'
l

little-cartoon-10569

05/16/2021, 10:10 PM
Not really an AWS question 🙂 Is the problem occurring when you use secret elsewhere? Or in this code, when you use stackReferenceToSecretName?
You've got a type error, and you need to access the value in an Output appropriately. Just need to figure out where.
m

microscopic-zoo-3564

05/16/2021, 10:13 PM
It is in this code, the type error appears when assigning stackReferenceToSecretName to name.
l

little-cartoon-10569

05/16/2021, 10:17 PM
Great. Can you add the code where you initialize the variable?
m

microscopic-zoo-3564

05/16/2021, 10:23 PM
const coreStackRef = new pulumi.StackReference(
  `name/project/${pulumi.getStack()}`
)

const hasuraCredentialsSecretName = coreStackRef.getOutput(
  "hasuraCredentialsSecretKeyName"
)

const hasuraCredentialsSecret = pulumi.output(
  aws.secretsmanager.getSecret(
    {
      name: hasuraCredentialsSecretName,
    },
    { async: true }
  )
)
l

little-cartoon-10569

05/16/2021, 10:23 PM
It should be something like this:
const secretInfo: pulumi.Output<GetSecretResult> = stackReferenceToSecretName.apply((secretName) => aws.secretsmanager.getSecret({ name: secretName });
The apply() will automatically convert the returned Promise<GetSecretResult> into a pulumi.Output<GetSecretResult> for you.
If the secretValue was created in another stack and you want to use it in this stack, you might find that the aws.secretsmanager.SecretVersion.get() static method helps you avoid a little boilerplate code.
m

microscopic-zoo-3564

05/16/2021, 10:37 PM
cool, thanks