Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing variables to D2 through environment variables #1612

Open
albertored11 opened this issue Sep 25, 2023 · 3 comments
Open

Passing variables to D2 through environment variables #1612

albertored11 opened this issue Sep 25, 2023 · 3 comments

Comments

@albertored11
Copy link

Variables are a great feature in D2, but it would be nice to be able to set values for the variables in other ways rather than directly in the .d2 file. In my case, I would like to reuse files for different diagrams, and having to create a new file with the values of the variables to import it from the main file is a bit inconvenient.

How about passing variables through environment variables in a similar fashion to Terraform variables?

E.g. to give bucket variable the value mybucket-1234 to be used when compiling a d2 file, do something like the following beforehand:

export D2_VAR_bucket="mybucket-1234"

I'd really appreciate your thoughts on this. Thanks in advance! 🙂

@cyborg-ts cyborg-ts added this to D2 Sep 25, 2023
@albertored11 albertored11 changed the title Passing variables through environment variables Passing variables to D2 through environment variables Sep 25, 2023
@alixander
Copy link
Collaborator

alixander commented Sep 25, 2023

Hmm, I can see that.

My first instinct was to have source variables take precedent over env variables, but I think I'd want to flip that so that the source variable is the "default", and all referenced variables have to exist in the source vars in order to compile.

vars: {
  num_servers: 2
  server_name: SET_ME_IN_ENVS
}

x: ${server_name}
...

@jygastaud
Copy link

Maybe a simpler idea to start could be to allow an creation/override from d2 command line ?
Something like --extra-vars parameter in Ansible CLI ( --extra-vars "version=1.23.45 other_variable=foo)

@alixander
Copy link
Collaborator

this is also useful for themes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants