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
3 changes: 3 additions & 0 deletions acceptance/bundle/refschema/out.fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3151,8 +3151,11 @@ resources.sql_warehouses.*.health.summary string REMOTE
resources.sql_warehouses.*.id string INPUT REMOTE
resources.sql_warehouses.*.instance_profile_arn string ALL
resources.sql_warehouses.*.jdbc_url string REMOTE
resources.sql_warehouses.*.lifecycle *dresources.StateLifecycle REMOTE STATE
resources.sql_warehouses.*.lifecycle *resources.LifecycleWithStarted INPUT
resources.sql_warehouses.*.lifecycle resources.Lifecycle INPUT
resources.sql_warehouses.*.lifecycle.prevent_destroy bool INPUT
resources.sql_warehouses.*.lifecycle.started *bool ALL
resources.sql_warehouses.*.max_num_clusters int ALL
resources.sql_warehouses.*.min_num_clusters int ALL
resources.sql_warehouses.*.modified_status string INPUT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
bundle:
name: lifecycle-started-terraform-error-$UNIQUE_NAME

workspace:
root_path: ~/.bundle/$UNIQUE_NAME

resources:
sql_warehouses:
mywarehouse:
name: my-warehouse-$UNIQUE_NAME
cluster_size: "Medium"
lifecycle:
started: true

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

=== bundle plan fails with lifecycle.started on terraform engine
>>> errcode [CLI] bundle plan
Error: lifecycle.started is only supported in direct deployment mode
in databricks.yml:13:18


Exit code: 1

=== bundle deploy fails with lifecycle.started on terraform engine
>>> errcode [CLI] bundle deploy
Error: lifecycle.started is only supported in direct deployment mode
in databricks.yml:13:18


Exit code: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
envsubst < databricks.yml.tmpl > databricks.yml

title "bundle plan fails with lifecycle.started on terraform engine"
trace errcode $CLI bundle plan
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we also have 'musterr' helper to assert that it indeed fails.


title "bundle deploy fails with lifecycle.started on terraform engine"
trace errcode $CLI bundle deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Local = true
Cloud = true
RecordRequests = false

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

