-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathdata_source_opensearch_host.go
49 lines (41 loc) · 1.18 KB
/
data_source_opensearch_host.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
package provider
import (
"reflect"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceOpensearchHost() *schema.Resource {
return &schema.Resource{
Description: "`opensearch_host` can be used to retrieve the host URL for the provider's current cluster.",
Read: dataSourceOpensearchHostRead,
Schema: map[string]*schema.Schema{
"active": {
Type: schema.TypeBool,
Required: true,
Description: "should be set to `true`",
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: "the url of the active cluster",
},
},
}
}
func dataSourceOpensearchHostRead(d *schema.ResourceData, m interface{}) error {
// The upstream client does not export the property for the urls
// it's using. Presumably the URLS would be available where the client is
// intantiated, but in terraform, that's not always practicable.
var err error
osClient, err := getClient(m.(*ProviderConf))
if err != nil {
return err
}
var url string
urls := reflect.ValueOf(osClient).Elem().FieldByName("urls")
if urls.Len() > 0 {
url = urls.Index(0).String()
}
d.SetId(url)
err = d.Set("url", url)
return err
}