Skip to content

Commit 920b36e

Browse files
authored
new GCP attributes for clusters & instance pools (databricks#1126)
1 parent c6acf4c commit 920b36e

File tree

5 files changed

+72
-7
lines changed

5 files changed

+72
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Added `workspace_url` attribute to the `databricks_current_user` data source ([#1107](https://github.com/databrickslabs/terraform-provider-databricks/pull/1107)).
66
* Fixed issue at `databricks_mount` where new cluster was created for S3 mount even when `cluster_id` was specified ([#1064](https://github.com/databrickslabs/terraform-provider-databricks/issues/1064)).
77
* Allow to disable auto-termination for Databricks SQL endpoints ([#900](https://github.com/databrickslabs/terraform-provider-databricks/pull/900)).
8+
* Added new `gcp_attributes` to `databricks_cluster` and `databricks_instance_pool` ([#1126](https://github.com/databrickslabs/terraform-provider-databricks/pull/1126)).
89

910
## 0.4.9
1011

clusters/clusters_api.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ const (
4242
AzureAvailabilitySpotWithFallback = "SPOT_WITH_FALLBACK_AZURE"
4343
)
4444

45+
// https://docs.gcp.databricks.com/dev-tools/api/latest/clusters.html#gcpavailability
46+
const (
47+
// GcpAvailabilityPreemptible is Preemptible instance type for clusters
48+
GcpAvailabilityPreemptible = "PREEMPTIBLE_GCP"
49+
// GcpAvailabilityOnDemand is OnDemand instance type for clusters
50+
GcpAvailabilityOnDemand = "ON_DEMAND_GCP"
51+
// GcpAvailabilityPreemptible is Preemptible instance type for clusters with option
52+
// to fallback into on-demand if instance cannot be acquired
53+
GcpAvailabilityPreemptibleWithFallback = "PREEMPTIBLE_WITH_FALLBACK_GCP"
54+
)
55+
4556
// AzureDiskVolumeType is disk type on azure vms
4657
type AzureDiskVolumeType string
4758

@@ -151,8 +162,11 @@ type AzureAttributes struct {
151162
// GcpAttributes encapsultes GCP specific attributes
152163
// https://docs.gcp.databricks.com/dev-tools/api/latest/clusters.html#clustergcpattributes
153164
type GcpAttributes struct {
154-
UsePreemptibleExecutors bool `json:"use_preemptible_executors,omitempty"`
155-
GoogleServiceAccount string `json:"google_service_account,omitempty"`
165+
UsePreemptibleExecutors bool `json:"use_preemptible_executors,omitempty"`
166+
GoogleServiceAccount string `json:"google_service_account,omitempty"`
167+
Availability Availability `json:"availability,omitempty"`
168+
BootDiskSize int32 `json:"boot_disk_size,omitempty"`
169+
ZoneId string `json:"zone_id,omitempty"`
156170
}
157171

158172
// DbfsStorageInfo contains the destination string for DBFS

docs/resources/cluster.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ The following options are available:
317317

318318
`azure_attributes` optional configuration block contains attributes related to [clusters running on Azure](https://docs.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/clusters#--azureattributes).
319319

320-
Here is the example of shared autoscaling cluster with some of AWS options set:
320+
Here is the example of shared autoscaling cluster with some of Azure options set:
321321

322322
```hcl
323323
data "databricks_spark_version" "latest" {}
@@ -351,10 +351,35 @@ The following options are [available](https://docs.microsoft.com/en-us/azure/dat
351351

352352
`gcp_attributes` optional configuration block contains attributes related to [clusters running on GCP](https://docs.gcp.databricks.com/dev-tools/api/latest/clusters.html#clustergcpattributes).
353353

354+
Here is the example of shared autoscaling cluster with some of GCP options set:
355+
356+
```hcl
357+
resource "databricks_cluster" "this" {
358+
cluster_name = "Shared Autoscaling"
359+
spark_version = data.databricks_spark_version.latest.id
360+
node_type_id = data.databricks_node_type.smallest.id
361+
autotermination_minutes = 20
362+
autoscale {
363+
min_workers = 1
364+
max_workers = 50
365+
}
366+
gcp_attributes {
367+
availability = "PREEMPTIBLE_WITH_FALLBACK_GCP"
368+
zone_id = "AUTO"
369+
}
370+
}
371+
```
372+
354373
The following options are available:
355374

356-
* `use_preemptible_executors` - (Optional, bool) if we should use preemptible executors ([GCP documentation](https://cloud.google.com/compute/docs/instances/preemptible))
375+
* `use_preemptible_executors` - (Optional, bool) if we should use preemptible executors ([GCP documentation](https://cloud.google.com/compute/docs/instances/preemptible)). *Warning: this field is deprecated in favor of `availability`, and will be removed soon.*
357376
* `google_service_account` - (Optional, string) Google Service Account email address that the cluster uses to authenticate with Google Identity. This field is used for authentication with the GCS and BigQuery data sources.
377+
* `availability` - (Optional) Availability type used for all nodes. Valid values are `PREEMPTIBLE_GCP`, `PREEMPTIBLE_WITH_FALLBACK_GCP` and `ON_DEMAND_GCP`, default: `ON_DEMAND_GCP`.
378+
* `boot_disk_size` (optional, int) Boot disk size in GB
379+
* `zone_id` (optional) Identifier for the availability zone in which the cluster resides. This can be one of the following:
380+
* `HA` (default): High availability, spread nodes across availability zones for a Databricks deployment region.
381+
* `AUTO`: Databricks picks an availability zone to schedule the cluster on.
382+
* name of a GCP availability zone: pick one of the available zones from the [list of available availability zones](https://cloud.google.com/compute/docs/regions-zones#available).
358383

359384
## docker_image
360385

docs/resources/instance_pool.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,17 @@ The following options are [available](https://docs.databricks.com/dev-tools/api/
6161

6262
The following options are [available](https://docs.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/clusters#--azureattributes):
6363

64-
* `availability` - (Optional) Availability type used for all subsequent nodes past the `first_on_demand` ones. Valid values are `SPOT_AZURE` and `ON_DEMAND_AZURE`.
64+
* `availability` - (Optional) Availability type used for all nodes. Valid values are `SPOT_AZURE` and `ON_DEMAND_AZURE`.
6565
* `spot_bid_max_price` - (Optional) The max price for Azure spot instances. Use `-1` to specify lowest price.
6666

67+
## gcp_attributes Configuration Block
68+
69+
`gcp_attributes` optional configuration block contains attributes related to [instance pools on GCP](https://docs.gcp.databricks.com/dev-tools/api/latest/instance-pools.html#clusterinstancepoolgcpattributes).
70+
71+
The following options are [available](https://docs.gcp.databricks.com/dev-tools/api/latest/clusters.html#gcpavailability):
72+
73+
* `availability` - (Optional) Availability type used for all nodes. Valid values are `PREEMPTIBLE_GCP`, `PREEMPTIBLE_WITH_FALLBACK_GCP` and `ON_DEMAND_GCP`, default: `ON_DEMAND_GCP`.
74+
6775

6876
### disk_spec Configuration Block
6977

pools/resource_instance_pool.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ type InstancePoolAzureAttributes struct {
2424
SpotBidMaxPrice float64 `json:"spot_bid_max_price,omitempty" tf:"force_new"`
2525
}
2626

27+
// InstancePoolGcpAttributes contains aws attributes for GCP Databricks deployments for instance pools
28+
// https://docs.gcp.databricks.com/dev-tools/api/latest/instance-pools.html#instancepoolgcpattributes
29+
type InstancePoolGcpAttributes struct {
30+
Availability clusters.Availability `json:"availability,omitempty" tf:"force_new"`
31+
}
32+
2733
// InstancePoolDiskType contains disk type information for each of the different cloud service providers
2834
type InstancePoolDiskType struct {
2935
AzureDiskVolumeType string `json:"azure_disk_volume_type,omitempty" tf:"force_new"`
@@ -46,6 +52,7 @@ type InstancePool struct {
4652
IdleInstanceAutoTerminationMinutes int32 `json:"idle_instance_autotermination_minutes"`
4753
AwsAttributes *InstancePoolAwsAttributes `json:"aws_attributes,omitempty" tf:"force_new,suppress_diff"`
4854
AzureAttributes *InstancePoolAzureAttributes `json:"azure_attributes,omitempty" tf:"force_new,suppress_diff"`
55+
GcpAttributes *InstancePoolGcpAttributes `json:"gcp_attributes,omitempty" tf:"force_new,suppress_diff"`
4956
NodeTypeID string `json:"node_type_id" tf:"force_new"`
5057
CustomTags map[string]string `json:"custom_tags,omitempty" tf:"force_new"`
5158
EnableElasticDisk bool `json:"enable_elastic_disk,omitempty" tf:"force_new,suppress_diff"`
@@ -70,6 +77,7 @@ type InstancePoolAndStats struct {
7077
MaxCapacity int32 `json:"max_capacity,omitempty"`
7178
AwsAttributes *InstancePoolAwsAttributes `json:"aws_attributes,omitempty"`
7279
AzureAttributes *InstancePoolAzureAttributes `json:"azure_attributes,omitempty"`
80+
GcpAttributes *InstancePoolGcpAttributes `json:"gcp_attributes,omitempty"`
7381
NodeTypeID string `json:"node_type_id"`
7482
DefaultTags map[string]string `json:"default_tags,omitempty" tf:"computed"`
7583
CustomTags map[string]string `json:"custom_tags,omitempty"`
@@ -135,8 +143,9 @@ func (a InstancePoolsAPI) Delete(instancePoolID string) error {
135143
func ResourceInstancePool() *schema.Resource {
136144
s := common.StructToSchema(InstancePool{}, func(s map[string]*schema.Schema) map[string]*schema.Schema {
137145
s["enable_elastic_disk"].Default = true
138-
s["aws_attributes"].ConflictsWith = []string{"azure_attributes"}
139-
s["azure_attributes"].ConflictsWith = []string{"aws_attributes"}
146+
s["aws_attributes"].ConflictsWith = []string{"azure_attributes", "gcp_attributes"}
147+
s["azure_attributes"].ConflictsWith = []string{"aws_attributes", "gcp_attributes"}
148+
s["gcp_attributes"].ConflictsWith = []string{"azure_attributes", "aws_attributes"}
140149
if v, err := common.SchemaPath(s, "aws_attributes", "availability"); err == nil {
141150
v.Default = clusters.AwsAvailabilitySpot
142151
v.ValidateFunc = validation.StringInSlice([]string{
@@ -154,6 +163,14 @@ func ResourceInstancePool() *schema.Resource {
154163
clusters.AzureAvailabilityOnDemand,
155164
}, false)
156165
}
166+
if v, err := common.SchemaPath(s, "gcp_attributes", "availability"); err == nil {
167+
v.Default = clusters.GcpAvailabilityOnDemand
168+
v.ValidateFunc = validation.StringInSlice([]string{
169+
clusters.GcpAvailabilityOnDemand,
170+
clusters.GcpAvailabilityPreemptible,
171+
clusters.GcpAvailabilityPreemptibleWithFallback,
172+
}, false)
173+
}
157174
if v, err := common.SchemaPath(s, "disk_spec", "disk_type", "azure_disk_volume_type"); err == nil {
158175
// nolint
159176
v.ValidateFunc = validation.StringInSlice([]string{

0 commit comments

Comments
 (0)