This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataSource_confluent_cluster.go
88 lines (83 loc) · 2.1 KB
/
dataSource_confluent_cluster.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
82
83
84
85
86
87
88
package main
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)
func dataSourceConfluentCluster() *schema.Resource {
return &schema.Resource{
Read: dataSourceClusterRead,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
ForceNew: true,
Required: true,
Description: "Cluster name",
},
"account_id": &schema.Schema{
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Description: "Account ID. If not set, using default account",
},
"organization_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"endpoint": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"api_endpoint": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"status": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"durability": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"host": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"port": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"protocol": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceClusterRead(d *schema.ResourceData, m interface{}) error {
config := m.(*Config)
if err := config.connect(); err != nil {
return err
}
accountId, accountIdSet := d.GetOk("account_id")
if !accountIdSet {
accountId = config.Me.Account.Id
}
log.Printf("Reading cluster: " + d.Get("name").(string) + " and account " + accountId.(string))
cluster, err := config.getCluster(accountId.(string), d.Get("name").(string))
if err != nil {
d.SetId("")
return nil
}
d.Set("name", cluster.Name)
d.Set("account_id", accountId.(string))
d.Set("endpoint", cluster.Endpoint)
d.Set("api_endpoint", cluster.ApiEndpoint)
d.Set("status", cluster.Status)
d.Set("durability", cluster.Durability)
d.Set("host", cluster.Host())
d.Set("port", cluster.Port())
d.Set("protocol", cluster.Protocol())
d.SetId(cluster.Id)
return nil
}