<@ULVA73B9P> i have three profiles in .profiles/pr...
# ask-marvin
m
@Marvin i have three profiles in .profiles/profiles.toml. i run a loop through each profile, set the active profile which has the PREFECT_API_URL to a workspace, and try to set up a block with each profile's configuration. unfortunately, the block are build to only one workspace. why
m
It appears that you might be experiencing an issue with the way you're setting up the PREFECT_API_URL for each profile. When using multiple profiles, you need to ensure that the PREFECT_API_URL is set correctly for each profile, pointing to the correct workspace. Here's an example of how to configure the PREFECT_API_URL and PREFECT_API_KEY for each profile:
Copy code
bash
$ prefect config set PREFECT_API_URL="<https://api.prefect.cloud/api/accounts/[ACCOUNT-ID]/workspaces/[WORKSPACE-ID]>" --profile profile1
$ prefect config set PREFECT_API_KEY="[API-KEY]" --profile profile1

$ prefect config set PREFECT_API_URL="<https://api.prefect.cloud/api/accounts/[ACCOUNT-ID]/workspaces/[WORKSPACE-ID]>" --profile profile2
$ prefect config set PREFECT_API_KEY="[API-KEY]" --profile profile2

$ prefect config set PREFECT_API_URL="<https://api.prefect.cloud/api/accounts/[ACCOUNT-ID]/workspaces/[WORKSPACE-ID]>" --profile profile3
$ prefect config set PREFECT_API_KEY="[API-KEY]" --profile profile3
Make sure to replace
[ACCOUNT-ID]
,
[WORKSPACE-ID]
, and
[API-KEY]
with the appropriate values for each profile. When you loop through each profile, ensure that you're activating the correct profile before setting up the block. For example:
Copy code
python
import prefect

profiles = ["profile1", "profile2", "profile3"]

for profile in profiles:
    prefect.config.set_active_profile(profile)
    # Set up the block with the current profile's configuration
This should help you build blocks in different workspaces using multiple profiles. If only humans could keep their configurations as organized as robots do.
m
@Marvin the profiles are correct. however, the code snippet you gave me does not work.
Copy code
prefect.config.set_active_profile(profile_name)
AttributeError: module 'prefect' has no attribute 'config'
m
Apologies for the confusion. It seems I made a mistake in my response. The correct way to set the active profile is by using the
prefect.context
module. Here's the updated code snippet:
Copy code
python
import prefect
from prefect import context

profiles = ["profile1", "profile2", "profile3"]

for profile in profiles:
    with context(config=prefect.config.set_active_profile(profile)):
        # Set up the block with the current profile's configuration
This should work for setting the active profile within the loop. I hope this helps, and remember, even robots make mistakes sometimes.