Skip to content

Commit 1d5c128

Browse files
committed
Pull MakeEmptyBlockSuppressFunc to common package
1 parent c0532f8 commit 1d5c128

File tree

8 files changed

+58
-42
lines changed

8 files changed

+58
-42
lines changed

common/resource.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,14 @@ func (r Resource) ToResource() *schema.Resource {
9393
Timeouts: r.Timeouts,
9494
}
9595
}
96+
97+
func MakeEmptyBlockSuppressFunc(name string) func(k, old, new string, d *schema.ResourceData) bool {
98+
return func(k, old, new string, d *schema.ResourceData) bool {
99+
log.Printf("[DEBUG] k='%v', old='%v', new='%v'", k, old, new)
100+
if k == name && old == "1" && new == "0" {
101+
log.Printf("[DEBUG] Disable removal of empty block")
102+
return true
103+
}
104+
return false
105+
}
106+
}

compute/resource_cluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ func resourceClusterSchema() map[string]*schema.Schema {
7373
s["aws_attributes"].ConflictsWith = []string{"azure_attributes", "gcp_attributes"}
7474
s["azure_attributes"].ConflictsWith = []string{"aws_attributes", "gcp_attributes"}
7575
s["gcp_attributes"].ConflictsWith = []string{"aws_attributes", "azure_attributes"}
76-
s["aws_attributes"].DiffSuppressFunc = makeEmptyBlockSuppressFunc("aws_attributes.#")
77-
s["azure_attributes"].DiffSuppressFunc = makeEmptyBlockSuppressFunc("azure_attributes.#")
78-
s["gcp_attributes"].DiffSuppressFunc = makeEmptyBlockSuppressFunc("gcp_attributes.#")
76+
s["aws_attributes"].DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("aws_attributes.#")
77+
s["azure_attributes"].DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("azure_attributes.#")
78+
s["gcp_attributes"].DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("gcp_attributes.#")
7979

8080
s["is_pinned"] = &schema.Schema{
8181
Type: schema.TypeBool,

compute/resource_instance_pool.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package compute
22

33
import (
44
"context"
5-
"log"
65

76
"github.com/databrickslabs/terraform-provider-databricks/common"
87

@@ -54,17 +53,6 @@ func (a InstancePoolsAPI) Delete(instancePoolID string) error {
5453
}, nil)
5554
}
5655

57-
func makeEmptyBlockSuppressFunc(name string) func(k, old, new string, d *schema.ResourceData) bool {
58-
return func(k, old, new string, d *schema.ResourceData) bool {
59-
log.Printf("[DEBUG] k='%v', old='%v', new='%v'", k, old, new)
60-
if k == name && old == "1" && new == "0" {
61-
log.Printf("[DEBUG] Disable removal of empty block")
62-
return true
63-
}
64-
return false
65-
}
66-
}
67-
6856
// ResourceInstancePool ...
6957
func ResourceInstancePool() *schema.Resource {
7058
s := common.StructToSchema(InstancePool{}, func(s map[string]*schema.Schema) map[string]*schema.Schema {
@@ -79,8 +67,8 @@ func ResourceInstancePool() *schema.Resource {
7967
s["enable_elastic_disk"].Default = true
8068
s["aws_attributes"].ConflictsWith = []string{"azure_attributes"}
8169
s["azure_attributes"].ConflictsWith = []string{"aws_attributes"}
82-
s["aws_attributes"].DiffSuppressFunc = makeEmptyBlockSuppressFunc("aws_attributes.#")
83-
s["azure_attributes"].DiffSuppressFunc = makeEmptyBlockSuppressFunc("azure_attributes.#")
70+
s["aws_attributes"].DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("aws_attributes.#")
71+
s["azure_attributes"].DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("azure_attributes.#")
8472
if v, err := common.SchemaPath(s, "aws_attributes", "availability"); err == nil {
8573
v.ForceNew = true
8674
v.Default = AwsAvailabilitySpot

compute/resource_job.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ var jobSchema = common.StructToSchema(JobSettings{},
132132
}
133133

134134
if v, err := common.SchemaPath(s, "new_cluster", "aws_attributes"); err == nil {
135-
v.DiffSuppressFunc = makeEmptyBlockSuppressFunc("new_cluster.0.aws_attributes.#")
135+
v.DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("new_cluster.0.aws_attributes.#")
136136
}
137137
if v, err := common.SchemaPath(s, "new_cluster", "azure_attributes"); err == nil {
138-
v.DiffSuppressFunc = makeEmptyBlockSuppressFunc("new_cluster.0.azure_attributes.#")
138+
v.DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("new_cluster.0.azure_attributes.#")
139139
}
140140
if v, err := common.SchemaPath(s, "new_cluster", "gcp_attributes"); err == nil {
141-
v.DiffSuppressFunc = makeEmptyBlockSuppressFunc("new_cluster.0.gcp_attributes.#")
141+
v.DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("new_cluster.0.gcp_attributes.#")
142142
}
143143

144-
s["email_notifications"].DiffSuppressFunc = makeEmptyBlockSuppressFunc("email_notifications.#")
144+
s["email_notifications"].DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("email_notifications.#")
145145

146146
s["name"].Description = "An optional name for the job. The default value is Untitled."
147147
s["library"].Description = "An optional list of libraries to be installed on " +

compute/resource_pipeline_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ func TestResourcePipelineCreate(t *testing.T) {
9696
"cluster_tag1" = "cluster_value1"
9797
}
9898
}
99-
libraries {
99+
library {
100100
jar = "dbfs:/pipelines/code/abcde.jar"
101101
}
102-
libraries {
102+
library {
103103
maven {
104104
coordinates = "com.microsoft.azure:azure-eventhubs-spark_2.12:2.3.18"
105105
}
@@ -131,7 +131,7 @@ func TestResourcePipelineCreate_Error(t *testing.T) {
131131
Resource: ResourcePipeline(),
132132
HCL: `name = "test"
133133
storage = "/test/storage"
134-
libraries {
134+
library {
135135
jar = "jar"
136136
}
137137
filters {
@@ -180,7 +180,7 @@ func TestResourcePipelineCreate_ErrorWhenWaitingFailedCleanup(t *testing.T) {
180180
Resource: ResourcePipeline(),
181181
HCL: `name = "test"
182182
storage = "/test/storage"
183-
libraries {
183+
library {
184184
jar = "jar"
185185
}
186186
filters {
@@ -229,7 +229,7 @@ func TestResourcePipelineCreate_ErrorWhenWaitingSuccessfulCleanup(t *testing.T)
229229
Resource: ResourcePipeline(),
230230
HCL: `name = "test"
231231
storage = "/test/storage"
232-
libraries {
232+
library {
233233
jar = "jar"
234234
}
235235
filters {
@@ -356,7 +356,7 @@ func TestResourcePipelineUpdate(t *testing.T) {
356356
Resource: ResourcePipeline(),
357357
HCL: `name = "test"
358358
storage = "/test/storage"
359-
libraries {
359+
library {
360360
maven {
361361
coordinates = "coordinates"
362362
}
@@ -387,7 +387,7 @@ func TestResourcePipelineUpdate_Error(t *testing.T) {
387387
Resource: ResourcePipeline(),
388388
HCL: `name = "test"
389389
storage = "/test/storage"
390-
libraries {
390+
library {
391391
maven {
392392
coordinates = "coordinates"
393393
}
@@ -439,7 +439,7 @@ func TestResourcePipelineUpdate_FailsAfterUpdate(t *testing.T) {
439439
Resource: ResourcePipeline(),
440440
HCL: `name = "test"
441441
storage = "/test/storage"
442-
libraries {
442+
library {
443443
maven {
444444
coordinates = "coordinates"
445445
}

docs/resources/sql_endpoint.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ The following arguments are supported:
3232

3333
* `name` - (Required) Name of the SQL endpoint. Must be unique.
3434
* `cluster_size` - (Required) The size of the clusters allocated to the endpoint: "2X-Small", "X-Small", "Small", "Medium", "Large", "X-Large", "2X-Large", "3X-Large", "4X-Large".
35-
* `min_num_clusters` - Minimum number of clusters available when a SQL endpoint is running. The default is 1.
36-
* `max_num_clusters` - Maximum number of clusters available when a SQL endpoint is running. This field is required. If multi-cluster load balancing is not enabled, this is default to 1.
35+
* `min_num_clusters` - Minimum number of clusters available when a SQL endpoint is running. The default is `1`.
36+
* `max_num_clusters` - Maximum number of clusters available when a SQL endpoint is running. This field is required. If multi-cluster load balancing is not enabled, this is default to `1`.
3737
* `auto_stop_mins` - Time in minutes until an idle SQL endpoint terminates all clusters and stops. This field is optional. The default is 0, which means auto stop is disabled.
3838
* `instance_profile_arn` - [databricks_instance_profile](instance_profile.md) used to access storage from the SQL endpoint. This field is optional.
3939
* `tags` - Databricks tags all endpoint resources with these tags.
40-
* `spot_instance_policy` - The spot policy to use for allocating instances to clusters: `COST_OPTIMIZED` or `RELIABILITY_OPTIMIZED`. This field is optional.
40+
* `spot_instance_policy` - The spot policy to use for allocating instances to clusters: `COST_OPTIMIZED` or `RELIABILITY_OPTIMIZED`. This field is optional. Default is `COST_OPTIMIZED`.
4141
* `enable_photon` - Whether to enable [Photon](https://databricks.com/product/delta-engine). This field is optional.
4242

4343
## Attribute Reference

sqlanalytics/resource_sql_endpoint.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,16 @@ func (a SQLEndpointsAPI) Delete(endpointID string) error {
180180
func ResourceSQLEndpoint() *schema.Resource {
181181
s := common.StructToSchema(SQLEndpoint{}, func(
182182
m map[string]*schema.Schema) map[string]*schema.Schema {
183+
m["auto_stop_mins"].Default = 120
183184
m["cluster_size"].ValidateDiagFunc = validation.ToDiagFunc(
184185
validation.StringInSlice(ClusterSizes, false))
185186
m["max_num_clusters"].Default = 1
186187
m["max_num_clusters"].ValidateDiagFunc = validation.ToDiagFunc(
187188
validation.IntBetween(1, MaxNumClusters))
189+
m["min_num_clusters"].Default = 1
190+
m["num_clusters"].Default = 1
191+
m["spot_instance_policy"].Default = "COST_OPTIMIZED"
192+
m["tags"].DiffSuppressFunc = common.MakeEmptyBlockSuppressFunc("tags.#")
188193
return m
189194
})
190195
return common.Resource{

sqlanalytics/resource_sql_endpoint_test.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ func TestResourceSQLEndpointCreate(t *testing.T) {
7272
Method: "POST",
7373
Resource: "/api/2.0/sql/endpoints",
7474
ExpectedRequest: SQLEndpoint{
75-
Name: "foo",
76-
ClusterSize: "Small",
77-
MaxNumClusters: 1,
75+
Name: "foo",
76+
ClusterSize: "Small",
77+
MaxNumClusters: 1,
78+
AutoStopMinutes: 120,
79+
MinNumClusters: 1,
80+
NumClusters: 1,
81+
SpotInstancePolicy: "COST_OPTIMIZED",
7882
},
7983
Response: SQLEndpoint{
8084
ID: "abc",
@@ -113,9 +117,13 @@ func TestResourceSQLEndpointCreate_ErrorDisabled(t *testing.T) {
113117
Method: "POST",
114118
Resource: "/api/2.0/sql/endpoints",
115119
ExpectedRequest: SQLEndpoint{
116-
Name: "foo",
117-
ClusterSize: "Small",
118-
MaxNumClusters: 1,
120+
Name: "foo",
121+
ClusterSize: "Small",
122+
AutoStopMinutes: 120,
123+
MaxNumClusters: 1,
124+
MinNumClusters: 1,
125+
NumClusters: 1,
126+
SpotInstancePolicy: "COST_OPTIMIZED",
119127
},
120128
Status: 404,
121129
Response: common.APIError{
@@ -169,10 +177,14 @@ func TestResourceSQLEndpointUpdate(t *testing.T) {
169177
Method: "POST",
170178
Resource: "/api/2.0/sql/endpoints/abc/edit",
171179
ExpectedRequest: SQLEndpoint{
172-
ID: "abc",
173-
Name: "foo",
174-
ClusterSize: "Small",
175-
MaxNumClusters: 1,
180+
ID: "abc",
181+
Name: "foo",
182+
ClusterSize: "Small",
183+
AutoStopMinutes: 120,
184+
MaxNumClusters: 1,
185+
MinNumClusters: 1,
186+
NumClusters: 1,
187+
SpotInstancePolicy: "COST_OPTIMIZED",
176188
},
177189
},
178190
{

0 commit comments

Comments
 (0)