Skip to content

Commit 152867a

Browse files
authored
Add autoscale mode configuration to databricks_pipeline resource (#1600)
1 parent 91e6a18 commit 152867a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

docs/resources/pipeline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The following arguments are supported:
5454
* `storage` - A location on DBFS or cloud storage where output data and metadata required for pipeline execution are stored. By default, tables are stored in a subdirectory of this location. *Change of this parameter forces recreation of the pipeline.*
5555
* `configuration` - An optional list of values to apply to the entire pipeline. Elements must be formatted as key:value pairs.
5656
* `library` blocks - Specifies pipeline code and required artifacts. Syntax resembles [library](cluster.md#library-configuration-block) configuration block with the addition of a special `notebook` type of library that should have the `path` attribute. *Right now only the `notebook` type is supported.*
57-
* `cluster` blocks - [Clusters](cluster.md) to run the pipeline. If none is specified, pipelines will automatically select a default cluster configuration for the pipeline. *Please note that DLT pipeline clusters are supporting only subset of attributes as described in [documentation](https://docs.databricks.com/data-engineering/delta-live-tables/delta-live-tables-api-guide.html#pipelinesnewcluster).*
57+
* `cluster` blocks - [Clusters](cluster.md) to run the pipeline. If none is specified, pipelines will automatically select a default cluster configuration for the pipeline. *Please note that DLT pipeline clusters are supporting only subset of attributes as described in [documentation](https://docs.databricks.com/data-engineering/delta-live-tables/delta-live-tables-api-guide.html#pipelinesnewcluster).* Also, note that `autoscale` block is extended with the `mode` parameter that controls the autoscaling algorithm (possible values are `ENHANCED` for new, enhanced autoscaling algorithm, or `LEGACY` for old algorithm).
5858
* `continuous` - A flag indicating whether to run the pipeline continuously. The default value is `false`.
5959
* `development` - A flag indicating whether to run the pipeline in development mode. The default value is `false`.
6060
* `photon` - A flag indicating whether to use Photon engine. The default value is `false`.

pipelines/resource_pipeline.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"regexp"
8+
"strings"
89
"time"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -19,15 +20,22 @@ import (
1920
// DefaultTimeout is the default amount of time that Terraform will wait when creating, updating and deleting pipelines.
2021
const DefaultTimeout = 20 * time.Minute
2122

23+
// dltAutoScale is a struct the describes auto scaling for DLT clusters
24+
type dltAutoScale struct {
25+
MinWorkers int32 `json:"min_workers,omitempty"`
26+
MaxWorkers int32 `json:"max_workers,omitempty"`
27+
Mode string `json:"mode,omitempty"`
28+
}
29+
2230
// We separate this struct from Cluster for two reasons:
2331
// 1. Pipeline clusters include a `Label` field.
2432
// 2. Spark version is not required (and shouldn't be specified) for pipeline clusters.
2533
// 3. num_workers is optional, and there is no single-node support for pipelines clusters.
2634
type pipelineCluster struct {
2735
Label string `json:"label,omitempty"` // used only by pipelines
2836

29-
NumWorkers int32 `json:"num_workers,omitempty" tf:"group:size"`
30-
Autoscale *clusters.AutoScale `json:"autoscale,omitempty" tf:"group:size"`
37+
NumWorkers int32 `json:"num_workers,omitempty" tf:"group:size"`
38+
Autoscale *dltAutoScale `json:"autoscale,omitempty" tf:"group:size"`
3139

3240
NodeTypeID string `json:"node_type_id,omitempty" tf:"group:node_type,computed"`
3341
DriverNodeTypeID string `json:"driver_node_type_id,omitempty" tf:"computed"`
@@ -266,12 +274,21 @@ func suppressStorageDiff(k, old, new string, d *schema.ResourceData) bool {
266274
return false
267275
}
268276

277+
func AutoscaleModeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
278+
if strings.EqualFold(old, new) {
279+
log.Printf("[INFO] Suppressing diff on autoscale mode")
280+
return true
281+
}
282+
return false
283+
}
284+
269285
func adjustPipelineResourceSchema(m map[string]*schema.Schema) map[string]*schema.Schema {
270286
cluster, _ := m["cluster"].Elem.(*schema.Resource)
271287
clustersSchema := cluster.Schema
272288
clustersSchema["spark_conf"].DiffSuppressFunc = clusters.SparkConfDiffSuppressFunc
273289
common.MustSchemaPath(clustersSchema,
274290
"aws_attributes", "zone_id").DiffSuppressFunc = clusters.ZoneDiffSuppress
291+
common.MustSchemaPath(clustersSchema, "autoscale", "mode").DiffSuppressFunc = AutoscaleModeDiffSuppress
275292

276293
awsAttributes, _ := clustersSchema["aws_attributes"].Elem.(*schema.Resource)
277294
awsAttributesSchema := awsAttributes.Schema

0 commit comments

Comments
 (0)