Skip to content

Commit 8b63df1

Browse files
nkvuongmgyucht
andauthored
[Feature] Add databricks_app resource (#4099)
## Changes - Added `databricks_app` resource Resolves #4084 ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder - [x] covered with integration tests in `internal/acceptance` - [x] relevant acceptance tests are passing - [x] using Go SDK --------- Co-authored-by: Miles Yucht <[email protected]>
1 parent 964e868 commit 8b63df1

File tree

14 files changed

+909
-8
lines changed

14 files changed

+909
-8
lines changed

docs/data-sources/app.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
subcategory: "Apps"
3+
---
4+
# databricks_app Data Source
5+
6+
-> This feature is in [Public Preview](https://docs.databricks.com/release-notes/release-types.html).
7+
8+
[Databricks Apps](https://docs.databricks.com/en/dev-tools/databricks-apps/index.html) run directly on a customer’s Databricks instance, integrate with their data, use and extend Databricks services, and enable users to interact through single sign-on. This resource creates the application but does not handle app deployment, which should be handled separately as part of your CI/CD pipeline.
9+
10+
This data source allows you to fetch information about a Databricks App.
11+
12+
## Example Usage
13+
14+
```hcl
15+
data "databricks_app" "this" {
16+
name = "my-custom-app"
17+
}
18+
```
19+
20+
## Argument Reference
21+
22+
The following arguments are required:
23+
24+
* `name` - The name of the app.
25+
26+
## Attribute Reference
27+
28+
In addition to all arguments above, the following attributes are exported:
29+
30+
* `app` attribute
31+
* `name` - The name of the app.
32+
* `description` - The description of the app.
33+
* `resources` - A list of resources that the app have access to.
34+
* `compute_status` attribute
35+
* `state` - State of the app compute.
36+
* `message` - Compute status message
37+
* `app_status` attribute
38+
* `state` - State of the application.
39+
* `message` - Application status message
40+
* `url` - The URL of the app once it is deployed.
41+
* `create_time` - The creation time of the app.
42+
* `creator` - The email of the user that created the app.
43+
* `update_time` - The update time of the app.
44+
* `updater` - The email of the user that last updated the app.
45+
* `service_principal_id` - id of the app service principal
46+
* `service_principal_name` - name of the app service principal
47+
* `default_source_code_path` - The default workspace file system path of the source code from which app deployment are created. This field tracks the workspace source code path of the last active deployment.
48+
49+
### resources Attribute
50+
51+
This attribute describes a resource used by the app.
52+
53+
* `name` - The name of the resource.
54+
* `description` - The description of the resource.
55+
56+
Exactly one of the following attributes will be provided:
57+
58+
* `secret` attribute
59+
* `scope` - Scope of the secret to grant permission on.
60+
* `key` - Key of the secret to grant permission on.
61+
* `permission` - Permission to grant on the secret scope. For secrets, only one permission is allowed. Permission must be one of: `READ`, `WRITE`, `MANAGE`.
62+
* `sql_warehouse` attribute
63+
* `id` - Id of the SQL warehouse to grant permission on.
64+
* `permission` - Permission to grant on the SQL warehouse. Supported permissions are: `CAN_MANAGE`, `CAN_USE`, `IS_OWNER`.
65+
* `serving_endpoint` attribute
66+
* `name` - Name of the serving endpoint to grant permission on.
67+
* `permission` - Permission to grant on the serving endpoint. Supported permissions are: `CAN_MANAGE`, `CAN_QUERY`, `CAN_VIEW`.
68+
* `job` attribute
69+
* `id` - Id of the job to grant permission on.
70+
* `permission` - Permissions to grant on the Job. Supported permissions are: `CAN_MANAGE`, `IS_OWNER`, `CAN_MANAGE_RUN`, `CAN_VIEW`.
71+
72+
## Related Resources
73+
74+
The following resources are used in the same context:
75+
76+
* [databricks_app](../resources/app.md) to manage [Databricks Apps](https://docs.databricks.com/en/dev-tools/databricks-apps/index.html).
77+
* [databricks_sql_endpoint](sql_endpoint.md) to manage Databricks SQL [Endpoints](https://docs.databricks.com/sql/admin/sql-endpoints.html).
78+
* [databricks_model_serving](model_serving.md) to serve this model on a Databricks serving endpoint.
79+
* [databricks_secret](secret.md) to manage [secrets](https://docs.databricks.com/security/secrets/index.html#secrets-user-guide) in Databricks workspace.
80+
* [databricks_job](job.md) to manage [Databricks Jobs](https://docs.databricks.com/jobs.html) to run non-interactive code.

docs/data-sources/apps.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
subcategory: "Apps"
3+
---
4+
# databricks_apps Data Source
5+
6+
-> This feature is in [Public Preview](https://docs.databricks.com/release-notes/release-types.html).
7+
8+
[Databricks Apps](https://docs.databricks.com/en/dev-tools/databricks-apps/index.html) run directly on a customer’s Databricks instance, integrate with their data, use and extend Databricks services, and enable users to interact through single sign-on. This resource creates the application but does not handle app deployment, which should be handled separately as part of your CI/CD pipeline.
9+
10+
This data source allows you to fetch information about all Databricks Apps within a workspace.
11+
12+
## Example Usage
13+
14+
```hcl
15+
data "databricks_apps" "all_apps" {}
16+
```
17+
18+
## Attribute Reference
19+
20+
The following attributes are exported:
21+
22+
* `apps` - A list of [databricks_app](../resources/app.md) resources.
23+
* `name` - The name of the app.
24+
* `description` - The description of the app.
25+
* `resources` - A list of resources that the app have access to.
26+
* `compute_status` attribute
27+
* `state` - State of the app compute.
28+
* `message` - Compute status message
29+
* `app_status` attribute
30+
* `state` - State of the application.
31+
* `message` - Application status message
32+
* `url` - The URL of the app once it is deployed.
33+
* `create_time` - The creation time of the app.
34+
* `creator` - The email of the user that created the app.
35+
* `update_time` - The update time of the app.
36+
* `updater` - The email of the user that last updated the app.
37+
* `service_principal_id` - id of the app service principal
38+
* `service_principal_name` - name of the app service principal
39+
* `default_source_code_path` - The default workspace file system path of the source code from which app deployment are created. This field tracks the workspace source code path of the last active deployment.
40+
41+
### resources Attribute
42+
43+
This attribute describes a resource used by the app.
44+
45+
* `name` - The name of the resource.
46+
* `description` - The description of the resource.
47+
48+
Exactly one of the following attributes will be provided:
49+
50+
* `secret` attribute
51+
* `scope` - Scope of the secret to grant permission on.
52+
* `key` - Key of the secret to grant permission on.
53+
* `permission` - Permission to grant on the secret scope. For secrets, only one permission is allowed. Permission must be one of: `READ`, `WRITE`, `MANAGE`.
54+
* `sql_warehouse` attribute
55+
* `id` - Id of the SQL warehouse to grant permission on.
56+
* `permission` - Permission to grant on the SQL warehouse. Supported permissions are: `CAN_MANAGE`, `CAN_USE`, `IS_OWNER`.
57+
* `serving_endpoint` attribute
58+
* `name` - Name of the serving endpoint to grant permission on.
59+
* `permission` - Permission to grant on the serving endpoint. Supported permissions are: `CAN_MANAGE`, `CAN_QUERY`, `CAN_VIEW`.
60+
* `job` attribute
61+
* `id` - Id of the job to grant permission on.
62+
* `permission` - Permissions to grant on the Job. Supported permissions are: `CAN_MANAGE`, `IS_OWNER`, `CAN_MANAGE_RUN`, `CAN_VIEW`.
63+
64+
## Related Resources
65+
66+
The following resources are used in the same context:
67+
68+
* [databricks_app](../resources/app.md) to manage [Databricks Apps](https://docs.databricks.com/en/dev-tools/databricks-apps/index.html).
69+
* [databricks_sql_endpoint](sql_endpoint.md) to manage Databricks SQL [Endpoints](https://docs.databricks.com/sql/admin/sql-endpoints.html).
70+
* [databricks_model_serving](model_serving.md) to serve this model on a Databricks serving endpoint.
71+
* [databricks_secret](secret.md) to manage [secrets](https://docs.databricks.com/security/secrets/index.html#secrets-user-guide) in Databricks workspace.
72+
* [databricks_job](job.md) to manage [Databricks Jobs](https://docs.databricks.com/jobs.html) to run non-interactive code.

docs/resources/app.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
subcategory: "Apps"
3+
---
4+
# databricks_app Resource
5+
6+
-> This feature is in [Public Preview](https://docs.databricks.com/release-notes/release-types.html).
7+
8+
[Databricks Apps](https://docs.databricks.com/en/dev-tools/databricks-apps/index.html) run directly on a customer’s Databricks instance, integrate with their data, use and extend Databricks services, and enable users to interact through single sign-on. This resource creates the application but does not handle app deployment, which should be handled separately as part of your CI/CD pipeline.
9+
10+
## Example Usage
11+
12+
```hcl
13+
resource "databricks_app" "this" {
14+
name = "my-custom-app"
15+
description = "My app"
16+
resources = [{
17+
name = "sql-warehouse"
18+
sql_warehouse = {
19+
id = "e9ca293f79a74b5c"
20+
permission = "CAN_MANAGE"
21+
}
22+
},
23+
{
24+
name = "serving-endpoint"
25+
serving_endpoint = {
26+
name = "databricks-meta-llama-3-1-70b-instruct"
27+
permission = "CAN_MANAGE"
28+
}
29+
},
30+
{
31+
name = "job"
32+
job = {
33+
id = "1234"
34+
permission = "CAN_MANAGE"
35+
}
36+
}]
37+
}
38+
```
39+
40+
## Argument Reference
41+
42+
The following arguments are required:
43+
44+
* `name` - (Required) The name of the app. The name must contain only lowercase alphanumeric characters and hyphens. It must be unique within the workspace.
45+
* `description` - (Optional) The description of the app.
46+
* `resources` - (Optional) A list of resources that the app have access to.
47+
48+
### resources Configuration Attribute
49+
50+
This attribute describes a resource used by the app.
51+
52+
* `name` - (Required) The name of the resource.
53+
* `description` - (Optional) The description of the resource.
54+
55+
Exactly one of the following attributes must be provided:
56+
57+
* `secret` attribute
58+
* `scope` - Scope of the secret to grant permission on.
59+
* `key` - Key of the secret to grant permission on.
60+
* `permission` - Permission to grant on the secret scope. For secrets, only one permission is allowed. Permission must be one of: `READ`, `WRITE`, `MANAGE`.
61+
* `sql_warehouse` attribute
62+
* `id` - Id of the SQL warehouse to grant permission on.
63+
* `permission` - Permission to grant on the SQL warehouse. Supported permissions are: `CAN_MANAGE`, `CAN_USE`, `IS_OWNER`.
64+
* `serving_endpoint` attribute
65+
* `name` - Name of the serving endpoint to grant permission on.
66+
* `permission` - Permission to grant on the serving endpoint. Supported permissions are: `CAN_MANAGE`, `CAN_QUERY`, `CAN_VIEW`.
67+
* `job` attribute
68+
* `id` - Id of the job to grant permission on.
69+
* `permission` - Permissions to grant on the Job. Supported permissions are: `CAN_MANAGE`, `IS_OWNER`, `CAN_MANAGE_RUN`, `CAN_VIEW`.
70+
71+
## Attribute Reference
72+
73+
In addition to all arguments above, the following attributes are exported:
74+
75+
* `compute_status` attribute
76+
* `state` - State of the app compute.
77+
* `message` - Compute status message
78+
* `app_status` attribute
79+
* `state` - State of the application.
80+
* `message` - Application status message
81+
* `url` - The URL of the app once it is deployed.
82+
* `create_time` - The creation time of the app.
83+
* `creator` - The email of the user that created the app.
84+
* `update_time` - The update time of the app.
85+
* `updater` - The email of the user that last updated the app.
86+
* `service_principal_id` - id of the app service principal
87+
* `service_principal_name` - name of the app service principal
88+
* `default_source_code_path` - The default workspace file system path of the source code from which app deployment are created. This field tracks the workspace source code path of the last active deployment.
89+
90+
## Import
91+
92+
This resource can be imported by name:
93+
94+
```hcl
95+
import {
96+
to = databricks_app.this
97+
id = "<app_name>"
98+
}
99+
```
100+
101+
or using the `terraform` CLI:
102+
103+
```bash
104+
terraform import databricks_app.this <app_name>
105+
```
106+
107+
## Related Resources
108+
109+
The following resources are used in the same context:
110+
111+
* [databricks_sql_endpoint](sql_endpoint.md) to manage Databricks SQL [Endpoints](https://docs.databricks.com/sql/admin/sql-endpoints.html).
112+
* [databricks_model_serving](model_serving.md) to serve this model on a Databricks serving endpoint.
113+
* [databricks_secret](secret.md) to manage [secrets](https://docs.databricks.com/security/secrets/index.html#secrets-user-guide) in Databricks workspace.
114+
* [databricks_job](job.md) to manage [Databricks Jobs](https://docs.databricks.com/jobs.html) to run non-interactive code.

docs/resources/permissions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ Valid [permission levels](https://docs.databricks.com/security/access-control/wo
423423

424424
A folder could be specified by using either `directory_path` or `directory_id` attribute. The value for the `directory_id` is the object ID of the resource in the Databricks Workspace that is exposed as `object_id` attribute of the `databricks_directory` resource as shown below.
425425

426-
427426
```hcl
428427
resource "databricks_group" "auto" {
429428
display_name = "Automation"
@@ -912,6 +911,7 @@ One type argument and at least one access control block argument are required.
912911

913912
Exactly one of the following arguments is required:
914913

914+
- `app_name` - [app](app.md) name
915915
- `cluster_id` - [cluster](cluster.md) id
916916
- `cluster_policy_id` - [cluster policy](cluster_policy.md) id
917917
- `instance_pool_id` - [instance pool](instance_pool.md) id

internal/acceptance/permissions_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,3 +947,25 @@ func TestAccPermissions_Query(t *testing.T) {
947947
ExpectError: regexp.MustCompile("cannot remove management permissions for the current user for query, allowed levels: CAN_MANAGE"),
948948
})
949949
}
950+
951+
func TestAccPermissions_App(t *testing.T) {
952+
loadDebugEnvIfRunsFromIDE(t, "workspace")
953+
if IsGcp(t) {
954+
Skipf(t)("not available on GCP")
955+
}
956+
queryTemplate := `
957+
resource "databricks_app" "this" {
958+
name = "{var.RANDOM}"
959+
description = "Test app"
960+
}`
961+
WorkspaceLevel(t, Step{
962+
Template: queryTemplate + makePermissionsTestStage("app_name", "databricks_app.this.name", groupPermissions("CAN_USE")),
963+
}, Step{
964+
Template: queryTemplate + makePermissionsTestStage("app_name", "databricks_app.this.name",
965+
currentPrincipalPermission(t, "CAN_MANAGE"), groupPermissions("CAN_USE", "CAN_MANAGE")),
966+
}, Step{
967+
Template: queryTemplate + makePermissionsTestStage("app_name", "databricks_app.this.name",
968+
currentPrincipalPermission(t, "CAN_USE"), groupPermissions("CAN_USE", "CAN_MANAGE")),
969+
ExpectError: regexp.MustCompile("cannot remove management permissions for the current user for apps, allowed levels: CAN_MANAGE"),
970+
})
971+
}

internal/providers/pluginfw/pluginfw_rollout_utils.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"slices"
1313
"strings"
1414

15+
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/products/app"
1516
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/products/catalog"
1617
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/products/cluster"
1718
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/products/library"
@@ -26,29 +27,35 @@ import (
2627
)
2728

2829
// List of resources that have been migrated from SDK V2 to plugin framework
30+
// Keep this list sorted.
2931
var migratedResources = []func() resource.Resource{
30-
qualitymonitor.ResourceQualityMonitor,
3132
library.ResourceLibrary,
33+
qualitymonitor.ResourceQualityMonitor,
3234
}
3335

3436
// List of data sources that have been migrated from SDK V2 to plugin framework
37+
// Keep this list sorted.
3538
var migratedDataSources = []func() datasource.DataSource{
3639
volume.DataSourceVolumes,
3740
}
3841

3942
// List of resources that have been onboarded to the plugin framework - not migrated from sdkv2.
43+
// Keep this list sorted.
4044
var pluginFwOnlyResources = []func() resource.Resource{
41-
// TODO Add resources here
42-
sharing.ResourceShare, // Using the staging name (with pluginframework suffix)
45+
app.ResourceApp,
46+
sharing.ResourceShare,
4347
}
4448

4549
// List of data sources that have been onboarded to the plugin framework - not migrated from sdkv2.
50+
// Keep this list sorted.
4651
var pluginFwOnlyDataSources = []func() datasource.DataSource{
47-
serving.DataSourceServingEndpoints,
52+
app.DataSourceApp,
53+
app.DataSourceApps,
54+
catalog.DataSourceFunctions,
55+
notificationdestinations.DataSourceNotificationDestinations,
4856
registered_model.DataSourceRegisteredModel,
4957
registered_model.DataSourceRegisteredModelVersions,
50-
notificationdestinations.DataSourceNotificationDestinations,
51-
catalog.DataSourceFunctions,
58+
serving.DataSourceServingEndpoints,
5259
// TODO: Add DataSourceCluster into migratedDataSources after fixing unit tests.
5360
cluster.DataSourceCluster, // Using the staging name (with pluginframework suffix)
5461
sharing.DataSourceShare, // Using the staging name (with pluginframework suffix)

0 commit comments

Comments
 (0)