diff --git a/docs/resources/user.md b/docs/resources/user.md index b3ea8129..f86716b3 100644 --- a/docs/resources/user.md +++ b/docs/resources/user.md @@ -26,6 +26,7 @@ Configures a Frontegg user. - `automatically_verify` (Boolean) Whether the user gets verified upon creation. - `password` (String, Sensitive) The user's login password. - `skip_invite_email` (Boolean) Skip sending the invite email. If true, user is automatically verified on creation. +- `superuser` (Boolean) Whether the user is a super user. ### Read-Only diff --git a/go.sum b/go.sum index b37b228c..2cf6c49b 100644 --- a/go.sum +++ b/go.sum @@ -154,6 +154,7 @@ github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= +github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= @@ -182,6 +183,7 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mitchellh/cli v1.1.4 h1:qj8czE26AU4PbiaPXK5uVmMSM+V5BYsFBiM9HhGRLUA= github.com/mitchellh/cli v1.1.4/go.mod h1:vTLESy5mRhKOs9KDp0/RATawxP1UqBmdrpVRMnpcvKQ= +github.com/mitchellh/cli v1.1.5 h1:OxRIeJXpAMztws/XHlN2vu6imG5Dpq+j61AzAX5fLng= github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= diff --git a/provider/resource_frontegg_user.go b/provider/resource_frontegg_user.go index 867a7246..b016b686 100644 --- a/provider/resource_frontegg_user.go +++ b/provider/resource_frontegg_user.go @@ -11,6 +11,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +type fronteggSuperUser struct { + SuperUser bool `json:"superUser"` +} + type fronteggUserRole struct { Id string `json:"id,omitempty"` Key string `json:"key,omitempty"` @@ -24,6 +28,7 @@ type fronteggUser struct { ReadRoleIDs []fronteggUserRole `json:"roles,omitempty"` SkipInviteEmail bool `json:"skipInviteEmail,omitempty"` Verified bool `json:"verified,omitempty"` + SuperUser bool `json:"superUser,omitempty"` } const fronteggUserPath = "/identity/resources/users/v2" @@ -77,6 +82,11 @@ func resourceFronteggUser() *schema.Resource { Type: schema.TypeString, Required: true, }, + "superuser": { + Description: "Whether the user is a super user.", + Type: schema.TypeBool, + Optional: true, + }, }, } } @@ -88,6 +98,7 @@ func resourceFronteggUserSerialize(d *schema.ResourceData) fronteggUser { Password: d.Get("password").(string), SkipInviteEmail: d.Get("skip_invite_email").(bool), CreateRoleIDs: d.Get("role_ids").(*schema.Set).List(), + SuperUser: d.Get("superuser").(bool), } } @@ -115,10 +126,21 @@ func resourceFronteggUserCreate(ctx context.Context, d *schema.ResourceData, met if err := clientHolder.ApiClient.RequestWithHeaders(ctx, "POST", fronteggUserPath, headers, in, &out); err != nil { return diag.FromErr(err) } + if err := resourceFronteggUserDeserialize(d, out); err != nil { return diag.FromErr(err) } + superUser := d.Get("superuser").(bool) + if superUser { + in := fronteggSuperUser{ + SuperUser: superUser, + } + if err := clientHolder.ApiClient.Put(ctx, fmt.Sprintf("%s/%s/superuser", fronteggUserPathV1, out.Key), in, nil); err != nil { + return diag.FromErr(err) + } + } + if !d.Get("automatically_verify").(bool) { return nil } @@ -197,6 +219,17 @@ func resourceFronteggUserUpdate(ctx context.Context, d *schema.ResourceData, met } } + // Super User: + if d.HasChange("superuser") { + superUser := d.Get("superuser").(bool) + in := fronteggSuperUser{ + SuperUser: superUser, + } + if err := clientHolder.ApiClient.Put(ctx, fmt.Sprintf("%s/%s/superuser", fronteggUserPathV1, d.Id()), in, nil); err != nil { + return diag.FromErr(err) + } + } + // Roles: if d.HasChange("role_ids") { headers := http.Header{}