Skip to content

Commit 15eb802

Browse files
authored
direct: Implement --fail-on-active-runs (#4063)
1 parent 7f65a43 commit 15eb802

File tree

7 files changed

+27
-17
lines changed

7 files changed

+27
-17
lines changed

acceptance/bundle/deploy/fail-on-active-runs/out.test.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/deploy/fail-on-active-runs/test.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
RecordRequests = true
22

3-
# --fail-on-active-runs not implemented yet
4-
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["terraform"]
5-
63
[[Server]]
74
Pattern = "GET /api/2.2/jobs/runs/list"
85
Response.Body = '''

acceptance/pipelines/deploy/fail-on-active-runs/out.test.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/pipelines/deploy/fail-on-active-runs/test.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Deploy relies on terraform.CheckRunningResource()
2-
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["terraform"]
3-
41
# Cycling between states not implemented yet
52
# spec to avoid "pipeline spec is nil" error
63

bundle/phases/plan.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/databricks/cli/bundle/deploy/terraform"
1313
"github.com/databricks/cli/bundle/deployplan"
1414
"github.com/databricks/cli/bundle/libraries"
15+
"github.com/databricks/cli/bundle/statemgmt"
1516
"github.com/databricks/cli/bundle/trampoline"
1617
"github.com/databricks/cli/libs/dyn"
1718
"github.com/databricks/cli/libs/logdiag"
@@ -24,7 +25,7 @@ func DeployPrepare(ctx context.Context, b *bundle.Bundle, isPlan bool, engine en
2425
terraform.CheckDashboardsModifiedRemotely(isPlan, engine),
2526
deploy.StatePull(),
2627
mutator.ValidateGitDetails(),
27-
terraform.CheckRunningResource(),
28+
statemgmt.CheckRunningResource(engine),
2829

2930
// libraries.CheckForSameNameLibraries() needs to be run after we expand glob references so we
3031
// know what are the actual library paths.

bundle/deploy/terraform/check_running_resources.go renamed to bundle/statemgmt/check_running_resources.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package terraform
1+
package statemgmt
22

33
import (
44
"context"
@@ -7,6 +7,8 @@ import (
77

88
"github.com/databricks/cli/bundle"
99
"github.com/databricks/cli/bundle/config"
10+
"github.com/databricks/cli/bundle/config/engine"
11+
"github.com/databricks/cli/bundle/deploy/terraform"
1012
"github.com/databricks/cli/libs/diag"
1113
"github.com/databricks/databricks-sdk-go"
1214
"github.com/databricks/databricks-sdk-go/service/jobs"
@@ -23,7 +25,9 @@ func (e ErrResourceIsRunning) Error() string {
2325
return fmt.Sprintf("%s %s is running", e.resourceType, e.resourceId)
2426
}
2527

26-
type checkRunningResources struct{}
28+
type checkRunningResources struct {
29+
engine engine.EngineType
30+
}
2731

2832
func (l *checkRunningResources) Name() string {
2933
return "check-running-resources"
@@ -34,9 +38,20 @@ func (l *checkRunningResources) Apply(ctx context.Context, b *bundle.Bundle) dia
3438
return nil
3539
}
3640

37-
state, err := ParseResourcesState(ctx, b)
38-
if err != nil && state == nil {
39-
return diag.FromErr(err)
41+
var err error
42+
var state ExportedResourcesMap
43+
44+
if l.engine.IsDirect() {
45+
_, fullPathDirect := b.StateFilenameDirect(ctx)
46+
state, err = b.DeploymentBundle.ExportState(ctx, fullPathDirect)
47+
if err != nil {
48+
return diag.FromErr(err)
49+
}
50+
} else {
51+
state, err = terraform.ParseResourcesState(ctx, b)
52+
if err != nil {
53+
return diag.FromErr(err)
54+
}
4055
}
4156

4257
w := b.WorkspaceClient()
@@ -47,8 +62,8 @@ func (l *checkRunningResources) Apply(ctx context.Context, b *bundle.Bundle) dia
4762
return nil
4863
}
4964

50-
func CheckRunningResource() *checkRunningResources {
51-
return &checkRunningResources{}
65+
func CheckRunningResource(engine engine.EngineType) bundle.Mutator {
66+
return &checkRunningResources{engine: engine}
5267
}
5368

5469
func checkAnyResourceRunning(ctx context.Context, w *databricks.WorkspaceClient, state ExportedResourcesMap) error {

bundle/deploy/terraform/check_running_resources_test.go renamed to bundle/statemgmt/check_running_resources_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package terraform
1+
package statemgmt
22

33
import (
44
"context"

0 commit comments

Comments
 (0)