Skip to content

Commit d81cb0b

Browse files
authored
Add support for valueFrom property (similar to app.yaml) inside Apps config field in bundle configuration (#4297)
## Changes Add support for valueFrom property (similar to app.yaml) inside Apps config field in bundle configuration ## Why Fixes #4288 ## Tests Added a unit test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 15e4169 commit d81cb0b

File tree

8 files changed

+70
-6
lines changed

8 files changed

+70
-6
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### CLI
88

99
### Bundles
10+
* Add support for valueFrom property (similar to app.yaml) inside Apps config field in bundle configuration ([#4297](https://github.com/databricks/cli/pull/4297))
1011
* engine/direct: Support bind & unbind. ([#4279](https://github.com/databricks/cli/pull/4279))
1112

1213
### Dependency updates

acceptance/bundle/refschema/out.fields.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ resources.apps.*.config.env []resources.AppEnvVar INPUT
106106
resources.apps.*.config.env[*] resources.AppEnvVar INPUT
107107
resources.apps.*.config.env[*].name string INPUT
108108
resources.apps.*.config.env[*].value string INPUT
109+
resources.apps.*.config.env[*].value_from string INPUT
109110
resources.apps.*.create_time string ALL
110111
resources.apps.*.creator string ALL
111112
resources.apps.*.default_source_code_path string ALL

bundle/config/resources/apps.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ type AppEnvVar struct {
2626
Name string `json:"name" yaml:"name"`
2727

2828
// Value is the environment variable value
29-
Value string `json:"value" yaml:"value"`
29+
Value string `json:"value,omitempty" yaml:"value,omitempty"`
30+
31+
// ValueFrom is the name of an external Databricks resource that contains the value, such as a secret or a database table.
32+
ValueFrom string `json:"value_from,omitempty" yaml:"value_from,omitempty"`
3033
}
3134

3235
type App struct {

bundle/internal/schema/annotations.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ github.com/databricks/cli/bundle/config/resources.AppEnvVar:
515515
"value":
516516
"description": |-
517517
PLACEHOLDER
518+
"value_from":
519+
"description": |-
520+
PLACEHOLDER
518521
github.com/databricks/cli/bundle/config/resources.AppPermission:
519522
"group_name":
520523
"description": |-

bundle/internal/validation/generated/required_fields.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/run/app.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ func (a *appRunner) buildAppDeployment() apps.AppDeployment {
176176
deployment.EnvVars = make([]apps.EnvVar, len(a.app.Config.Env))
177177
for i, env := range a.app.Config.Env {
178178
deployment.EnvVars[i] = apps.EnvVar{
179-
Name: env.Name,
180-
Value: env.Value,
179+
Name: env.Name,
180+
Value: env.Value,
181+
ValueFrom: env.ValueFrom,
181182
}
182183
}
183184
}

bundle/run/app_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,56 @@ func TestStopApp(t *testing.T) {
270270
err := r.Cancel(ctx)
271271
require.NoError(t, err)
272272
}
273+
274+
func TestBuildAppDeploymentWithValueFrom(t *testing.T) {
275+
app := &resources.App{
276+
SourceCodePath: "/path/to/app",
277+
Config: &resources.AppConfig{
278+
Command: []string{"python", "app.py"},
279+
Env: []resources.AppEnvVar{
280+
{
281+
Name: "REGULAR_VAR",
282+
Value: "regular_value",
283+
},
284+
{
285+
Name: "SECRET_VAR",
286+
ValueFrom: "secrets/my-secret",
287+
},
288+
{
289+
Name: "COMBINED_VAR",
290+
Value: "default_value",
291+
ValueFrom: "secrets/override",
292+
},
293+
},
294+
},
295+
}
296+
297+
runner := &appRunner{
298+
app: app,
299+
}
300+
301+
deployment := runner.buildAppDeployment()
302+
303+
require.Equal(t, apps.AppDeploymentModeSnapshot, deployment.Mode)
304+
require.Equal(t, "/path/to/app", deployment.SourceCodePath)
305+
require.Len(t, deployment.Command, 2)
306+
require.Equal(t, "python", deployment.Command[0])
307+
require.Equal(t, "app.py", deployment.Command[1])
308+
309+
require.Len(t, deployment.EnvVars, 3)
310+
311+
// Regular env var with value
312+
require.Equal(t, "REGULAR_VAR", deployment.EnvVars[0].Name)
313+
require.Equal(t, "regular_value", deployment.EnvVars[0].Value)
314+
require.Equal(t, "", deployment.EnvVars[0].ValueFrom)
315+
316+
// Env var with value_from
317+
require.Equal(t, "SECRET_VAR", deployment.EnvVars[1].Name)
318+
require.Equal(t, "", deployment.EnvVars[1].Value)
319+
require.Equal(t, "secrets/my-secret", deployment.EnvVars[1].ValueFrom)
320+
321+
// Env var with both value and value_from
322+
require.Equal(t, "COMBINED_VAR", deployment.EnvVars[2].Name)
323+
require.Equal(t, "default_value", deployment.EnvVars[2].Value)
324+
require.Equal(t, "secrets/override", deployment.EnvVars[2].ValueFrom)
325+
}

bundle/schema/jsonschema.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)