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
8 changes: 0 additions & 8 deletions bundle/deploy/terraform/import.go

This file was deleted.

25 changes: 12 additions & 13 deletions bundle/phases/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config/engine"
"github.com/databricks/cli/bundle/deploy/lock"
"github.com/databricks/cli/bundle/deploy/terraform"
"github.com/databricks/cli/bundle/deployplan"
"github.com/databricks/cli/bundle/statemgmt"
"github.com/databricks/cli/libs/agent"
Expand All @@ -20,7 +19,15 @@ import (
"github.com/databricks/cli/libs/logdiag"
)

func Bind(ctx context.Context, b *bundle.Bundle, opts *terraform.BindOptions, stateDesc *statemgmt.StateDesc) {
type BindOptions struct {
AutoApprove bool
// Group is the bundle resource group, e.g. "jobs".
Group string
ResourceKey string
ResourceId string
}

func Bind(ctx context.Context, b *bundle.Bundle, opts *BindOptions, stateDesc *statemgmt.StateDesc) {
log.Info(ctx, "Phase: bind")
engine := stateDesc.Engine

Expand All @@ -46,11 +53,7 @@ func Bind(ctx context.Context, b *bundle.Bundle, opts *terraform.BindOptions, st
}

// Direct engine: import into temp state, run plan, check for changes.
groupName, ok := terraform.TerraformToGroupName[opts.ResourceType]
if !ok {
groupName = opts.ResourceType
}
resourceKey := fmt.Sprintf("resources.%s.%s", groupName, opts.ResourceKey)
resourceKey := fmt.Sprintf("resources.%s.%s", opts.Group, opts.ResourceKey)
_, statePath := b.StateFilenameDirect(ctx)

result, err := b.DeploymentBundle.Bind(ctx, b.WorkspaceClient(ctx), &b.Config, statePath, resourceKey, opts.ResourceId)
Expand Down Expand Up @@ -116,7 +119,7 @@ func jsonDump(ctx context.Context, v any, field string) string {
return string(b)
}

func Unbind(ctx context.Context, b *bundle.Bundle, tfResourceType, resourceKey string, engine engine.EngineType) {
func Unbind(ctx context.Context, b *bundle.Bundle, group, resourceKey string, engine engine.EngineType) {
log.Info(ctx, "Phase: unbind")

bundle.ApplyContext(ctx, b, lock.Acquire(lock.GoalUnbind))
Expand All @@ -135,11 +138,7 @@ func Unbind(ctx context.Context, b *bundle.Bundle, tfResourceType, resourceKey s
return
}

groupName, ok := terraform.TerraformToGroupName[tfResourceType]
if !ok {
groupName = tfResourceType
}
fullResourceKey := fmt.Sprintf("resources.%s.%s", groupName, resourceKey)
fullResourceKey := fmt.Sprintf("resources.%s.%s", group, resourceKey)
_, statePath := b.StateFilenameDirect(ctx)
err := b.DeploymentBundle.Unbind(ctx, statePath, fullResourceKey)
if err != nil {
Expand Down
15 changes: 5 additions & 10 deletions cmd/apps/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"go.yaml.in/yaml/v3"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/deploy/terraform"
"github.com/databricks/cli/bundle/generate"
"github.com/databricks/cli/bundle/phases"
"github.com/databricks/cli/bundle/resources"
Expand Down Expand Up @@ -331,15 +330,11 @@ func runImport(ctx context.Context, w *databricks.WorkspaceClient, appName, outp
}

// Bind the resource
tfName, ok := terraform.GroupToTerraformName[resource.ResourceDescription().PluralName]
if !ok {
tfName = resource.ResourceDescription().PluralName
}
phases.Bind(ctx, b, &terraform.BindOptions{
AutoApprove: true,
ResourceType: tfName,
ResourceKey: appKey,
ResourceId: app.Name,
phases.Bind(ctx, b, &phases.BindOptions{
AutoApprove: true,
Group: resource.ResourceDescription().PluralName,
ResourceKey: appKey,
ResourceId: app.Name,
}, stateDesc)
if logdiag.HasError(ctx) {
return errors.New("failed to bind resource")
Expand Down
15 changes: 5 additions & 10 deletions cmd/bundle/deployment/bind_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/deploy/terraform"
"github.com/databricks/cli/bundle/phases"
"github.com/databricks/cli/cmd/bundle/utils"
"github.com/databricks/cli/cmd/root"
Expand Down Expand Up @@ -43,15 +42,11 @@ 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, ok := terraform.GroupToTerraformName[resource.ResourceDescription().PluralName]
if !ok {
tfName = resource.ResourceDescription().PluralName
}
phases.Bind(ctx, b, &terraform.BindOptions{
AutoApprove: autoApprove,
ResourceType: tfName,
ResourceKey: resourceKey,
ResourceId: resourceId,
phases.Bind(ctx, b, &phases.BindOptions{
AutoApprove: autoApprove,
Group: resource.ResourceDescription().PluralName,
ResourceKey: resourceKey,
ResourceId: resourceId,
}, stateDesc)
if logdiag.HasError(ctx) {
return root.ErrAlreadyPrinted
Expand Down
8 changes: 1 addition & 7 deletions cmd/bundle/deployment/unbind.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package deployment

import (
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/deploy/terraform"
"github.com/databricks/cli/bundle/phases"
"github.com/databricks/cli/cmd/bundle/utils"
"github.com/databricks/cli/cmd/root"
Expand Down Expand Up @@ -68,12 +67,7 @@ To re-bind the resource later, use:
return err
}

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