-
Notifications
You must be signed in to change notification settings - Fork 372
/
data_instance_pool.go
46 lines (41 loc) · 1.24 KB
/
data_instance_pool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package pools
import (
"context"
"fmt"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func getPool(poolsAPI InstancePoolsAPI, name string) (*InstancePoolAndStats, error) {
poolList, err := poolsAPI.List()
if err != nil {
return nil, err
}
for _, pool := range poolList.InstancePools {
if pool.InstancePoolName == name {
return &pool, nil
}
}
return nil, fmt.Errorf("instance pool '%s' doesn't exist", name)
}
// DataSourceInstancePool returns information about instance pool specified by name
func DataSourceInstancePool() common.Resource {
type poolDetails struct {
Name string `json:"name"`
Attributes *InstancePoolAndStats `json:"pool_info,omitempty" tf:"computed"`
}
s := common.StructToSchema(poolDetails{}, nil)
return common.Resource{
Schema: s,
Read: func(ctx context.Context, d *schema.ResourceData, m *common.DatabricksClient) error {
name := d.Get("name").(string)
poolsAPI := NewInstancePoolsAPI(ctx, m)
pool, err := getPool(poolsAPI, name)
if err != nil {
return err
}
d.SetId(pool.InstancePoolID)
err = common.StructToData(poolDetails{Name: name, Attributes: pool}, s, d)
return err
},
}
}