Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### New Features and Improvements

* Fixed `databricks_app` producing "inconsistent result after apply" when the app is in a space and `resources`, `user_api_scopes`, or `budget_policy_id` are populated by the server from the space configuration.

### Bug Fixes

### Documentation
Expand Down
6 changes: 3 additions & 3 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ The following arguments are required:

* `name` - (Required) The name of the app. The name must contain only lowercase alphanumeric characters and hyphens. It must be unique within the workspace.
* `description` - (Optional) The description of the app.
* `budget_policy_id` - (Optional) The Budget Policy ID set for this resource.
* `resources` - (Optional) A list of resources that the app have access to.
* `user_api_scopes` - (Optional) A list of api scopes granted to the user access token.
* `budget_policy_id` - (Optional) The Budget Policy ID set for this resource. When the app is in a space, this may be automatically populated from the space's usage policy.
* `resources` - (Optional) A list of resources that the app has access to. When the app is in a space, this may be automatically populated from the space's resource configuration.
* `user_api_scopes` - (Optional) A list of api scopes granted to the user access token. When the app is in a space, this may be automatically populated from the space's configuration.
* `compute_size` - (Optional) A string specifying compute size for the App. Possible values are `MEDIUM`, `LARGE`.

### resources Configuration Attribute
Expand Down
3 changes: 3 additions & 0 deletions internal/providers/pluginfw/products/app/resource_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func (a AppResource) ApplySchemaCustomizations(s map[string]tfschema.AttributeBu
s["no_compute"] = s["no_compute"].SetOptional()
s["provider_config"] = s["provider_config"].SetOptional()
s["compute_size"] = s["compute_size"].SetComputed()
s["resources"] = s["resources"].SetComputed()
s["user_api_scopes"] = s["user_api_scopes"].SetComputed()
s["budget_policy_id"] = s["budget_policy_id"].SetComputed()
s = apps_tf.App{}.ApplySchemaCustomizations(s)
return s
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,53 @@ func TestAccAppResource_NoCompute(t *testing.T) {
})
}

func TestAccAppResource_InSpace(t *testing.T) {
acceptance.LoadWorkspaceEnv(t)
if acceptance.IsGcp(t) {
acceptance.Skipf(t)("not available on GCP")
}
spaceTemplate := `
resource "databricks_secret_scope" "space" {
name = "tf-space-{var.STICKY_RANDOM}"
}

resource "databricks_secret" "space" {
scope = databricks_secret_scope.space.name
key = "tf-{var.STICKY_RANDOM}"
string_value = "secret"
}

resource "databricks_app_space" "this" {
name = "tf-{var.STICKY_RANDOM}"
description = "Space for acceptance test"
resources = [{
name = "my-secret"
secret = {
scope = databricks_secret_scope.space.name
key = databricks_secret.space.key
permission = "READ"
}
}]
user_api_scopes = ["sql"]
}

resource "databricks_app" "this" {
name = "tf-{var.STICKY_RANDOM}"
description = "App in a space"
space = databricks_app_space.this.name
}`
acceptance.WorkspaceLevel(t, acceptance.Step{
Template: spaceTemplate,
ExpectNonEmptyPlan: true,
Check: func(s *terraform.State) error {
attrs := s.RootModule().Resources["databricks_app.this"].Primary.Attributes
assert.NotEmpty(t, attrs["resources.#"], "resources should be populated from the space")
assert.NotEmpty(t, attrs["user_api_scopes.#"], "user_api_scopes should be populated from the space")
return nil
},
})
}

var deletedOutsideTemplate = `
resource "databricks_secret_scope" "this" {
name = "tf-{var.STICKY_RANDOM}"
Expand Down
24 changes: 24 additions & 0 deletions internal/providers/pluginfw/products/app/resource_app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package app

import (
"context"
"testing"

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAppResourceSchema_SpaceInheritedFieldsAreComputed(t *testing.T) {
ctx := context.Background()
r := ResourceApp()
resp := &resource.SchemaResponse{}
r.Schema(ctx, resource.SchemaRequest{}, resp)

for _, field := range []string{"resources", "user_api_scopes", "budget_policy_id"} {
attr, ok := resp.Schema.Attributes[field]
require.True(t, ok, "field %s should exist in schema", field)
assert.True(t, attr.IsOptional(), "field %s should be optional", field)
assert.True(t, attr.IsComputed(), "field %s should be computed (server-populated from space)", field)
}
}