From ed591391b672bc518aee43fcdcfdad6be26ef902 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Wed, 14 Feb 2024 10:24:54 +0100 Subject: [PATCH] Example to show how bundle variables work --- knowledge_base/bundle_variables/.gitignore | 1 + knowledge_base/bundle_variables/README.md | 65 +++++++++++++++++++ .../bundle_variables/databricks.yml | 24 +++++++ 3 files changed, 90 insertions(+) create mode 100644 knowledge_base/bundle_variables/.gitignore create mode 100644 knowledge_base/bundle_variables/README.md create mode 100644 knowledge_base/bundle_variables/databricks.yml diff --git a/knowledge_base/bundle_variables/.gitignore b/knowledge_base/bundle_variables/.gitignore new file mode 100644 index 0000000..15bcc6d --- /dev/null +++ b/knowledge_base/bundle_variables/.gitignore @@ -0,0 +1 @@ +.databricks diff --git a/knowledge_base/bundle_variables/README.md b/knowledge_base/bundle_variables/README.md new file mode 100644 index 0000000..11b25ae --- /dev/null +++ b/knowledge_base/bundle_variables/README.md @@ -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. + +## Usage + +Configure the workspace to use: +```sh +export DATABRICKS_CONFIG_PROFILE="" +``` + +Try to run validate without arguments: +```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: +``` +Error: no value assigned to required variable "no_default". +``` + +Assign a value for this variable by either: + +1. Adding a `--var` flag to all bundle commands: +```sh +databricks bundle validate --var no_default="injected value" +``` + +2. Configuring an environment variable: +```sh +export BUNDLE_VAR_no_default="injected value" +``` + +Now, try to run validate again, and observe that it passes: +```sh +databricks bundle validate --var no_default="injected value" --output json | jq .variables +``` + +Example output: +```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: +* 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. diff --git a/knowledge_base/bundle_variables/databricks.yml b/knowledge_base/bundle_variables/databricks.yml new file mode 100644 index 0000000..98bf9c2 --- /dev/null +++ b/knowledge_base/bundle_variables/databricks.yml @@ -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 + +targets: + development: + default: true + + variables: + with_default_in_targets: value_in_development + + production: + variables: + with_default_in_targets: value_in_production