Skip to content

Commit

Permalink
fix: optionally pass group UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanbouz authored and MCBrandenburg committed Mar 30, 2022
1 parent fdc32df commit 90c5bd9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ resource "fusionauth_group" "my_group" {

## Argument Reference

* `group_id` - (Optional) The Id to use for the new Group. If not specified a secure random UUID will be generated.
* `data` - (Optional) An object that can hold any information about the Group that should be persisted.
* `name` - (Required) The name of the Group.
* `role_ids` - (Optional) The Application Roles to assign to this group.
* `tenant_id` - (Required) The unique Id of the tenant used to scope this API request.
* `tenant_id` - (Required) The unique Id of the tenant used to scope this API request.
16 changes: 15 additions & 1 deletion fusionauth/resource_fusionauth_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ func newGroup() *schema.Resource {
UpdateContext: updateGroup,
DeleteContext: deleteGroup,
Schema: map[string]*schema.Schema{
"group_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The Id to use for the new Group. If not specified a secure random UUID will be generated.",
ValidateFunc: validation.IsUUID,
},
"data": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -47,8 +55,14 @@ func newGroup() *schema.Resource {
}

func buildGroup(data *schema.ResourceData) fusionauth.GroupRequest {
var gid string
if gi, ok := data.Get("group_id").(string); ok {
gid = gi
}

g := fusionauth.GroupRequest{
Group: fusionauth.Group{
Id: gid,
Data: nil,
Name: data.Get("name").(string),
TenantId: data.Get("tenant_id").(string),
Expand All @@ -67,7 +81,7 @@ func createGroup(_ context.Context, data *schema.ResourceData, i interface{}) di
defer func() {
client.FAClient.TenantId = oldTenantID
}()
resp, faErrs, err := client.FAClient.CreateGroup("", g)
resp, faErrs, err := client.FAClient.CreateGroup(g.Group.Id, g)
if err != nil {
return diag.Errorf("CreateGroup err: %v", err)
}
Expand Down

0 comments on commit 90c5bd9

Please sign in to comment.