diff --git a/bundle/apps/interpolate_variables.go b/bundle/apps/interpolate_variables.go index 206609a12..f4860127b 100644 --- a/bundle/apps/interpolate_variables.go +++ b/bundle/apps/interpolate_variables.go @@ -19,37 +19,27 @@ func (i *interpolateVariables) Apply(ctx context.Context, b *bundle.Bundle) diag dyn.Key("config"), ) + tfToConfigMap := map[string]string{ + "databricks_pipeline": "pipelines", + "databricks_job": "jobs", + "databricks_mlflow_model": "models", + "databricks_mlflow_experiment": "experiments", + "databricks_model_serving": "model_serving_endpoints", + "databricks_registered_model": "registered_models", + "databricks_quality_monitor": "quality_monitors", + "databricks_schema": "schemas", + "databricks_volume": "volumes", + "databricks_cluster": "clusters", + "databricks_dashboard": "dashboards", + "databricks_app": "apps", + } + err := b.Config.Mutate(func(root dyn.Value) (dyn.Value, error) { return dyn.MapByPattern(root, pattern, func(p dyn.Path, v dyn.Value) (dyn.Value, error) { return dynvar.Resolve(v, func(path dyn.Path) (dyn.Value, error) { - switch path[0] { - case dyn.Key("databricks_pipeline"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("pipelines")).Append(path[1:]...) - case dyn.Key("databricks_job"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("jobs")).Append(path[1:]...) - case dyn.Key("databricks_mlflow_model"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("models")).Append(path[1:]...) - case dyn.Key("databricks_mlflow_experiment"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("experiments")).Append(path[1:]...) - case dyn.Key("databricks_model_serving"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("model_serving_endpoints")).Append(path[1:]...) - case dyn.Key("databricks_registered_model"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("registered_models")).Append(path[1:]...) - case dyn.Key("databricks_quality_monitor"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("quality_monitors")).Append(path[1:]...) - case dyn.Key("databricks_schema"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("schemas")).Append(path[1:]...) - case dyn.Key("databricks_volume"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("volumes")).Append(path[1:]...) - case dyn.Key("databricks_cluster"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("clusters")).Append(path[1:]...) - case dyn.Key("databricks_dashboard"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("dashboards")).Append(path[1:]...) - case dyn.Key("databricks_app"): - path = dyn.NewPath(dyn.Key("resources"), dyn.Key("apps")).Append(path[1:]...) - default: - // Trigger "key not found" for unknown resource types. - return dyn.GetByPath(root, path) + key, ok := tfToConfigMap[path[0].Key()] + if ok { + path = dyn.NewPath(dyn.Key("resources"), dyn.Key(key)).Append(path[1:]...) } return dyn.GetByPath(root, path) diff --git a/bundle/apps/upload_config.go b/bundle/apps/upload_config.go index 4f70976a3..4eb90f905 100644 --- a/bundle/apps/upload_config.go +++ b/bundle/apps/upload_config.go @@ -25,6 +25,8 @@ func (u *uploadConfig) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos var diags diag.Diagnostics errGroup, ctx := errgroup.WithContext(ctx) + diagsPerApp := make(map[string]diag.Diagnostic) + for key, app := range b.Config.Resources.Apps { // If the app has a config, we need to deploy it first. // It means we need to write app.yml file with the content of the config field @@ -57,12 +59,12 @@ func (u *uploadConfig) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos errGroup.Go(func() error { err = f.Write(ctx, path.Join(appPath, "app.yml"), buf, filer.OverwriteIfExists) if err != nil { - diags = append(diags, diag.Diagnostic{ + diagsPerApp[key] = diag.Diagnostic{ Severity: diag.Error, Summary: "Failed to save config", Detail: fmt.Sprintf("Failed to write %s file: %s", path.Join(app.SourceCodePath, "app.yml"), err), Locations: b.Config.GetLocations(fmt.Sprintf("resources.apps.%s", key)), - }) + } } return nil }) @@ -70,7 +72,11 @@ func (u *uploadConfig) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos } if err := errGroup.Wait(); err != nil { - return diag.FromErr(err) + return diags.Extend(diag.FromErr(err)) + } + + for _, diag := range diagsPerApp { + diags = append(diags, diag) } return diags diff --git a/integration/bundle/apps_test.go b/integration/bundle/apps_test.go index 0707403dc..7fc565e91 100644 --- a/integration/bundle/apps_test.go +++ b/integration/bundle/apps_test.go @@ -70,8 +70,7 @@ env: value: "%d"`, job.JobId)) // Try to run the app - _, out, err := runResourceWithStderr(t, ctx, root, "test_app") - require.NoError(t, err) + _, out := runResourceWithStderr(t, ctx, root, "test_app") require.Contains(t, out, app.Url) // App should be in the running state @@ -89,8 +88,7 @@ env: require.Equal(t, apps.ApplicationStateUnavailable, app.AppStatus.State) // Try to run the app again - _, out, err = runResourceWithStderr(t, ctx, root, "test_app") - require.NoError(t, err) + _, out = runResourceWithStderr(t, ctx, root, "test_app") require.Contains(t, out, app.Url) // App should be in the running state diff --git a/integration/bundle/helpers_test.go b/integration/bundle/helpers_test.go index c62c79307..a537ca351 100644 --- a/integration/bundle/helpers_test.go +++ b/integration/bundle/helpers_test.go @@ -119,13 +119,15 @@ func runResource(t testutil.TestingT, ctx context.Context, path, key string) (st return stdout.String(), err } -func runResourceWithStderr(t testutil.TestingT, ctx context.Context, path, key string) (string, string, error) { +func runResourceWithStderr(t testutil.TestingT, ctx context.Context, path, key string) (string, string) { ctx = env.Set(ctx, "BUNDLE_ROOT", path) ctx = cmdio.NewContext(ctx, cmdio.Default()) c := testcli.NewRunner(t, ctx, "bundle", "run", key) stdout, stderr, err := c.Run() - return stdout.String(), stderr.String(), err + require.NoError(t, err) + + return stdout.String(), stderr.String() } func runResourceWithParams(t testutil.TestingT, ctx context.Context, path, key string, params ...string) (string, error) {