-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93b7cc4
commit e6aa8ed
Showing
3 changed files
with
117 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package outscale | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
oscgo "github.com/outscale/osc-sdk-go/v2" | ||
"github.com/outscale/terraform-provider-outscale/utils" | ||
) | ||
|
||
func DataSourceUserGroupsPerUser() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: DataSourceUserGroupsPerUserRead, | ||
Schema: map[string]*schema.Schema{ | ||
"user_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"user_path": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"user_groups": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"user_group_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"path": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"user_group_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"orn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"creation_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"last_modification_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func DataSourceUserGroupsPerUserRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*OutscaleClient).OSCAPI | ||
|
||
req := oscgo.NewReadUserGroupsPerUserRequest(d.Get("user_name").(string)) | ||
userPath := d.Get("user_path").(string) | ||
if userPath != "" { | ||
req.SetUserPath(userPath) | ||
} | ||
var resp oscgo.ReadUserGroupsPerUserResponse | ||
err := resource.Retry(2*time.Minute, func() *resource.RetryError { | ||
rp, httpResp, err := conn.UserGroupApi.ReadUserGroupsPerUser(context.Background()).ReadUserGroupsPerUserRequest(*req).Execute() | ||
if err != nil { | ||
return utils.CheckThrottling(httpResp, err) | ||
} | ||
resp = rp | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if _, ok := resp.GetUserGroupsOk(); !ok { | ||
return fmt.Errorf("Unable to find user groups") | ||
} | ||
d.SetId(resource.UniqueId()) | ||
userGps := resp.GetUserGroups() | ||
userGroups := make([]map[string]interface{}, len(userGps)) | ||
|
||
for i, v := range userGps { | ||
userGroup := make(map[string]interface{}) | ||
userGroup["user_group_name"] = v.GetName() | ||
userGroup["user_group_id"] = v.GetUserGroupId() | ||
userGroup["path"] = v.GetPath() | ||
userGroup["orn"] = v.GetOrn() | ||
userGroup["creation_date"] = v.GetCreationDate() | ||
userGroup["last_modification_date"] = v.GetLastModificationDate() | ||
userGroups[i] = userGroup | ||
} | ||
return d.Set("user_groups", userGroups) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters