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

Example to show how bundle variables work #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Feb 14, 2024

No description provided.

@pietern
Copy link
Contributor Author

pietern commented Feb 14, 2024

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
Copy link
Contributor

@juliacrawf-db juliacrawf-db Feb 15, 2024

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"?

Comment on lines +3 to +6
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.
Copy link
Contributor

@juliacrawf-db juliacrawf-db Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor

@juliacrawf-db juliacrawf-db Feb 15, 2024

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.

Copy link
Contributor

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

Copy link
Contributor

@juliacrawf-db juliacrawf-db Feb 15, 2024

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
Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Configure the workspace to use:
First, configure your workspace:

export DATABRICKS_CONFIG_PROFILE="<workspace profile>"
```

Try to run validate without arguments:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Try to run validate without arguments:
Next, run `bundle validate` using the JSON output mode and `jq` to retrieve just the variables node.

Copy link
Contributor

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.

Comment on lines +20 to +21
Because the configuration includes a variable definition without a value, it returns an error
saying that the value must be defined:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Adding a `--var` flag to all bundle commands:
- Add a `--var` flag to all bundle commands:

Copy link
Contributor

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:
Copy link
Contributor

@juliacrawf-db juliacrawf-db Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Configuring an environment variable:
OR
- Configure an environment variable:

Copy link
Contributor

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)

Comment on lines +29 to +31
```sh
databricks bundle validate --var no_default="injected value"
```
Copy link
Contributor

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"
```
Copy link
Contributor

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:
Copy link
Contributor

@juliacrawf-db juliacrawf-db Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Example output:

}
```

What we've seen:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
What we've seen:
In summary:

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

Successfully merging this pull request may close these issues.

3 participants