-
Notifications
You must be signed in to change notification settings - Fork 131
/
data_me_identity_user.go
89 lines (81 loc) · 2.16 KB
/
data_me_identity_user.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
package ovh
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceMeIdentityUser() *schema.Resource {
return &schema.Resource{
Read: dataSourceMeIdentityUserRead,
Schema: map[string]*schema.Schema{
"user": {
Type: schema.TypeString,
Required: true,
Description: "User's login",
},
"login": {
Type: schema.TypeString,
Computed: true,
Description: "User's login suffix",
},
"creation": {
Type: schema.TypeString,
Computed: true,
Description: "Creation date of this user",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "User description",
},
"email": {
Type: schema.TypeString,
Computed: true,
Description: "User's email",
},
"group": {
Type: schema.TypeString,
Computed: true,
Description: "User's group",
},
"last_update": {
Type: schema.TypeString,
Computed: true,
Description: "Last update of this user",
},
"password_last_update": {
Type: schema.TypeString,
Computed: true,
Description: "When the user changed his password for the last time",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Current user's status",
},
},
}
}
func dataSourceMeIdentityUserRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
identityUser := &MeIdentityUserResponse{}
user := d.Get("user").(string)
err := config.OVHClient.Get(
fmt.Sprintf("/me/identity/user/%s", user),
identityUser,
)
if err != nil {
return fmt.Errorf("Unable to find identity user %s:\n\t %q", user, err)
}
log.Printf("[DEBUG] identity user for %s: %+v", user, identityUser)
d.SetId(user)
d.Set("login", identityUser.Login)
d.Set("creation", identityUser.Creation)
d.Set("description", identityUser.Description)
d.Set("email", identityUser.Email)
d.Set("group", identityUser.Group)
d.Set("last_update", identityUser.LastUpdate)
d.Set("password_last_update", identityUser.PasswordLastUpdate)
d.Set("status", identityUser.Status)
return nil
}