/
identity_ui_password_resource.go
141 lines (113 loc) · 3.08 KB
/
identity_ui_password_resource.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// 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 IdentityUiPasswordResource() *schema.Resource {
return &schema.Resource{
Timeouts: DefaultTimeout,
Create: createIdentityUiPassword,
Read: readIdentityUiPassword,
Delete: deleteIdentityUiPassword,
Schema: map[string]*schema.Schema{
// Required
"user_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
// Optional
// Computed
"inactive_status": {
Type: schema.TypeString,
Computed: true,
},
"password": {
Type: schema.TypeString,
Computed: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"time_created": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func createIdentityUiPassword(d *schema.ResourceData, m interface{}) error {
sync := &IdentityUiPasswordResourceCrud{}
sync.D = d
sync.Client = m.(*OracleClients).identityClient
return CreateResource(d, sync)
}
func readIdentityUiPassword(d *schema.ResourceData, m interface{}) error {
return nil
}
func deleteIdentityUiPassword(d *schema.ResourceData, m interface{}) error {
return nil
}
type IdentityUiPasswordResourceCrud struct {
BaseCrud
Client *oci_identity.IdentityClient
Res *oci_identity.UiPassword
DisableNotFoundRetries bool
}
func (s *IdentityUiPasswordResourceCrud) ID() string {
return *s.Res.UserId
}
func (s *IdentityUiPasswordResourceCrud) CreatedPending() []string {
return []string{
string(oci_identity.UiPasswordLifecycleStateCreating),
}
}
func (s *IdentityUiPasswordResourceCrud) CreatedTarget() []string {
return []string{
string(oci_identity.UiPasswordLifecycleStateActive),
}
}
func (s *IdentityUiPasswordResourceCrud) DeletedPending() []string {
return []string{
string(oci_identity.UiPasswordLifecycleStateDeleting),
}
}
func (s *IdentityUiPasswordResourceCrud) DeletedTarget() []string {
return []string{
string(oci_identity.UiPasswordLifecycleStateDeleted),
}
}
func (s *IdentityUiPasswordResourceCrud) Create() error {
request := oci_identity.CreateOrResetUIPasswordRequest{}
if userId, ok := s.D.GetOkExists("user_id"); ok {
tmp := userId.(string)
request.UserId = &tmp
}
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "identity")
response, err := s.Client.CreateOrResetUIPassword(context.Background(), request)
if err != nil {
return err
}
s.Res = &response.UiPassword
return nil
}
func (s *IdentityUiPasswordResourceCrud) SetData() error {
if s.Res.InactiveStatus != nil {
s.D.Set("inactive_status", strconv.FormatInt(*s.Res.InactiveStatus, 10))
}
if s.Res.Password != nil {
s.D.Set("password", *s.Res.Password)
}
s.D.Set("state", s.Res.LifecycleState)
if s.Res.TimeCreated != nil {
s.D.Set("time_created", s.Res.TimeCreated.String())
}
if s.Res.UserId != nil {
s.D.Set("user_id", *s.Res.UserId)
}
return nil
}