|
| 1 | +package ovh |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 8 | +) |
| 9 | + |
| 10 | +func dataSourceMeIdentityUser() *schema.Resource { |
| 11 | + return &schema.Resource{ |
| 12 | + Read: dataSourceMeIdentityUserRead, |
| 13 | + Schema: map[string]*schema.Schema{ |
| 14 | + "user": { |
| 15 | + Type: schema.TypeString, |
| 16 | + Required: true, |
| 17 | + Description: "User's login", |
| 18 | + }, |
| 19 | + "login": { |
| 20 | + Type: schema.TypeString, |
| 21 | + Computed: true, |
| 22 | + Description: "User's login suffix", |
| 23 | + }, |
| 24 | + "creation": { |
| 25 | + Type: schema.TypeString, |
| 26 | + Computed: true, |
| 27 | + Description: "Creation date of this user", |
| 28 | + }, |
| 29 | + "description": { |
| 30 | + Type: schema.TypeString, |
| 31 | + Computed: true, |
| 32 | + Description: "User description", |
| 33 | + }, |
| 34 | + "email": { |
| 35 | + Type: schema.TypeString, |
| 36 | + Computed: true, |
| 37 | + Description: "User's email", |
| 38 | + }, |
| 39 | + "group": { |
| 40 | + Type: schema.TypeString, |
| 41 | + Computed: true, |
| 42 | + Description: "User's group", |
| 43 | + }, |
| 44 | + "last_update": { |
| 45 | + Type: schema.TypeString, |
| 46 | + Computed: true, |
| 47 | + Description: "Last update of this user", |
| 48 | + }, |
| 49 | + "password_last_update": { |
| 50 | + Type: schema.TypeString, |
| 51 | + Computed: true, |
| 52 | + Description: "When the user changed his password for the last time", |
| 53 | + }, |
| 54 | + "status": { |
| 55 | + Type: schema.TypeString, |
| 56 | + Computed: true, |
| 57 | + Description: "Current user's status", |
| 58 | + }, |
| 59 | + }, |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +func dataSourceMeIdentityUserRead(d *schema.ResourceData, meta interface{}) error { |
| 64 | + config := meta.(*Config) |
| 65 | + |
| 66 | + identityUser := &MeIdentityUserResponse{} |
| 67 | + |
| 68 | + user := d.Get("user").(string) |
| 69 | + err := config.OVHClient.Get( |
| 70 | + fmt.Sprintf("/me/identity/user/%s", user), |
| 71 | + identityUser, |
| 72 | + ) |
| 73 | + if err != nil { |
| 74 | + return fmt.Errorf("Unable to find identity user %s:\n\t %q", user, err) |
| 75 | + } |
| 76 | + log.Printf("[DEBUG] identity user for %s: %+v", user, identityUser) |
| 77 | + |
| 78 | + d.SetId(user) |
| 79 | + d.Set("login", identityUser.Login) |
| 80 | + d.Set("creation", identityUser.Creation) |
| 81 | + d.Set("description", identityUser.Description) |
| 82 | + d.Set("email", identityUser.Email) |
| 83 | + d.Set("group", identityUser.Group) |
| 84 | + d.Set("last_update", identityUser.LastUpdate) |
| 85 | + d.Set("password_last_update", identityUser.PasswordLastUpdate) |
| 86 | + d.Set("status", identityUser.Status) |
| 87 | + |
| 88 | + return nil |
| 89 | +} |
0 commit comments