Skip to content
Merged
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
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* engine/direct: Fix 400 error when deploying grants with ALL_PRIVILEGES ([#4801](https://github.com/databricks/cli/pull/4801))
* Deduplicate grant entries with duplicate principals or privileges during initialization ([#4801](https://github.com/databricks/cli/pull/4801))
* engine/direct: Fix unwanted recreation of secret scopes when scope_backend_type is not set ([#4834](https://github.com/databricks/cli/pull/4834))
* engine/direct: Fix bind and unbind for non-Terraform resources ([#4850](https://github.com/databricks/cli/pull/4850))
* engine/direct: Fix deploying removed principals ([#4824](https://github.com/databricks/cli/pull/4824))

### Dependency updates
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bundle:
name: test-bundle-$UNIQUE_NAME

resources:
catalogs:
foo:
name: test-catalog-$UNIQUE_NAME
comment: This is a test catalog
6 changes: 6 additions & 0 deletions acceptance/bundle/deployment/bind/catalog/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions acceptance/bundle/deployment/bind/catalog/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

>>> [CLI] catalogs create test-catalog-[UNIQUE_NAME]
{
"comment": null,
"name": "test-catalog-[UNIQUE_NAME]"
}

>>> [CLI] bundle deployment bind foo test-catalog-[UNIQUE_NAME] --auto-approve
Updating deployment state...
Successfully bound catalog with an id 'test-catalog-[UNIQUE_NAME]'
Run 'bundle deploy' to deploy changes to your workspace

=== Deploy bundle
>>> [CLI] bundle deploy --force-lock --auto-approve
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> [CLI] catalogs get test-catalog-[UNIQUE_NAME]
{
"comment": "This is a test catalog",
"name": "test-catalog-[UNIQUE_NAME]"
}

=== Unbind catalog
>>> [CLI] bundle deployment unbind foo
Updating deployment state...

=== Destroy bundle
>>> [CLI] bundle destroy --auto-approve
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default

Deleting files...
Destroy complete!

=== Read the pre-defined catalog again (expecting it still exists):
>>> [CLI] catalogs get test-catalog-[UNIQUE_NAME]
{
"comment": "This is a test catalog",
"name": "test-catalog-[UNIQUE_NAME]"
}

=== Test cleanup
>>> [CLI] catalogs delete test-catalog-[UNIQUE_NAME] --force
0
26 changes: 26 additions & 0 deletions acceptance/bundle/deployment/bind/catalog/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cleanup() {
title "Test cleanup"
trace $CLI catalogs delete "test-catalog-$UNIQUE_NAME" --force
echo $?
}
trap cleanup EXIT

envsubst < databricks.yml.tmpl > databricks.yml

trace $CLI catalogs create "test-catalog-$UNIQUE_NAME" | jq '{comment, name}'

trace $CLI bundle deployment bind foo "test-catalog-$UNIQUE_NAME" --auto-approve

title "Deploy bundle"
trace $CLI bundle deploy --force-lock --auto-approve

trace $CLI catalogs get "test-catalog-$UNIQUE_NAME" | jq '{comment, name}'

title "Unbind catalog"
trace $CLI bundle deployment unbind foo

title "Destroy bundle"
trace $CLI bundle destroy --auto-approve

title "Read the pre-defined catalog again (expecting it still exists): "
trace $CLI catalogs get "test-catalog-$UNIQUE_NAME" | jq '{comment, name}'
11 changes: 11 additions & 0 deletions acceptance/bundle/deployment/bind/catalog/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Local = true
Cloud = true
RequiresUnityCatalog = true

Ignore = [
".databricks",
"databricks.yml",
]

[EnvMatrix]
DATABRICKS_BUNDLE_ENGINE = ["direct"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bundle:
name: test-bundle-$UNIQUE_NAME

resources:
external_locations:
test_location:
name: test-location-$UNIQUE_NAME
url: s3://test-bucket/path-dabs
credential_name: test_storage_credential
comment: "Test external location from DABs"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions acceptance/bundle/deployment/bind/external_location/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

>>> [CLI] external-locations create test-location-[UNIQUE_NAME] s3://test-bucket/path test_storage_credential
{
"name": "test-location-[UNIQUE_NAME]",
"url": "s3://test-bucket/path",
"credential_name": "test_storage_credential"
}

>>> [CLI] bundle deployment bind test_location test-location-[UNIQUE_NAME] --auto-approve
Updating deployment state...
Successfully bound external_location with an id 'test-location-[UNIQUE_NAME]'
Run 'bundle deploy' to deploy changes to your workspace

=== Deploy bundle
>>> [CLI] bundle deploy --force-lock --auto-approve
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> [CLI] external-locations get test-location-[UNIQUE_NAME]
{
"name": "test-location-[UNIQUE_NAME]",
"url": "s3://test-bucket/path-dabs",
"credential_name": "test_storage_credential"
}

=== Unbind external location
>>> [CLI] bundle deployment unbind test_location
Updating deployment state...

=== Destroy bundle
>>> [CLI] bundle destroy --auto-approve
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default

Deleting files...
Destroy complete!

=== Read the pre-defined external location again (expecting it still exists):
>>> [CLI] external-locations get test-location-[UNIQUE_NAME]
{
"name": "test-location-[UNIQUE_NAME]",
"url": "s3://test-bucket/path-dabs",
"credential_name": "test_storage_credential"
}

=== Test cleanup
>>> [CLI] external-locations delete test-location-[UNIQUE_NAME]
0
26 changes: 26 additions & 0 deletions acceptance/bundle/deployment/bind/external_location/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cleanup() {
title "Test cleanup"
trace $CLI external-locations delete "test-location-$UNIQUE_NAME"
echo $?
}
trap cleanup EXIT

envsubst < databricks.yml.tmpl > databricks.yml

trace $CLI external-locations create "test-location-$UNIQUE_NAME" "s3://test-bucket/path" "test_storage_credential" | jq '{name, url, credential_name}'

trace $CLI bundle deployment bind test_location "test-location-$UNIQUE_NAME" --auto-approve

title "Deploy bundle"
trace $CLI bundle deploy --force-lock --auto-approve

trace $CLI external-locations get "test-location-$UNIQUE_NAME" | jq '{name, url, credential_name}'

title "Unbind external location"
trace $CLI bundle deployment unbind test_location

title "Destroy bundle"
trace $CLI bundle destroy --auto-approve

title "Read the pre-defined external location again (expecting it still exists): "
trace $CLI external-locations get "test-location-$UNIQUE_NAME" | jq '{name, url, credential_name}'
10 changes: 10 additions & 0 deletions acceptance/bundle/deployment/bind/external_location/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Local = true
Cloud = false

Ignore = [
".databricks",
"databricks.yml",
]

[EnvMatrix]
DATABRICKS_BUNDLE_ENGINE = ["direct"]
10 changes: 8 additions & 2 deletions bundle/phases/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func Bind(ctx context.Context, b *bundle.Bundle, opts *terraform.BindOptions) {
if engine.IsDirect() {
// Direct engine: import into temp state, run plan, check for changes
// This follows the same pattern as terraform import
groupName := terraform.TerraformToGroupName[opts.ResourceType]
groupName, ok := terraform.TerraformToGroupName[opts.ResourceType]
if !ok {
groupName = opts.ResourceType
}
resourceKey := fmt.Sprintf("resources.%s.%s", groupName, opts.ResourceKey)
_, statePath := b.StateFilenameDirect(ctx)

Expand Down Expand Up @@ -136,7 +139,10 @@ func Unbind(ctx context.Context, b *bundle.Bundle, bundleType, tfResourceType, r
}()

if engine.IsDirect() {
groupName := terraform.TerraformToGroupName[tfResourceType]
groupName, ok := terraform.TerraformToGroupName[tfResourceType]
if !ok {
groupName = tfResourceType
}
fullResourceKey := fmt.Sprintf("resources.%s.%s", groupName, resourceKey)
_, statePath := b.StateFilenameDirect(ctx)
err := b.DeploymentBundle.Unbind(ctx, statePath, fullResourceKey)
Expand Down
5 changes: 4 additions & 1 deletion cmd/apps/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ func runImport(ctx context.Context, w *databricks.WorkspaceClient, appName, outp
}

// Bind the resource
tfName := terraform.GroupToTerraformName[resource.ResourceDescription().PluralName]
tfName, ok := terraform.GroupToTerraformName[resource.ResourceDescription().PluralName]
if !ok {
tfName = resource.ResourceDescription().PluralName
}
phases.Bind(ctx, b, &terraform.BindOptions{
AutoApprove: true,
ResourceType: tfName,
Expand Down
5 changes: 4 additions & 1 deletion cmd/bundle/deployment/bind_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ func BindResource(cmd *cobra.Command, resourceKey, resourceId string, autoApprov
return fmt.Errorf("%s with an id '%s' is not found", resource.ResourceDescription().SingularName, resourceId)
}

tfName := terraform.GroupToTerraformName[resource.ResourceDescription().PluralName]
tfName, ok := terraform.GroupToTerraformName[resource.ResourceDescription().PluralName]
if !ok {
tfName = resource.ResourceDescription().PluralName
}
phases.Bind(ctx, b, &terraform.BindOptions{
AutoApprove: autoApprove,
ResourceType: tfName,
Expand Down
5 changes: 4 additions & 1 deletion cmd/bundle/deployment/unbind.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ To re-bind the resource later, use:
}

rd := resource.ResourceDescription()
tfName := terraform.GroupToTerraformName[rd.PluralName]
tfName, ok := terraform.GroupToTerraformName[rd.PluralName]
if !ok {
tfName = rd.PluralName
}
phases.Unbind(ctx, b, rd.SingularName, tfName, args[0])
if logdiag.HasError(ctx) {
return root.ErrAlreadyPrinted
Expand Down
Loading