diff --git a/bundle/deploy/terraform/import.go b/bundle/deploy/terraform/import.go deleted file mode 100644 index c15b486bf2d..00000000000 --- a/bundle/deploy/terraform/import.go +++ /dev/null @@ -1,8 +0,0 @@ -package terraform - -type BindOptions struct { - AutoApprove bool - ResourceType string - ResourceKey string - ResourceId string -} diff --git a/bundle/phases/bind.go b/bundle/phases/bind.go index 383feb3417b..d8ff6aeaf3e 100644 --- a/bundle/phases/bind.go +++ b/bundle/phases/bind.go @@ -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" @@ -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 @@ -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) @@ -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)) @@ -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 { diff --git a/cmd/apps/import.go b/cmd/apps/import.go index ea3fce67e93..079c34c274f 100644 --- a/cmd/apps/import.go +++ b/cmd/apps/import.go @@ -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" @@ -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") diff --git a/cmd/bundle/deployment/bind_resource.go b/cmd/bundle/deployment/bind_resource.go index 1a3476775c4..ef38c972362 100644 --- a/cmd/bundle/deployment/bind_resource.go +++ b/cmd/bundle/deployment/bind_resource.go @@ -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" @@ -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 diff --git a/cmd/bundle/deployment/unbind.go b/cmd/bundle/deployment/unbind.go index 132022f0ede..585767676ef 100644 --- a/cmd/bundle/deployment/unbind.go +++ b/cmd/bundle/deployment/unbind.go @@ -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" @@ -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 }