<@ULVA73B9P> I have some secret blocks in my prod ...
# ask-marvin
c
@Marvin I have some secret blocks in my prod workspace that I want to reference in dev. Is there a way to share blocks across workspaces to have the same blocks on my prod workspace available for my dev workspace?
m
thought for 274.6 seconds
Short answer: not directly. In Prefect Cloud 3.x, blocks (including Secret blocks) are scoped to a workspace and cannot be shared across workspaces. You’ll need to recreate them in your dev workspace. Recommended approaches: - Preferred: Source secrets from your secret manager (AWS Secrets Manager, Vault, etc.) and “seed” both workspaces from that source of truth. - One‑off copy: Use a small script to read secrets from prod and write them to dev. Secret values are encrypted at rest but can be retrieved in code with
.get()
when you have access. Example copy script (handle carefully; don’t log secrets):
Copy code
from prefect.blocks.system import Secret
from prefect.settings import temporary_settings, PREFECT_API_URL, PREFECT_API_KEY

# Fill in your API URLs/keys for each workspace
PROD = {
    PREFECT_API_URL: "<https://api.prefect.cloud/api/accounts/<account_id>/workspaces/<prod_workspace_id>>",
    PREFECT_API_KEY: "<prod_api_key>",
}
DEV = {
    PREFECT_API_URL: "<https://api.prefect.cloud/api/accounts/<account_id>/workspaces/<dev_workspace_id>>",
    PREFECT_API_KEY: "<dev_api_key>",
}

# List the secret block names you want to copy
secret_names = ["db-password", "slack-token"]

# Read from prod
with temporary_settings(PROD):
    values = {name: Secret.load(name).get() for name in secret_names}

# Write to dev (creates or updates)
with temporary_settings(DEV):
    for name, value in values.items():
        Secret(value=value).save(name, overwrite=True)
Helpful tips: - You can list what blocks exist in a workspace with:
Copy code
prefect block ls
- Inspect an individual block (metadata only; not the secret value):
Copy code
prefect block inspect -n <block-name>
- Keep block names consistent across environments so your code can always
Secret.load("<name>")
. Docs: - Workspaces overview: Workspaces in Prefect Cloud - Storing and using secrets: Store secrets with Secret blocks If you’d like, tell me how many secrets you need to copy and I can tailor a script (e.g., discover all Secret blocks in prod and mirror them to dev).