-
Notifications
You must be signed in to change notification settings - Fork 38
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
Example to show how bundle variables work #21
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.databricks |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||||||||
# bundle_variables | ||||||||||||
|
||||||||||||
Example to show how bundle variables work. | ||||||||||||
|
||||||||||||
We will focus on the behavior of the variables section alone. To do so, we exclusively use | ||||||||||||
the `validate` command, and use its JSON output mode to focus on the variables section. | ||||||||||||
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is the main intent of this KB, but another sentence could also be added about showing how to set variable defaults. (Update: I tinkered with that suggestion.) |
||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any prerequisites worth mentioning? It might be a good standard just to list the supported CLI version for any KB? |
||||||||||||
## Usage | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This singular heading feels unnecessary and also doesn't seem like quite the right word. I'd either remove it (acceptable for a KB e.g., https://kb.databricks.com/en_US/clusters/calculate-number-of-cores) or break up the content into at least two headings. (I'd lean towards the former.) |
||||||||||||
|
||||||||||||
Configure the workspace to use: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
```sh | ||||||||||||
export DATABRICKS_CONFIG_PROFILE="<workspace profile>" | ||||||||||||
``` | ||||||||||||
|
||||||||||||
Try to run validate without arguments: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure how this command was "without arguments" but maybe I'm misunderstanding the intent there. Also, I'm not sure if it's necessary to state that last bit as most devs know all about jq, but it feels most complete. |
||||||||||||
```sh | ||||||||||||
databricks bundle validate --output json | jq .variables | ||||||||||||
``` | ||||||||||||
|
||||||||||||
Because the configuration includes a variable definition without a value, it returns an error | ||||||||||||
saying that the value must be defined: | ||||||||||||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
``` | ||||||||||||
Error: no value assigned to required variable "no_default". | ||||||||||||
``` | ||||||||||||
|
||||||||||||
Assign a value for this variable by either: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
1. Adding a `--var` flag to all bundle commands: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These aren't steps (numbered list) but a list of options (bulleted list). However, I like making it really clear (see the next comment)... |
||||||||||||
```sh | ||||||||||||
databricks bundle validate --var no_default="injected value" | ||||||||||||
``` | ||||||||||||
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent these to fit under the bullet. |
||||||||||||
|
||||||||||||
2. Configuring an environment variable: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (But this might look weird, or not follow our style) |
||||||||||||
```sh | ||||||||||||
export BUNDLE_VAR_no_default="injected value" | ||||||||||||
``` | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent this to fit under the bullet. |
||||||||||||
|
||||||||||||
Now, try to run validate again, and observe that it passes: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
```sh | ||||||||||||
databricks bundle validate --var no_default="injected value" --output json | jq .variables | ||||||||||||
``` | ||||||||||||
|
||||||||||||
Example output: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
```json | ||||||||||||
{ | ||||||||||||
"no_default": { | ||||||||||||
"description": "This is a variable with no default value", | ||||||||||||
"value": "injected value" | ||||||||||||
}, | ||||||||||||
"with_default": { | ||||||||||||
"description": "This is a variable with a default value", | ||||||||||||
"value": "hello" | ||||||||||||
}, | ||||||||||||
"with_default_in_targets": { | ||||||||||||
"default": "value_in_development", | ||||||||||||
"description": "This is a variable with its default value defined in the targets section", | ||||||||||||
"value": "value_in_development" | ||||||||||||
} | ||||||||||||
} | ||||||||||||
``` | ||||||||||||
|
||||||||||||
What we've seen: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
* The `no_default` variable is defined with the value we injected. | ||||||||||||
* The `with_default` variable is defined with the default value. | ||||||||||||
* The `with_default_in_targets` variable is defined with the value from the targets section. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
bundle: | ||
name: bundle_variables | ||
|
||
variables: | ||
no_default: | ||
description: This is a variable with no default value | ||
|
||
with_default: | ||
description: This is a variable with a default value | ||
value: hello | ||
|
||
with_default_in_targets: | ||
description: This is a variable with its default value defined in the targets section | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pedantic, I know, but can we add periods to the end of the sentences on all of these descriptions? |
||
targets: | ||
development: | ||
default: true | ||
|
||
variables: | ||
with_default_in_targets: value_in_development | ||
|
||
production: | ||
variables: | ||
with_default_in_targets: value_in_production |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a real title would be nice. Given it's a KB topic, how about "How to validate bundle variables"? Or maybe that's not quite right... "How to validate and set variable values"?