Skip to content

Commit c28b209

Browse files
sabinonfx
andauthored
Support single node clusters (#375)
* Default value for num_workers * fmt * NumWorkers Test * Missing stub * Update documentation * Update CHANGELOG.md Co-authored-by: Serge Smertin <[email protected]>
1 parent 34d2211 commit c28b209

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Added [databricks_node_type](https://github.com/databrickslabs/terraform-provider-databricks/pull/376) data source for simpler selection of node types across AWS & Azure.
88
* Added [Azure Key Vault support](https://github.com/databrickslabs/terraform-provider-databricks/pull/381) for databricks_secret_scope for Azure CLI authenticated users.
99
* Added [is_pinned](https://github.com/databrickslabs/terraform-provider-databricks/pull/348) support for `databricks_cluster` resource.
10+
* Fixed [single node clusters](https://docs.databricks.com/clusters/single-node.html) support by allowing [`num_workers` to be `0`](https://github.com/databrickslabs/terraform-provider-databricks/pull/375).
1011
* Internal: API for retrieval of the cluster events.
1112

1213
Updated dependency versions:

compute/model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ type Cluster struct {
228228
ClusterName string `json:"cluster_name,omitempty"`
229229

230230
SparkVersion string `json:"spark_version"` // TODO: perhaps make a default
231-
NumWorkers int32 `json:"num_workers,omitempty" tf:"group:size"`
231+
NumWorkers int32 `json:"num_workers" tf:"group:size"`
232232
Autoscale *AutoScale `json:"autoscale,omitempty" tf:"group:size"`
233233
EnableElasticDisk bool `json:"enable_elastic_disk,omitempty" tf:"computed"`
234234
EnableLocalDiskEncryption bool `json:"enable_local_disk_encryption,omitempty"`
@@ -260,7 +260,7 @@ type ClusterList struct {
260260

261261
// ClusterInfo contains the information when getting cluster info from the get request.
262262
type ClusterInfo struct {
263-
NumWorkers int32 `json:"num_workers,omitempty"`
263+
NumWorkers int32 `json:"num_workers"`
264264
AutoScale *AutoScale `json:"autoscale,omitempty"`
265265
ClusterID string `json:"cluster_id,omitempty"`
266266
CreatorUserName string `json:"creator_user_name,omitempty"`

compute/resource_cluster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ func resourceClusterSchema() map[string]*schema.Schema {
101101
p.Sensitive = true
102102
}
103103
s["autotermination_minutes"].Default = 60
104+
s["num_workers"] = &schema.Schema{
105+
Type: schema.TypeInt,
106+
Optional: true,
107+
Default: 0,
108+
}
104109
s["idempotency_token"].ForceNew = true
105110
s["cluster_id"] = &schema.Schema{
106111
Type: schema.TypeString,

compute/resource_cluster_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,73 @@ func TestResourceClusterCreate_WithLibraries(t *testing.T) {
495495
assert.Equal(t, "abc", d.Id())
496496
}
497497

498+
func TestResourceClusterCreate_WithoutNumWorkers(t *testing.T) {
499+
d, err := qa.ResourceFixture{
500+
Fixtures: []qa.HTTPFixture{
501+
{
502+
Method: "POST",
503+
Resource: "/api/2.0/clusters/create",
504+
ExpectedRequest: Cluster{
505+
NumWorkers: 0,
506+
ClusterName: "Single Node Cluster",
507+
SparkVersion: "7.1-scala12",
508+
NodeTypeID: "dev-tier-node",
509+
AutoterminationMinutes: 120,
510+
},
511+
Response: ClusterInfo{
512+
ClusterID: "abc",
513+
State: ClusterStateRunning,
514+
},
515+
},
516+
{
517+
Method: "POST",
518+
Resource: "/api/2.0/clusters/events",
519+
ExpectedRequest: EventsRequest{
520+
ClusterID: "abc",
521+
Limit: 1,
522+
Order: SortDescending,
523+
EventTypes: []ClusterEventType{EvTypePinned, EvTypeUnpinned},
524+
},
525+
Response: EventsResponse{
526+
Events: []ClusterEvent{},
527+
TotalCount: 0,
528+
},
529+
},
530+
{
531+
Method: "GET",
532+
ReuseRequest: true,
533+
Resource: "/api/2.0/clusters/get?cluster_id=abc",
534+
Response: ClusterInfo{
535+
ClusterID: "abc",
536+
ClusterName: "Single Node Cluster",
537+
SparkVersion: "7.1-scala12",
538+
NodeTypeID: "dev-tier-node",
539+
AutoterminationMinutes: 120,
540+
State: ClusterStateRunning,
541+
},
542+
},
543+
{
544+
Method: "GET",
545+
Resource: "/api/2.0/libraries/cluster-status?cluster_id=abc",
546+
Response: ClusterLibraryStatuses{
547+
LibraryStatuses: []LibraryStatus{},
548+
},
549+
},
550+
},
551+
Create: true,
552+
Resource: ResourceCluster(),
553+
State: map[string]interface{}{
554+
"autotermination_minutes": 120,
555+
"cluster_name": "Single Node Cluster",
556+
"spark_version": "7.1-scala12",
557+
"node_type_id": "dev-tier-node",
558+
"is_pinned": false,
559+
},
560+
}.Apply(t)
561+
assert.NoError(t, err, err)
562+
assert.Equal(t, 0, d.Get("num_workers"))
563+
}
564+
498565
func TestResourceClusterCreate_Error(t *testing.T) {
499566
d, err := qa.ResourceFixture{
500567
Fixtures: []qa.HTTPFixture{

docs/resources/cluster.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ resource "databricks_cluster" "shared_autoscaling" {
6767

6868
When you [create a Databricks cluster](https://docs.databricks.com/clusters/configure.html#cluster-size-and-autoscaling), you can either provide a `num_workers` for the fixed size cluster or provide `min_workers` and/or `max_workers` for the cluster withing `autoscale` group. When you provide a fixed size cluster, Databricks ensures that your cluster has the specified number of workers. When you provide a range for the number of workers, Databricks chooses the appropriate number of workers required to run your job. This is referred to as autoscaling. With autoscaling, Databricks dynamically reallocates workers to account for the characteristics of your job. Certain parts of your pipeline may be more computationally demanding than others, and Databricks automatically adds additional workers during these phases of your job (and removes them when they’re no longer needed). It is advised to keep all common configurations in [Cluster Policies](cluster_policy.md) to maintain control of the environments launched.
6969

70-
* `num_workers` - (Optional) Number of worker nodes that this cluster should have. A cluster has one Spark Driver and num_workers Executors for a total of num_workers + 1 Spark node.
70+
When using a [Single Node cluster](https://docs.databricks.com/clusters/single-node.html), `num_workers` needs to be `0`. In this case you can choose to explicitly add the argument or not, as it defaults to `0`.
71+
72+
* `num_workers` - (Optional) Number of worker nodes that this cluster should have. A cluster has one Spark Driver and num_workers Executors for a total of num_workers + 1 Spark node. Set to `0` when not provided.
7173

7274
`autoscale` optional configuration block supports the following:
7375

0 commit comments

Comments
 (0)