Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring first user role #130

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ resource "frontegg_role" "example" {

### Optional

- `first_user` (Boolean) Whether the role should be applied to the first user in the tenant (new tenants only).
- `tenant_id` (String) The ID of the tenant that owns the role.

### Read-Only
Expand Down
1 change: 1 addition & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ resource "frontegg_role" "example" {
name = "Example"
key = "example"
default = true
first_user = true
description = "An example of a role"
level = 0
permission_ids = [
Expand Down
40 changes: 25 additions & 15 deletions provider/resource_frontegg_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import (
const fronteggRolePath = "/identity/resources/roles/v1"

type fronteggRole struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
Description string `json:"description,omitempty"`
Level int `json:"level"`
IsDefault bool `json:"isDefault"`
Permissions []string `json:"permissions"`
TenantID string `json:"tenantId,omitempty"`
VendorID string `json:"vendorId,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
Description string `json:"description,omitempty"`
Level int `json:"level"`
IsDefault bool `json:"isDefault"`
FirstUserRole bool `json:"firstUserRole"`
Permissions []string `json:"permissions"`
TenantID string `json:"tenantId,omitempty"`
VendorID string `json:"vendorId,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
}

type fronteggRolePermissions struct {
Expand Down Expand Up @@ -62,6 +63,11 @@ func resourceFronteggRole() *schema.Resource {
Type: schema.TypeBool,
Required: true,
},
"first_user": {
Description: "Whether the role should be applied to the first user in the tenant (new tenants only).",
Type: schema.TypeBool,
Optional: true,
},
"level": {
Description: "The level of the role in the role hierarchy.",
Type: schema.TypeInt,
Expand Down Expand Up @@ -94,11 +100,12 @@ func resourceFronteggRole() *schema.Resource {

func resourceFronteggRoleSerialize(d *schema.ResourceData) fronteggRole {
return fronteggRole{
Name: d.Get("name").(string),
IsDefault: d.Get("default").(bool),
Key: d.Get("key").(string),
Description: d.Get("description").(string),
Level: d.Get("level").(int),
Name: d.Get("name").(string),
IsDefault: d.Get("default").(bool),
FirstUserRole: d.Get("first_user").(bool),
Key: d.Get("key").(string),
Description: d.Get("description").(string),
Level: d.Get("level").(int),
}
}

Expand All @@ -122,6 +129,9 @@ func resourceFronteggRoleDeserialize(d *schema.ResourceData, f fronteggRole) err
if err := d.Set("default", f.IsDefault); err != nil {
return err
}
if err := d.Set("first_user", f.FirstUserRole); err != nil {
return err
}
if err := d.Set("level", f.Level); err != nil {
return err
}
Expand Down