forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kusto_cluster_data_source.go
81 lines (63 loc) · 2.29 KB
/
kusto_cluster_data_source.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package kusto
import (
"fmt"
"time"
"github.com/kevinklinger/terraform-provider-azurerm/v2/helpers/azure"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/clients"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/services/kusto/validate"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tags"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/pluginsdk"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/timeouts"
"github.com/kevinklinger/terraform-provider-azurerm/v2/utils"
)
func dataSourceKustoCluster() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceKustoClusterRead,
Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.ClusterName,
},
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
"location": azure.SchemaLocationForDataSource(),
"uri": {
Type: pluginsdk.TypeString,
Computed: true,
},
"data_ingestion_uri": {
Type: pluginsdk.TypeString,
Computed: true,
},
"tags": tags.SchemaDataSource(),
},
}
}
func dataSourceKustoClusterRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Kusto.ClustersClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Kusto Cluster %q (Resource Group %q) does not exist", name, resourceGroup)
}
return fmt.Errorf("retrieving Kusto Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.SetId(*resp.ID)
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
if clusterProperties := resp.ClusterProperties; clusterProperties != nil {
d.Set("uri", clusterProperties.URI)
d.Set("data_ingestion_uri", clusterProperties.DataIngestionURI)
}
return tags.FlattenAndSet(d, resp.Tags)
}