/
identity_group_data_source.go
95 lines (71 loc) · 2.06 KB
/
identity_group_data_source.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
89
90
91
92
93
94
95
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
package provider
import (
"context"
"strconv"
"github.com/hashicorp/terraform/helper/schema"
oci_identity "github.com/oracle/oci-go-sdk/identity"
)
func IdentityGroupDataSource() *schema.Resource {
fieldMap := make(map[string]*schema.Schema)
fieldMap["group_id"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
return GetSingularDataSourceItemSchema(IdentityGroupResource(), fieldMap, readSingularIdentityGroup)
}
func readSingularIdentityGroup(d *schema.ResourceData, m interface{}) error {
sync := &IdentityGroupDataSourceCrud{}
sync.D = d
sync.Client = m.(*OracleClients).identityClient
return ReadResource(sync)
}
type IdentityGroupDataSourceCrud struct {
D *schema.ResourceData
Client *oci_identity.IdentityClient
Res *oci_identity.GetGroupResponse
}
func (s *IdentityGroupDataSourceCrud) VoidState() {
s.D.SetId("")
}
func (s *IdentityGroupDataSourceCrud) Get() error {
request := oci_identity.GetGroupRequest{}
if groupId, ok := s.D.GetOkExists("group_id"); ok {
tmp := groupId.(string)
request.GroupId = &tmp
}
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "identity")
response, err := s.Client.GetGroup(context.Background(), request)
if err != nil {
return err
}
s.Res = &response
return nil
}
func (s *IdentityGroupDataSourceCrud) SetData() error {
if s.Res == nil {
return nil
}
s.D.SetId(*s.Res.Id)
if s.Res.CompartmentId != nil {
s.D.Set("compartment_id", *s.Res.CompartmentId)
}
if s.Res.DefinedTags != nil {
s.D.Set("defined_tags", definedTagsToMap(s.Res.DefinedTags))
}
if s.Res.Description != nil {
s.D.Set("description", *s.Res.Description)
}
s.D.Set("freeform_tags", s.Res.FreeformTags)
if s.Res.InactiveStatus != nil {
s.D.Set("inactive_state", strconv.FormatInt(*s.Res.InactiveStatus, 10))
}
if s.Res.Name != nil {
s.D.Set("name", *s.Res.Name)
}
s.D.Set("state", s.Res.LifecycleState)
if s.Res.TimeCreated != nil {
s.D.Set("time_created", s.Res.TimeCreated.String())
}
return nil
}