Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyiliev committed Dec 1, 2023
1 parent 1141d3f commit d08bc37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
1 change: 0 additions & 1 deletion integration/user.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
resource "materialize_user" "example_user" {
for_each = toset(["1", "2", "3", "4", "5"])
email = "example-user${each.key}@example.com"
auth_provider = "local"
roles = ["Member", "Admin"]
}
5 changes: 3 additions & 2 deletions pkg/datasources/datasource_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func Region() *schema.Resource {
Description: "The name of the region.",
},
"url": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Description: "The URL at which the Region API can be reached.",
},
"cloud_provider": {
Type: schema.TypeString,
Expand Down
28 changes: 13 additions & 15 deletions pkg/resources/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func User() *schema.Resource {
Description: "The email address of the user. This must be unique across all users in the organization.",
},
"auth_provider": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Computed: true,
Description: "The authentication provider for the user.",
},
"roles": {
Type: schema.TypeList,
Expand All @@ -48,19 +48,14 @@ func User() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"profile_picture_url": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

// CreateUserRequest is used to serialize the request body for creating a new user.
type CreateUserRequest struct {
Email string `json:"email"`
Provider string `json:"provider"`
RoleIDs []string `json:"roleIds"`
Email string `json:"email"`
RoleIDs []string `json:"roleIds"`
}

// CreatedUser represents the expected structure of a user creation response.
Expand All @@ -70,6 +65,7 @@ type CreatedUser struct {
ProfilePictureURL string `json:"profilePictureUrl"`
Verified bool `json:"verified"`
Metadata string `json:"metadata"`
Provider string `json:"provider"`
}

type FronteggRolesResponse struct {
Expand All @@ -94,7 +90,7 @@ func userCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) d
client := providerMeta.Frontegg

email := d.Get("email").(string)
provider := d.Get("auth_provider").(string)
// provider := "local"
roleNames := convertToStringSlice(d.Get("roles").([]interface{}))

for _, roleName := range roleNames {
Expand All @@ -120,9 +116,8 @@ func userCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) d
}

createUserRequest := CreateUserRequest{
Email: email,
Provider: provider,
RoleIDs: roleIDs,
Email: email,
RoleIDs: roleIDs,
}

requestBody, err := json.Marshal(createUserRequest)
Expand Down Expand Up @@ -153,6 +148,9 @@ func userCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) d
return diag.FromErr(fmt.Errorf("error decoding response: %s", err))
}

d.Set("verified", createdUser.Verified)
d.Set("metadata", createdUser.Metadata)
d.Set("auth_provider", createdUser.Provider)
d.SetId(createdUser.ID)
return nil
}
Expand Down Expand Up @@ -198,9 +196,9 @@ func userRead(ctx context.Context, d *schema.ResourceData, meta interface{}) dia

// Update the Terraform state with the fetched user data
d.Set("email", user.Email)
d.Set("profile_picture_url", user.ProfilePictureURL)
d.Set("verified", user.Verified)
d.Set("metadata", user.Metadata)
d.Set("auth_provider", user.Provider)

return nil
}
Expand Down

0 comments on commit d08bc37

Please sign in to comment.