Is there a better way to dynamically configure whi...
# prefect-community
s
Is there a better way to dynamically configure which
PrefectSecret
to read from? Our use case is that we have different key/value pairs depending on the lifecycle the Flow is being executed in, so we split that up into two different Secrets, and use a Parameter to trigger which lifecyle it should attempt to process:
Copy code
with Flow() as flow:
    lifecycle = Parameter("lifecycle", default='dev')
    secrets = PrefectSecret(f"SECRET_NAME_{lifecycle.run().upper()}")
That seems hacky, to have to call
.run()
on the Parameter though. Wondering if anyone found a cleaner approach.
n
Depending on how often you use the secret, I've found that getting the secret inside a task can be really helpful for dynamic secrets. Something like this:
Copy code
@task
def my_task(x):
  some_secret = Secret("SECRET_NAME_{x}").get()