Thread
#prefect-community
    p

    Peyton Runyan

    1 year ago
    Is there a good way to parameterize an environment variable in a flow? Below is my user config. I'd love to be able to pass
    mode
    as a parameter instead of messing with it in the config and re-registering my flow.
    mode = "hard_coded_mode"
    [sql_server]
        server = server
        driver = driver
        dsn = "MYMSSQL"
        user = "${sql_server.${mode}.user}"
        database = "${sql_server.${mode}.database}"
    
        [sql_server.dev]
            user =  dev user
            database = "dev db
    
        [sql_server.hub]
            user = app user
            database = app db
    
        [sql_server.prod]
            user = prod user
            database = prod db
    Worst comes to worst I guess I could just kill the agent and restart it with
    mode
    as an environment variable?
    Kyle Moon-Wright

    Kyle Moon-Wright

    1 year ago
    Hey @Peyton Runyan, With your setup so far, it might work to set the environment variable in your python script with something like this (not sure if these work):
    mode = Parameter("Environment Mode", default="dev")
    os.environ["PREFECT__CONFIG__MODE"] = mode
    Otherwise, setting the values directly in your script might be best:
    mode = Parameter("Mode", default="dev")
    
    prefect.config.sql_server.user = prefect.config.sql_server.${mode}.user
    
    prefect.config.sql_server.database = prefect.config.sql_server.${mode}.database
    You’ll likely need to adjust for your use case, but I definitely think you can accomplish something like this. More information on switching configurations can be found here.