https://pulumi.com logo
Title
s

square-coat-62279

11/12/2021, 11:47 AM
Not sure if this makes sense, I am parsing a list of prefixes to fetch a list of matching secrets from Google Secret Manager:
let var3 = []
      for (let secret of props.secret ){
        let var1 = pulumi.output(gcp.secretmanager.getSecret({
          secretId: `${secret}*`
        }))
        let var2 = var1.name
            var3 = var3.concat(var2)
      }
The idea is to append the result from the getSecret function to var3 and then parse this list to create kubernetes secrets, I saw error: Variable 'var3' implicitly has type 'any[]' in some locations where its type cannot be determined. What's the result type return from the function and how should I append them?
h

happy-parrot-60128

11/12/2021, 12:02 PM
Assuming you're working in JS/TS you can use the
pulumi.all
helper to work with a list of outputs e.g.
let var3 = pulumi
  .all(props.secret.map((secret) => gcp.secretmanager.getSecret({ secretId: `${secret}*` })))
  .apply((secrets) => secrets.map((s) => s.name));
This makes the type of
var3
an
Output<string[]>
. You can then use this as an input to another resource, or use another
.apply(...)
to manipulate it further. Does that help?
s

square-coat-62279

11/12/2021, 12:15 PM
Thanks Daniel, does that make var3: ["secret1","secret2","secret3"] (for example if these are the returned secret names)?
h

happy-parrot-60128

11/12/2021, 12:16 PM
Yup, that's the one 👍
s

square-coat-62279

11/12/2021, 1:52 PM
forgot to mention, I am using TS and props.secret looks like ["secret","test"], would the map function still work?
h

happy-parrot-60128

11/12/2021, 1:59 PM
Yup, I think that should all work. Give it a go and drop a note back if you run into any tricky bits
s

square-coat-62279

11/12/2021, 2:01 PM
My IDE doesn't recognise the map for secrets 🤔
h

happy-parrot-60128

11/12/2021, 2:03 PM
Is the type of props.secret
string[]
?
s

square-coat-62279

11/12/2021, 2:14 PM
Yes
h

happy-parrot-60128

11/12/2021, 2:21 PM
Oh I was looking at the wrong variable - does you're IDE show you the type of
secrets
? It should be something like
pulumi.UnwrappedObject<gcp.secretmanager.GetSecretResult>[]
s

square-coat-62279

11/12/2021, 2:45 PM
h

happy-parrot-60128

11/12/2021, 3:01 PM
It looks like the source of the issue is that Typescript doesn't know the type of
props.secret
- and therefore the input to pulumi.all isn't nailed down either. You could try manually specifying the type first e.g.
let secret: string[] = props.secret
🆗 1
s

square-coat-62279

11/12/2021, 3:43 PM
seems like IDE stop complaining about the line now, the next question is, I'd like to generate an array:
data: var2.map(p => ({
               "key": p,
               "name": p,
               "version": "latest"
          })),
the objective is to loop through the item in the array and create a new array that looks like this:
data:
  - key: secret1
    name: secret1
    version: latest
  - key: secret2
    name: secret2
    version: latest
before going too far, does the getter function support wildcard search?
h

happy-parrot-60128

11/12/2021, 5:33 PM
Ah yeah, I expect it's just a direct lookup by name rather than search
s

square-coat-62279

11/13/2021, 10:26 AM
oh boy, is there a way to fetch a list of secrets from secret manager based on a prefix in Pulumi?
h

happy-parrot-60128

11/15/2021, 10:31 AM
Not that I'm aware of - Pulumi's designed more to create & manage resources rather than querying existing ones. If you're just wanting to query the secrets then the SDK is probably your best route. If you want to manage the secrets with Pulumi then you can import them