Not sure if this makes sense, I am parsing a list ...
# general
s
Not sure if this makes sense, I am parsing a list of prefixes to fetch a list of matching secrets from Google Secret Manager:
Copy code
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
Assuming you're working in JS/TS you can use the
pulumi.all
helper to work with a list of outputs e.g.
Copy code
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
Thanks Daniel, does that make var3: ["secret1","secret2","secret3"] (for example if these are the returned secret names)?
h
Yup, that's the one 👍
s
forgot to mention, I am using TS and props.secret looks like ["secret","test"], would the map function still work?
h
Yup, I think that should all work. Give it a go and drop a note back if you run into any tricky bits
s
My IDE doesn't recognise the map for secrets 🤔
h
Is the type of props.secret
string[]
?
s
Yes
h
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
h
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
seems like IDE stop complaining about the line now, the next question is, I'd like to generate an array:
Copy code
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:
Copy code
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
Ah yeah, I expect it's just a direct lookup by name rather than search
s
oh boy, is there a way to fetch a list of secrets from secret manager based on a prefix in Pulumi?
h
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