Skip to content

Commit e537f4b

Browse files
authored
Add more attributes to databricks_instance_pool (#1463)
1 parent 9b9c1fa commit e537f4b

File tree

5 files changed

+83
-36
lines changed

5 files changed

+83
-36
lines changed

clusters/clusters_api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ func TestListSparkVersionsWithError(t *testing.T) {
944944
ctx := context.Background()
945945
_, err = NewClustersAPI(ctx, client).ListSparkVersions()
946946
require.Error(t, err)
947-
require.Equal(t, true, strings.Contains(err.Error(), "Invalid JSON received"))
947+
require.Equal(t, true, strings.Contains(err.Error(), "invalid character 'g' looking"))
948948
}
949949

950950
func TestGetLatestSparkVersion(t *testing.T) {

clusters/data_spark_version_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,5 @@ func TestSparkVersionErrorBadAnswer(t *testing.T) {
232232
ID: ".",
233233
}.Apply(t)
234234
assert.Error(t, err)
235-
require.Equal(t, true, strings.Contains(err.Error(), "Invalid JSON received"))
235+
require.Equal(t, true, strings.Contains(err.Error(), "invalid character 'g' looking"))
236236
}

common/http.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ func (c *DatabricksClient) unmarshall(path string, body []byte, response any) er
308308
ErrorCode: "UNKNOWN",
309309
StatusCode: 200,
310310
Resource: "..." + path,
311-
Message: fmt.Sprintf("Invalid JSON received (%d bytes): %v",
312-
len(body), string(body)),
311+
Message: fmt.Sprintf("%s\n%s", err.Error(), onlyNBytes(string(body), 32)),
313312
}
314313
}
315314

common/http_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func TestPost_Error(t *testing.T) {
269269
ScimDetail: "some",
270270
}, &resp)
271271
require.Error(t, err)
272-
assert.True(t, strings.HasPrefix(err.Error(), "Invalid JSON received (16 bytes)"),
272+
assert.True(t, strings.HasPrefix(err.Error(), "invalid character 'c'"),
273273
"Actual message: %s", err.Error())
274274
}
275275

@@ -311,6 +311,18 @@ func TestUnmarshall(t *testing.T) {
311311
require.NoError(t, err)
312312
}
313313

