/
data_source_ibm_org.go
52 lines (45 loc) · 1.11 KB
/
data_source_ibm_org.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
package ibm
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceIBMOrg() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMOrgRead,
Schema: map[string]*schema.Schema{
"org": {
Description: "Org name, for example myorg@domain",
Type: schema.TypeString,
Optional: true,
Deprecated: "use name instead",
ExactlyOneOf: []string{"org", "name"},
},
"name": {
Description: "Org name, for example myorg@domain",
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"org", "name"},
},
},
}
}
func dataSourceIBMOrgRead(d *schema.ResourceData, meta interface{}) error {
cfAPI, err := meta.(ClientSession).MccpAPI()
if err != nil {
return err
}
orgAPI := cfAPI.Organizations()
var org string
if v, ok := d.GetOk("name"); ok {
org = v.(string)
}
if v, ok := d.GetOk("org"); ok {
org = v.(string)
}
orgFields, err := orgAPI.FindByName(org, BluemixRegion)
if err != nil {
return fmt.Errorf("Error retrieving organisation: %s", err)
}
d.SetId(orgFields.GUID)
return nil
}