-
Notifications
You must be signed in to change notification settings - Fork 251
/
Copy pathdata_source_cloud_organization.go
68 lines (62 loc) · 1.55 KB
/
data_source_cloud_organization.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
package cloud
import (
"context"
"strconv"
"github.com/grafana/grafana-com-public-clients/go/gcom"
"github.com/grafana/terraform-provider-grafana/v3/internal/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func datasourceOrganization() *common.DataSource {
schema := &schema.Resource{
ReadContext: withClient[schema.ReadContextFunc](datasourceOrganizationRead),
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"slug": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"url": {
Type: schema.TypeString,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
},
}
return common.NewLegacySDKDataSource("grafana_cloud_organization", schema)
}
func datasourceOrganizationRead(ctx context.Context, d *schema.ResourceData, client *gcom.APIClient) diag.Diagnostics {
id := d.Get("id").(string)
if id == "" {
id = d.Get("slug").(string)
}
org, _, err := client.OrgsAPI.GetOrg(ctx, id).Execute()
if err != nil {
return apiError(err)
}
id = strconv.FormatInt(int64(org.Id), 10)
d.SetId(id)
d.Set("id", id)
d.Set("name", org.Name)
d.Set("slug", org.Slug)
d.Set("url", org.Url)
d.Set("created_at", org.CreatedAt)
d.Set("updated_at", org.UpdatedAt.Get())
return nil
}