Skip to content

Commit 320b408

Browse files
committed
feedback
1 parent 6b70cfd commit 320b408

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

bundle/apps/interpolate_variables.go

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,27 @@ func (i *interpolateVariables) Apply(ctx context.Context, b *bundle.Bundle) diag
1919
dyn.Key("config"),
2020
)
2121

22+
tfToConfigMap := map[string]string{
23+
"databricks_pipeline": "pipelines",
24+
"databricks_job": "jobs",
25+
"databricks_mlflow_model": "models",
26+
"databricks_mlflow_experiment": "experiments",
27+
"databricks_model_serving": "model_serving_endpoints",
28+
"databricks_registered_model": "registered_models",
29+
"databricks_quality_monitor": "quality_monitors",
30+
"databricks_schema": "schemas",
31+
"databricks_volume": "volumes",
32+
"databricks_cluster": "clusters",
33+
"databricks_dashboard": "dashboards",
34+
"databricks_app": "apps",
35+
}
36+
2237
err := b.Config.Mutate(func(root dyn.Value) (dyn.Value, error) {
2338
return dyn.MapByPattern(root, pattern, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
2439
return dynvar.Resolve(v, func(path dyn.Path) (dyn.Value, error) {
25-
switch path[0] {
26-
case dyn.Key("databricks_pipeline"):
27-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("pipelines")).Append(path[1:]...)
28-
case dyn.Key("databricks_job"):
29-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("jobs")).Append(path[1:]...)
30-
case dyn.Key("databricks_mlflow_model"):
31-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("models")).Append(path[1:]...)
32-
case dyn.Key("databricks_mlflow_experiment"):
33-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("experiments")).Append(path[1:]...)
34-
case dyn.Key("databricks_model_serving"):
35-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("model_serving_endpoints")).Append(path[1:]...)
36-
case dyn.Key("databricks_registered_model"):
37-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("registered_models")).Append(path[1:]...)
38-
case dyn.Key("databricks_quality_monitor"):
39-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("quality_monitors")).Append(path[1:]...)
40-
case dyn.Key("databricks_schema"):
41-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("schemas")).Append(path[1:]...)
42-
case dyn.Key("databricks_volume"):
43-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("volumes")).Append(path[1:]...)
44-
case dyn.Key("databricks_cluster"):
45-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("clusters")).Append(path[1:]...)
46-
case dyn.Key("databricks_dashboard"):
47-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("dashboards")).Append(path[1:]...)
48-
case dyn.Key("databricks_app"):
49-
path = dyn.NewPath(dyn.Key("resources"), dyn.Key("apps")).Append(path[1:]...)
50-
default:
51-
// Trigger "key not found" for unknown resource types.
52-
return dyn.GetByPath(root, path)
40+
key, ok := tfToConfigMap[path[0].Key()]
41+
if ok {
42+
path = dyn.NewPath(dyn.Key("resources"), dyn.Key(key)).Append(path[1:]...)
5343
}
5444

5545
return dyn.GetByPath(root, path)

bundle/apps/upload_config.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func (u *uploadConfig) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
2525
var diags diag.Diagnostics
2626
errGroup, ctx := errgroup.WithContext(ctx)
2727

28+
diagsPerApp := make(map[string]diag.Diagnostic)
29+
2830
for key, app := range b.Config.Resources.Apps {
2931
// If the app has a config, we need to deploy it first.
3032
// It means we need to write app.yml file with the content of the config field
@@ -57,20 +59,24 @@ func (u *uploadConfig) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
5759
errGroup.Go(func() error {
5860
err = f.Write(ctx, path.Join(appPath, "app.yml"), buf, filer.OverwriteIfExists)
5961
if err != nil {
60-
diags = append(diags, diag.Diagnostic{
62+
diagsPerApp[key] = diag.Diagnostic{
6163
Severity: diag.Error,
6264
Summary: "Failed to save config",
6365
Detail: fmt.Sprintf("Failed to write %s file: %s", path.Join(app.SourceCodePath, "app.yml"), err),
6466
Locations: b.Config.GetLocations(fmt.Sprintf("resources.apps.%s", key)),
65-
})
67+
}
6668
}
6769
return nil
6870
})
6971
}
7072
}
7173

7274
if err := errGroup.Wait(); err != nil {
73-
return diag.FromErr(err)
75+
return diags.Extend(diag.FromErr(err))
76+
}
77+
78+
for _, diag := range diagsPerApp {
79+
diags = append(diags, diag)
7480
}
7581

7682
return diags

integration/bundle/apps_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ env:
7070
value: "%d"`, job.JobId))
7171

7272
// Try to run the app
73-
_, out, err := runResourceWithStderr(t, ctx, root, "test_app")
74-
require.NoError(t, err)
73+
_, out := runResourceWithStderr(t, ctx, root, "test_app")
7574
require.Contains(t, out, app.Url)
7675

7776
// App should be in the running state
@@ -89,8 +88,7 @@ env:
8988
require.Equal(t, apps.ApplicationStateUnavailable, app.AppStatus.State)
9089

9190
// Try to run the app again
92-
_, out, err = runResourceWithStderr(t, ctx, root, "test_app")
93-
require.NoError(t, err)
91+
_, out = runResourceWithStderr(t, ctx, root, "test_app")
9492
require.Contains(t, out, app.Url)
9593

9694
// App should be in the running state

integration/bundle/helpers_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ func runResource(t testutil.TestingT, ctx context.Context, path, key string) (st
119119
return stdout.String(), err
120120
}
121121

122-
func runResourceWithStderr(t testutil.TestingT, ctx context.Context, path, key string) (string, string, error) {
122+
func runResourceWithStderr(t testutil.TestingT, ctx context.Context, path, key string) (string, string) {
123123
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
124124
ctx = cmdio.NewContext(ctx, cmdio.Default())
125125

126126
c := testcli.NewRunner(t, ctx, "bundle", "run", key)
127127
stdout, stderr, err := c.Run()
128-
return stdout.String(), stderr.String(), err
128+
require.NoError(t, err)
129+
130+
return stdout.String(), stderr.String()
129131
}
130132

131133
func runResourceWithParams(t testutil.TestingT, ctx context.Context, path, key string, params ...string) (string, error) {

0 commit comments

Comments
 (0)