314+
func TestUnmarshallError(t *testing.T) {
315+
v := struct {
316+
Correct string `json:"c"`
317+
Incorrect int `json:"i"`
318+
}{}
319+
ws := DatabricksClient{}
320+
err := ws.unmarshall("/a/b/c", []byte(`{"c":"val", "i":"123"}`), &v)
321+
require.Error(t, err)
322+
require.EqualError(t, err,
323+
"json: cannot unmarshal string into Go struct field .i of type int\n{\"c\":\"val\", \"i\":\"123\"}")
324+
}
325+
314326
func TestAPI2(t *testing.T) {
315327
ws := DatabricksClient{Host: "ht_tp://example.com/"}
316328
err := ws.completeUrl(&http.Request{})

pools/resource_instance_pool.go

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,48 @@ type InstancePoolDiskSpec struct {
4343
DiskSize int32 `json:"disk_size,omitempty"`
4444
}
4545

46+
type AwsAllocationStrategy string
47+
48+
const (
49+
// AwsAllocationStrategyLowestPrice is allocation type for AWS Instance fleets
50+
AwsAllocationStrategyLowestPrice = "LOWEST_PRICE"
51+
// AwsAllocationStrategyCapacityOptimized is allocation type for AWS Instance fleets
52+
AwsAllocationStrategyCapacityOptimized = "CAPACITY_OPTIMIZED"
53+
)
54+
55+
type AwsFleetOption struct {
56+
AllocationStrategy AwsAllocationStrategy `json:"allocation_strategy" tf:"force_new,suppress_diff"`
57+
InstancePoolsToUseCount int32 `json:"instance_pools_to_use_count,omitempty" tf:"suppress_diff"`
58+
}
59+
60+
type AwsFleetLaunchTemplateOverride struct {
61+
AvailabilityZone string `json:"availability_zone" tf:"force_new,suppress_diff"`
62+
InstanceType string `json:"instance_type" tf:"force_new,suppress_diff"`
63+
}
64+
65+
type AwsInstancePoolFleetAttributes struct {
66+
FleetSpotOption *AwsFleetOption `json:"fleet_spot_option,omitempty" tf:"force_new,suppress_diff,conflicts:fleet_on_demand_option"`
67+
FleetOnDemandOption *AwsFleetOption `json:"fleet_on_demand_option,omitempty" tf:"force_new,suppress_diff,conflicts:fleet_spot_option"`
68+
FleetLaunchTemplateOverride []AwsFleetLaunchTemplateOverride `json:"launch_template_overrides" tf:"suppress_diff,force_new,slice_set,alias:launch_template_override"`
69+
}
70+
4671
// InstancePool describes the instance pool object on Databricks
4772
type InstancePool struct {
48-
InstancePoolID string `json:"instance_pool_id,omitempty" tf:"computed"`
49-
InstancePoolName string `json:"instance_pool_name"`
50-
MinIdleInstances int32 `json:"min_idle_instances,omitempty"`
51-
MaxCapacity int32 `json:"max_capacity,omitempty" tf:"suppress_diff"`
52-
IdleInstanceAutoTerminationMinutes int32 `json:"idle_instance_autotermination_minutes"`
53-
AwsAttributes *InstancePoolAwsAttributes `json:"aws_attributes,omitempty" tf:"force_new,suppress_diff"`
54-
AzureAttributes *InstancePoolAzureAttributes `json:"azure_attributes,omitempty" tf:"force_new,suppress_diff"`
55-
GcpAttributes *InstancePoolGcpAttributes `json:"gcp_attributes,omitempty" tf:"force_new,suppress_diff"`
56-
NodeTypeID string `json:"node_type_id" tf:"force_new"`
57-
CustomTags map[string]string `json:"custom_tags,omitempty" tf:"force_new"`
58-
EnableElasticDisk bool `json:"enable_elastic_disk,omitempty" tf:"force_new,suppress_diff"`
59-
DiskSpec *InstancePoolDiskSpec `json:"disk_spec,omitempty" tf:"force_new"`
60-
PreloadedSparkVersions []string `json:"preloaded_spark_versions,omitempty" tf:"force_new"`
61-
PreloadedDockerImages []clusters.DockerImage `json:"preloaded_docker_images,omitempty" tf:"force_new,slice_set,alias:preloaded_docker_image"`
73+
InstancePoolID string `json:"instance_pool_id,omitempty" tf:"computed"`
74+
InstancePoolName string `json:"instance_pool_name"`
75+
MinIdleInstances int32 `json:"min_idle_instances,omitempty"`
76+
MaxCapacity int32 `json:"max_capacity,omitempty" tf:"suppress_diff"`
77+
IdleInstanceAutoTerminationMinutes int32 `json:"idle_instance_autotermination_minutes"`
78+
AwsAttributes *InstancePoolAwsAttributes `json:"aws_attributes,omitempty" tf:"force_new,suppress_diff,computed"`
79+
AwsInstancePoolFleetAttributes *AwsInstancePoolFleetAttributes `json:"instance_pool_fleet_attributes,omitempty" tf:"force_new,suppress_diff,conflicts:node_type_id"`
80+
AzureAttributes *InstancePoolAzureAttributes `json:"azure_attributes,omitempty" tf:"force_new,suppress_diff"`
81+
GcpAttributes *InstancePoolGcpAttributes `json:"gcp_attributes,omitempty" tf:"force_new,suppress_diff"`
82+
NodeTypeID string `json:"node_type_id,omitempty" tf:"suppress_diff,force_new,conflicts:instance_pool_fleet_attributes"`
83+
CustomTags map[string]string `json:"custom_tags,omitempty" tf:"force_new"`
84+
EnableElasticDisk bool `json:"enable_elastic_disk,omitempty" tf:"force_new,suppress_diff"`
85+
DiskSpec *InstancePoolDiskSpec `json:"disk_spec,omitempty" tf:"force_new"`
86+
PreloadedSparkVersions []string `json:"preloaded_spark_versions,omitempty" tf:"force_new"`
87+
PreloadedDockerImages []clusters.DockerImage `json:"preloaded_docker_images,omitempty" tf:"force_new,slice_set,alias:preloaded_docker_image"`
6288
}
6389

6490
// InstancePoolStats contains the stats on a given pool
@@ -71,23 +97,24 @@ type InstancePoolStats struct {
7197

7298
// InstancePoolAndStats encapsulates a get response from the GET api for instance pools on Databricks
7399
type InstancePoolAndStats struct {
74-
InstancePoolID string `json:"instance_pool_id,omitempty" tf:"computed"`
75-
InstancePoolName string `json:"instance_pool_name"`
76-
MinIdleInstances int32 `json:"min_idle_instances,omitempty"`
77-
MaxCapacity int32 `json:"max_capacity,omitempty"`
78-
AwsAttributes *InstancePoolAwsAttributes `json:"aws_attributes,omitempty"`
79-
AzureAttributes *InstancePoolAzureAttributes `json:"azure_attributes,omitempty"`
80-
GcpAttributes *InstancePoolGcpAttributes `json:"gcp_attributes,omitempty"`
81-
NodeTypeID string `json:"node_type_id"`
82-
DefaultTags map[string]string `json:"default_tags,omitempty" tf:"computed"`
83-
CustomTags map[string]string `json:"custom_tags,omitempty"`
84-
IdleInstanceAutoTerminationMinutes int32 `json:"idle_instance_autotermination_minutes"`
85-
EnableElasticDisk bool `json:"enable_elastic_disk,omitempty"`
86-
DiskSpec *InstancePoolDiskSpec `json:"disk_spec,omitempty"`
87-
PreloadedSparkVersions []string `json:"preloaded_spark_versions,omitempty"`
88-
State string `json:"state,omitempty"`
89-
Stats *InstancePoolStats `json:"stats,omitempty"`
90-
PreloadedDockerImages []clusters.DockerImage `json:"preloaded_docker_images,omitempty" tf:"slice_set,alias:preloaded_docker_image"`
100+
InstancePoolID string `json:"instance_pool_id,omitempty" tf:"computed"`
101+
InstancePoolName string `json:"instance_pool_name"`
102+
MinIdleInstances int32 `json:"min_idle_instances,omitempty"`
103+
MaxCapacity int32 `json:"max_capacity,omitempty"`
104+
AwsAttributes *InstancePoolAwsAttributes `json:"aws_attributes,omitempty"`
105+
AwsInstancePoolFleetAttributes []AwsInstancePoolFleetAttributes `json:"instance_pool_fleet_attributes,omitempty"`
106+
AzureAttributes *InstancePoolAzureAttributes `json:"azure_attributes,omitempty"`
107+
GcpAttributes *InstancePoolGcpAttributes `json:"gcp_attributes,omitempty"`
108+
NodeTypeID string `json:"node_type_id,omitempty"`
109+
DefaultTags map[string]string `json:"default_tags,omitempty" tf:"computed"`
110+
CustomTags map[string]string `json:"custom_tags,omitempty"`
111+
IdleInstanceAutoTerminationMinutes int32 `json:"idle_instance_autotermination_minutes"`
112+
EnableElasticDisk bool `json:"enable_elastic_disk,omitempty"`
113+
DiskSpec *InstancePoolDiskSpec `json:"disk_spec,omitempty"`
114+
PreloadedSparkVersions []string `json:"preloaded_spark_versions,omitempty"`
115+
State string `json:"state,omitempty"`
116+
Stats *InstancePoolStats `json:"stats,omitempty"`
117+
PreloadedDockerImages []clusters.DockerImage `json:"preloaded_docker_images,omitempty" tf:"slice_set,alias:preloaded_docker_image"`
91118
}
92119

93120
// InstancePoolList shows list of instance pools
@@ -185,6 +212,15 @@ func ResourceInstancePool() *schema.Resource {
185212
clusters.EbsVolumeTypeThroughputOptimizedHdd,
186213
}, false)
187214
}
215+
if v, err := common.SchemaPath(s, "instance_pool_fleet_attributes", "fleet_on_demand_option", "allocation_strategy"); err == nil {
216+
v.ValidateFunc = validation.StringInSlice([]string{AwsAllocationStrategyLowestPrice}, false)
217+
}
218+
if v, err := common.SchemaPath(s, "instance_pool_fleet_attributes", "fleet_spot_option", "allocation_strategy"); err == nil {
219+
v.ValidateFunc = validation.StringInSlice([]string{
220+
AwsAllocationStrategyLowestPrice,
221+
AwsAllocationStrategyCapacityOptimized,
222+
}, false)
223+
}
188224
if v, err := common.SchemaPath(s, "preloaded_docker_image", "url"); err == nil {
189225
v.ForceNew = true
190226
}

0 commit comments

Comments
 (0)