Skip to content

Commit

Permalink
[Fix] Forced send auto_stop_mins for databricks_sql_endpoint reso…
Browse files Browse the repository at this point in the history
…urce (#4265)

## Changes
- Forced send `auto_stop_mins` for `databricks_sql_endpoint` resource.
This allows creating SQL warehouses with auto stop turned off

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->

- [x] `make test` run locally
- [x] relevant acceptance tests are passing
- [x] using Go SDK
  • Loading branch information
nkvuong authored Nov 22, 2024
1 parent e587a02 commit 1844fa1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sql/resource_sql_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (

// ClusterSizes for SQL endpoints
var (
ClusterSizes = []string{"2X-Small", "X-Small", "Small", "Medium", "Large", "X-Large", "2X-Large", "3X-Large", "4X-Large"}
MaxNumClusters = 30
ClusterSizes = []string{"2X-Small", "X-Small", "Small", "Medium", "Large", "X-Large", "2X-Large", "3X-Large", "4X-Large"}
MaxNumClusters = 30
ForceSendFields = []string{"enable_serverless_compute", "enable_photon", "auto_stop_mins"}
)

type SqlWarehouse struct {
Expand Down Expand Up @@ -95,7 +96,7 @@ func ResourceSqlEndpoint() common.Resource {
}
var se sql.CreateWarehouseRequest
common.DataToStructPointer(d, s, &se)
common.SetForceSendFields(&se, d, []string{"enable_serverless_compute", "enable_photon"})
common.SetForceSendFields(&se, d, ForceSendFields)
wait, err := w.Warehouses.Create(ctx, se)
if err != nil {
return fmt.Errorf("failed creating warehouse: %w", err)
Expand Down Expand Up @@ -129,7 +130,7 @@ func ResourceSqlEndpoint() common.Resource {
}
var se sql.EditWarehouseRequest
common.DataToStructPointer(d, s, &se)
common.SetForceSendFields(&se, d, []string{"enable_serverless_compute", "enable_photon"})
common.SetForceSendFields(&se, d, ForceSendFields)
se.Id = d.Id()
_, err = w.Warehouses.Edit(ctx, se)
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions sql/resource_sql_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func TestResourceSQLEndpointCreateNoAutoTermination(t *testing.T) {
AutoStopMins: 0,
EnablePhoton: true,
SpotInstancePolicy: "COST_OPTIMIZED",
ForceSendFields: []string{"AutoStopMins"},
}).Return(&sql.WaitGetWarehouseRunning[sql.CreateWarehouseResponse]{
Poll: poll.Simple(getResponse),
}, nil)
Expand Down Expand Up @@ -271,6 +272,38 @@ func TestResourceSQLEndpointUpdateHealthNoDiff(t *testing.T) {
}.ApplyNoError(t)
}

func TestResourceSQLEndpointUpdateNoAutoTermination(t *testing.T) {
qa.ResourceFixture{
Resource: ResourceSqlEndpoint(),
ID: "abc",
InstanceState: map[string]string{
"name": "foo",
"cluster_size": "Small",
"auto_stop_mins": "120",
"enable_photon": "true",
"max_num_clusters": "1",
"spot_instance_policy": "COST_OPTIMIZED",
},
ExpectedDiff: map[string]*terraform.ResourceAttrDiff{
"auto_stop_mins": {Old: "120", New: "0", NewComputed: false, NewRemoved: false, RequiresNew: false, Sensitive: false},
"state": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
"odbc_params.#": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
"num_clusters": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
"num_active_sessions": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
"jdbc_url": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
"id": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
"enable_serverless_compute": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
"data_source_id": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
"creator_name": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
},
HCL: `
name = "foo"
cluster_size = "Small"
auto_stop_mins = 0
`,
}.ApplyNoError(t)
}

func TestResourceSQLEndpointDelete(t *testing.T) {
d, err := qa.ResourceFixture{
MockWorkspaceClientFunc: func(mwc *mocks.MockWorkspaceClient) {
Expand Down

0 comments on commit 1844fa1

Please sign in to comment.