[EnvMatrix]
DATABRICKS_BUNDLE_ENGINE = ["terraform"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
bundle:
name: lifecycle-started-toggle-$UNIQUE_NAME

workspace:
root_path: ~/.bundle/$UNIQUE_NAME

resources:
sql_warehouses:
mywarehouse:
name: $UNIQUE_NAME
cluster_size: "Medium"
lifecycle:
started: false

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

=== Deploy with started=false: warehouse created and then stopped
>>> errcode [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> print_requests.py //sql/warehouses
{
"method": "POST",
"path": "/api/2.0/sql/warehouses",
"body": {
"auto_stop_mins": 120,
"cluster_size": "Medium",
"enable_photon": true,
"max_num_clusters": 1,
"name": "[UNIQUE_NAME]",
"spot_instance_policy": "COST_OPTIMIZED"
}
}
{
"method": "POST",
"path": "/api/2.0/sql/warehouses/[UUID]/stop"
}

>>> errcode [CLI] warehouses get [UUID]
"STOPPED"

=== Toggle started=false -> started=true: only Start should be called, no Edit
>>> update_file.py databricks.yml started: false started: true

>>> errcode [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> print_requests.py //sql/warehouses
{
"method": "POST",
"path": "/api/2.0/sql/warehouses/[UUID]/start"
}

>>> errcode [CLI] warehouses get [UUID]
"RUNNING"

=== Toggle started=true -> started=false: only Stop should be called, no Edit
>>> update_file.py databricks.yml started: true started: false

>>> errcode [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> print_requests.py //sql/warehouses
{
"method": "POST",
"path": "/api/2.0/sql/warehouses/[UUID]/stop"
}

>>> errcode [CLI] warehouses get [UUID]
"STOPPED"

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.sql_warehouses.mywarehouse

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]

Deleting files...
Destroy complete!
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
envsubst < databricks.yml.tmpl > databricks.yml

cleanup() {
trace $CLI bundle destroy --auto-approve
rm -f out.requests.txt
}
trap cleanup EXIT

title "Deploy with started=false: warehouse created and then stopped"
trace errcode $CLI bundle deploy
WAREHOUSE_ID=$($CLI bundle summary -o json | jq -r '.resources.sql_warehouses.mywarehouse.id')
trace print_requests.py //sql/warehouses
rm -f out.requests.txt
{ trace errcode $CLI warehouses get "$WAREHOUSE_ID" | jq '.state'; } || true

title "Toggle started=false -> started=true: only Start should be called, no Edit"
trace update_file.py databricks.yml "started: false" "started: true"
trace errcode $CLI bundle deploy
trace print_requests.py //sql/warehouses
rm -f out.requests.txt
{ trace errcode $CLI warehouses get "$WAREHOUSE_ID" | jq '.state'; } || true

title "Toggle started=true -> started=false: only Stop should be called, no Edit"
trace update_file.py databricks.yml "started: true" "started: false"
trace errcode $CLI bundle deploy
trace print_requests.py //sql/warehouses
rm -f out.requests.txt
{ trace errcode $CLI warehouses get "$WAREHOUSE_ID" | jq '.state'; } || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Local = true
Cloud = true
RecordRequests = true

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

[[Repls]]
Old = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
New = "[UUID]"

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

workspace:
root_path: ~/.bundle/$UNIQUE_NAME

resources:
sql_warehouses:
mywarehouse:
name: $UNIQUE_NAME
cluster_size: "Medium"
lifecycle:
started: true

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

=== Deploy with started=true: warehouse created and running
>>> errcode [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> print_requests.py //sql/warehouses
{
"method": "POST",
"path": "/api/2.0/sql/warehouses",
"body": {
"auto_stop_mins": 120,
"cluster_size": "Medium",
"enable_photon": true,
"max_num_clusters": 1,
"name": "[UNIQUE_NAME]",
"spot_instance_policy": "COST_OPTIMIZED"
}
}

>>> errcode [CLI] warehouses get [UUID]
"RUNNING"

=== Stop warehouse externally while config says started=true: plan detects drift
>>> errcode [CLI] warehouses stop [UUID]
"STOPPED"

>>> [CLI] bundle plan
update sql_warehouses.mywarehouse

Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged

=== Deploy fixes the drift: warehouse restarted
>>> errcode [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> print_requests.py //sql/warehouses
{
"method": "POST",
"path": "/api/2.0/sql/warehouses/[UUID]/stop"
}
{
"method": "POST",
"path": "/api/2.0/sql/warehouses/[UUID]/start"
}

>>> errcode [CLI] warehouses get [UUID]
"RUNNING"

=== Deploy with started=false while warehouse is stopped: warehouse stays stopped
>>> errcode [CLI] warehouses stop [UUID]
"STOPPED"

>>> update_file.py databricks.yml started: true started: false

>>> errcode [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> print_requests.py //sql/warehouses
{
"method": "POST",
"path": "/api/2.0/sql/warehouses/[UUID]/stop"
}

>>> errcode [CLI] warehouses get [UUID]
"STOPPED"

=== Deploy with started=true: warehouse restarted
>>> update_file.py databricks.yml started: false started: true

>>> errcode [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> print_requests.py //sql/warehouses
{
"method": "POST",
"path": "/api/2.0/sql/warehouses/[UUID]/start"
}

>>> errcode [CLI] warehouses get [UUID]
"RUNNING"

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.sql_warehouses.mywarehouse

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]

Deleting files...
Destroy complete!
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
envsubst < databricks.yml.tmpl > databricks.yml

cleanup() {
trace $CLI bundle destroy --auto-approve
rm -f out.requests.txt
}
trap cleanup EXIT

title "Deploy with started=true: warehouse created and running"
trace errcode $CLI bundle deploy
WAREHOUSE_ID=$($CLI bundle summary -o json | jq -r '.resources.sql_warehouses.mywarehouse.id')
trace print_requests.py //sql/warehouses
rm -f out.requests.txt
{ trace errcode $CLI warehouses get "$WAREHOUSE_ID" | jq '.state'; } || true

title "Stop warehouse externally while config says started=true: plan detects drift"
{ trace errcode $CLI warehouses stop "$WAREHOUSE_ID" | jq '.state'; } || true
trace $CLI bundle plan

title "Deploy fixes the drift: warehouse restarted"
trace errcode $CLI bundle deploy
trace print_requests.py //sql/warehouses
rm -f out.requests.txt
{ trace errcode $CLI warehouses get "$WAREHOUSE_ID" | jq '.state'; } || true

title "Deploy with started=false while warehouse is stopped: warehouse stays stopped"
{ trace errcode $CLI warehouses stop "$WAREHOUSE_ID" | jq '.state'; } || true
trace update_file.py databricks.yml "started: true" "started: false"
trace errcode $CLI bundle deploy
trace print_requests.py //sql/warehouses
rm -f out.requests.txt
{ trace errcode $CLI warehouses get "$WAREHOUSE_ID" | jq '.state'; } || true

title "Deploy with started=true: warehouse restarted"
trace update_file.py databricks.yml "started: false" "started: true"
trace errcode $CLI bundle deploy
trace print_requests.py //sql/warehouses
rm -f out.requests.txt
{ trace errcode $CLI warehouses get "$WAREHOUSE_ID" | jq '.state'; } || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Local = true
Cloud = true
RecordRequests = true

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

[[Repls]]
Old = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
New = "[UUID]"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you know the UUID of the resources in question, you can add them to replacement dynamically with add_repl.py. It's better, since it's targeted, function as assert that id is correct, and distinguishes different ids.


[EnvMatrix]
DATABRICKS_BUNDLE_ENGINE = ["direct"]
11 changes: 11 additions & 0 deletions bundle/config/resources/sql_warehouses.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@ type SqlWarehouse struct {
BaseResource
sql.CreateWarehouseRequest

// Lifecycle shadows BaseResource.Lifecycle to add support for lifecycle.started.
Lifecycle *LifecycleWithStarted `json:"lifecycle,omitempty"`

Permissions []SqlWarehousePermission `json:"permissions,omitempty"`
}

// GetLifecycle returns the lifecycle settings, using LifecycleWithStarted.
func (sw *SqlWarehouse) GetLifecycle() LifecycleConfig {
if sw.Lifecycle == nil {
return LifecycleWithStarted{}
}
return *sw.Lifecycle
}

func (sw *SqlWarehouse) UnmarshalJSON(b []byte) error {
return marshal.Unmarshal(b, sw)
}
Expand Down
Loading
Loading