https://dagster.io/ logo
#ask-community
Title
# ask-community
b

Bolin Zhu

06/12/2023, 11:08 AM
Hi team! I am trying to use
dagster.EnvVar
to load an environment variable while constructing a resource. I am doing something like this:
Copy code
configured_cassandra_resource = Cassandra(
    clusters=os.getenv("CASSANDRA_CLUSTERS").split(),
    port=<http://EnvVar.int|EnvVar.int>("CASSANDRA_PORT"),
    user=EnvVar("CASSANDRA_USER"),
    password=EnvVar("CASSANDRA_PASSWORD")
)
Is there a way to use EnvVar and load the environment variable
CASSANDRA_CLUSTERS
as an array?
EnvVar("CASSANDRA_CLUSTERS").split()
does not work as it returns
["CASSANDRA_CLUSTERS"]
as the value (see screenshot) Alternatively, is there a more elegant way to supply an array of string to
Cassandra.clusters
?
q

Qwame

06/12/2023, 12:40 PM
You probably have to strip first before you split.
.strip("][").split(",")
t

Tim Castillo

06/12/2023, 4:40 PM
Hey Bolin! Unfortunately, resolving arrays from environment variables is hard, but can you use
EnvVar
to take a string of comma-separated values and then split them within your custom resource at runtime?
b

Bolin Zhu

06/13/2023, 2:09 AM
Yeap, I will do that, thank you both!
8 Views