-
Notifications
You must be signed in to change notification settings - Fork 7
/
data_source_organization.go
76 lines (68 loc) · 2.12 KB
/
data_source_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
69
70
71
72
73
74
75
76
package cloudsmith
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func dataSourceOrganizationRead(d *schema.ResourceData, m interface{}) error {
pc := m.(*providerConfig)
slug := requiredString(d, "slug")
req := pc.APIClient.OrgsApi.OrgsRead(pc.Auth, slug)
organization, _, err := pc.APIClient.OrgsApi.OrgsReadExecute(req)
if err != nil {
return err
}
d.Set("country", organization.GetCountry())
d.Set("created_at", timeToString(organization.GetCreatedAt()))
d.Set("location", organization.GetLocation())
d.Set("name", organization.GetName())
d.Set("slug", organization.GetSlug())
d.Set("slug_perm", organization.GetSlugPerm())
d.Set("tagline", organization.GetTagline())
d.SetId(organization.GetSlugPerm())
return nil
}
//nolint:funlen
func dataSourceOrganization() *schema.Resource {
return &schema.Resource{
Read: dataSourceOrganizationRead,
Schema: map[string]*schema.Schema{
"country": {
Type: schema.TypeString,
Description: "Country in which the organization is based.",
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Description: "ISO 8601 timestamp at which the organization was created.",
Computed: true,
},
"location": {
Type: schema.TypeString,
Description: "The city/town/area in which the organization is based.",
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "A descriptive name for the organization.",
Computed: true,
},
"slug": {
Type: schema.TypeString,
Description: "The slug identifies the organization in URIs.",
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"slug_perm": {
Type: schema.TypeString,
Description: "The slug_perm immutably identifies the organization. " +
"It will never change once an organization has been created.",
Computed: true,
},
"tagline": {
Type: schema.TypeString,
Description: "A short public description for the organization.",
Computed: true,
},
},
}
}