-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make bundle deploy work if no resources are defined (#767)
## Changes This PR sets "resource" to nil in the terraform representation if no resources are defined in the bundle configuration. This solves two problems: 1. Makes bundle deploy work without any resources specified. 2. Previously if a `resources` block was removed after a deployment, that would fail with an error. Now the resources would get destroyed as expected. Also removes `TerraformHasNoResources` which is no longer needed. ## Tests New e2e tests.
- Loading branch information
1 parent
be55310
commit fe32c46
Showing
12 changed files
with
138 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
internal/bundle/bundles/deploy_then_remove_resources/databricks_template_schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"properties": { | ||
"unique_id": { | ||
"type": "string", | ||
"description": "Unique ID for job name" | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
internal/bundle/bundles/deploy_then_remove_resources/template/databricks.yml.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
bundle: | ||
name: deploy-then-remove | ||
|
||
workspace: | ||
root_path: "~/.bundle/{{.unique_id}}" | ||
|
||
include: | ||
- "./*.yml" |
1 change: 1 addition & 0 deletions
1
internal/bundle/bundles/deploy_then_remove_resources/template/foo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print("hello") |
7 changes: 7 additions & 0 deletions
7
internal/bundle/bundles/deploy_then_remove_resources/template/resources.yml.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
resources: | ||
pipelines: | ||
bar: | ||
name: test-bundle-pipeline-{{.unique_id}} | ||
libraries: | ||
- notebook: | ||
path: "./foo.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bundle: | ||
name: abc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package bundle | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/databricks/cli/internal" | ||
"github.com/databricks/databricks-sdk-go" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAccBundleDeployThenRemoveResources(t *testing.T) { | ||
env := internal.GetEnvOrSkipTest(t, "CLOUD_ENV") | ||
t.Log(env) | ||
|
||
uniqueId := uuid.New().String() | ||
bundleRoot, err := initTestTemplate(t, "deploy_then_remove_resources", map[string]any{ | ||
"unique_id": uniqueId, | ||
}) | ||
require.NoError(t, err) | ||
|
||
// deploy pipeline | ||
err = deployBundle(t, bundleRoot) | ||
require.NoError(t, err) | ||
|
||
w, err := databricks.NewWorkspaceClient() | ||
require.NoError(t, err) | ||
|
||
// assert pipeline is created | ||
pipelineName := "test-bundle-pipeline-" + uniqueId | ||
pipeline, err := w.Pipelines.GetByName(context.Background(), pipelineName) | ||
require.NoError(t, err) | ||
assert.Equal(t, pipeline.Name, pipelineName) | ||
|
||
// delete resources.yml | ||
err = os.Remove(filepath.Join(bundleRoot, "resources.yml")) | ||
require.NoError(t, err) | ||
|
||
// deploy again | ||
err = deployBundle(t, bundleRoot) | ||
require.NoError(t, err) | ||
|
||
// assert pipeline is deleted | ||
_, err = w.Pipelines.GetByName(context.Background(), pipelineName) | ||
assert.ErrorContains(t, err, "does not exist") | ||
|
||
t.Cleanup(func() { | ||
err = destroyBundle(t, bundleRoot) | ||
require.NoError(t, err) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package bundle | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/databricks/cli/internal" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAccEmptyBundleDeploy(t *testing.T) { | ||
env := internal.GetEnvOrSkipTest(t, "CLOUD_ENV") | ||
t.Log(env) | ||
|
||
// create empty bundle | ||
tmpDir := t.TempDir() | ||
f, err := os.Create(filepath.Join(tmpDir, "databricks.yml")) | ||
require.NoError(t, err) | ||
|
||
bundleRoot := fmt.Sprintf(`bundle: | ||
name: %s`, uuid.New().String()) | ||
_, err = f.WriteString(bundleRoot) | ||
require.NoError(t, err) | ||
f.Close() | ||
|
||
// deploy empty bundle | ||
err = deployBundle(t, tmpDir) | ||
require.NoError(t, err) | ||
|
||
t.Cleanup(func() { | ||
err = destroyBundle(t, tmpDir) | ||
require.NoError(t, err) | ||
}) | ||
} |