Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nkvuong committed Nov 15, 2024
1 parent 7449b45 commit eda8a91
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
27 changes: 21 additions & 6 deletions apps/resource_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apps
import (
"context"
"log"
"regexp"
"time"

"github.com/databricks/databricks-sdk-go/service/apps"
Expand All @@ -11,8 +12,10 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

const defaultAppProvisionTimeout = 10 * time.Minute
const deleteCallTimeout = 10 * time.Second
const (
defaultAppProvisionTimeout = 10 * time.Minute
deleteCallTimeout = 10 * time.Second
)

var appAliasMap = map[string]string{
"resources": "resource",
Expand All @@ -31,12 +34,23 @@ func (appStruct) Aliases() map[string]map[string]string {
func (appStruct) CustomizeSchema(s *common.CustomizableSchema) *common.CustomizableSchema {

// Required fields & validation
s.SchemaPath("name").SetRequired().SetForceNew().SetValidateFunc(validation.StringLenBetween(2, 30))
s.SchemaPath("name").SetRequired().SetForceNew().SetValidateFunc(validation.StringMatch(regexp.MustCompile("^[a-z-]{2,30}$"), "name must contain only lowercase alphanumeric characters and hyphens, and be between 2 and 30 characters long"))

// Computed fields
for _, p := range []string{"active_deployment", "app_status", "compute_status", "create_time", "creator",
"default_source_code_path", "pending_deployment", "service_principal_id", "service_principal_name",
"update_time", "updater", "url"} {
for _, p := range []string{
"active_deployment",
"app_status",
"compute_status",
"create_time",
"creator",
"default_source_code_path",
"pending_deployment",
"service_principal_id",
"service_principal_name",
"update_time",
"updater",
"url",
} {
s.SchemaPath(p).SetComputed()
}
return s
Expand All @@ -61,6 +75,7 @@ func ResourceApp() common.Resource {
if err != nil {
return err
}
// wait for up to the create timeout, accounting for the deletion on failure.
app, err := wait.GetWithTimeout(d.Timeout(schema.TimeoutCreate) - deleteCallTimeout)
if err != nil {
log.Printf("[ERROR] Error waiting for app to be created: %s", err.Error())
Expand Down
14 changes: 13 additions & 1 deletion docs/resources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ Apps run directly on a customer’s Databricks instance, integrate with their da
resource "databricks_app" "this" {
name = "my-custom-app"
description = "My app"
sql_warehouse {
id = "e9ca293f79a74b5c"
permission = "CAN_MANAGE"
}
serving_endpoint {
name = "databricks-meta-llama-3-1-70b-instruct"
permission = "CAN_MANAGE"
}
job {
id = "1234"
permission = "CAN_MANAGE"
}
}
```

Expand All @@ -21,7 +33,7 @@ resource "databricks_app" "this" {
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` - The description of the app.
* `description` - (Optional) The description of the app.

One or more `resource` block with the following arguments:

Expand Down

0 comments on commit eda8a91

Please sign in to comment.