Hey Prefect team :slightly_smiling_face: We’re se...
# ask-community
m
Hey Prefect team 🙂 We’re setting up flows that need to connect to various systems, like databases, and we’re using secrets stored in our Prefect Cloud instance to manage those connections. Right now, we’re pulling in secrets within a task in the flow (see sample code below).
Copy code
@task
def db_connection() -> connection:
    try:
        connection = db.connect(
            user=Secret.load("user").get(),
            password=Secret.load("password").get(),
            # additional connection params...
        )
        return connection
    except Exception as e:
        raise PrefectException(f"DB connection error: {e}")
Next step: we want to spin up a test work pool/worker to trigger these flows in a test environment before they go live in production. These test flows would also need to connect to separate test databases. Question: Do we need separate secrets for the test environment in Prefect Cloud, and conditionally load them based on the environment (test vs. production)? Or is there a more streamlined way to handle this setup? Anyone tackled this before? Thanks in advance!
n
hey @Michael Michael! one thing that might be useful to know is that nowadays you can set any JSON value as a
Secret
block so for example
Copy code
{
  "test": "sk-XXX",
  "prod": "sk-XXX"
}
could be a secret value, and you'd get the actual
dict
instance when you call
Secret.load('your-secret')
👍 1