-
Notifications
You must be signed in to change notification settings - Fork 37
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?
Conversation
I was in need of a working example to demonstrate how this works, so figured I create an example. Feedback welcome! |
@@ -0,0 +1,65 @@ | |||
# bundle_variables |
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"?
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. |
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.
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. | |
This example shows how to validate and set values for the custom variables defined for a bundle using the `bundle validate` command and its JSON output mode. |
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 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.)
|
||
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. | ||
|
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.
Are there any prerequisites worth mentioning? It might be a good standard just to list the supported CLI version for any KB?
|
||
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 comment
The 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?
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. | ||
|
||
## Usage |
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.
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.)
|
||
## Usage | ||
|
||
Configure the workspace to use: |
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.
Configure the workspace to use: | |
First, configure your workspace: |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Try to run validate without arguments: | |
Next, run `bundle validate` using the JSON output mode and `jq` to retrieve just the variables node. |
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 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.
Because the configuration includes a variable definition without a value, it returns an error | ||
saying that the value must be defined: |
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.
Because the configuration includes a variable definition without a value, it returns an error | |
saying that the value must be defined: | |
Because the configuration includes a variable definition without a value, it returns the following error: |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Assign a value for this variable by either: | |
To assign a value to this variable, you can either: |
|
||
Assign a value for this variable by either: | ||
|
||
1. Adding a `--var` flag to all bundle commands: |
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.
1. Adding a `--var` flag to all bundle commands: | |
- Add a `--var` flag to all bundle commands: |
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.
These aren't steps (numbered list) but a list of options (bulleted list). However, I like making it really clear (see the next comment)...
databricks bundle validate --var no_default="injected value" | ||
``` | ||
|
||
2. Configuring an environment variable: |
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.
2. Configuring an environment variable: | |
OR | |
- Configure an environment variable: |
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.
(But this might look weird, or not follow our style)
```sh | ||
databricks bundle validate --var no_default="injected value" | ||
``` |
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.
Indent these to fit under the bullet.
2. Configuring an environment variable: | ||
```sh | ||
export BUNDLE_VAR_no_default="injected value" | ||
``` |
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.
Indent this to fit under the bullet.
export BUNDLE_VAR_no_default="injected value" | ||
``` | ||
|
||
Now, try to run validate again, and observe that it passes: |
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.
Now, try to run validate again, and observe that it passes: | |
Now run validate again, and observe that it succeeds in outputting valid JSON: |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Example output: |
} | ||
``` | ||
|
||
What we've seen: |
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.
What we've seen: | |
In summary: |
No description provided.