Skip to content

Commit

Permalink
added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Nov 13, 2024
1 parent 0fead5a commit 4a1ca4c
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 33 deletions.
157 changes: 157 additions & 0 deletions docs/resources/user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
---
page_title: "spectrocloud_user Resource - terraform-provider-spectrocloud"
subcategory: ""
description: |-
Create and manage projects in Palette.
---

# spectrocloud_user (Resource)

Create and manage projects in Palette.

You can learn more about managing users in Palette by reviewing the [Users](https://docs.spectrocloud.com/user-management/) guide.

## Example Usage

An example of creating a user resource with assigned teams and custom roles in Palette.

```hcl
resource "spectrocloud_user" "user-test"{
first_name = "tf"
last_name = "test"
email = "[email protected]"
team_ids = [data.spectrocloud_team.team2.id]
project_role {
project_id = data.spectrocloud_project.default.id
role_ids = [for r in data.spectrocloud_role.app_roles : r.id]
}
project_role {
project_id = data.spectrocloud_project.ranjith.id
role_ids = [for r in data.spectrocloud_role.app_roles : r.id]
}
tenant_role = [for t in data.spectrocloud_role.tenant_roles : t.id]
workspace_role {
project_id = data.spectrocloud_project.default.id
workspace {
id = data.spectrocloud_workspace.workspace.id
role_ids = [for w in data.spectrocloud_role.workspace_roles : w.id]
}
workspace {
id = data.spectrocloud_workspace.workspace2.id
role_ids = ["66fbea622947f81fc26983e6"]
}
}
resource_role {
project_ids = [data.spectrocloud_project.default.id, data.spectrocloud_project.ranjith.id]
filter_ids = [data.spectrocloud_filter.filter.id]
role_ids = [for r in data.spectrocloud_role.resource_roles : r.id]
}
resource_role {
project_ids = [data.spectrocloud_project.ranjith.id]
filter_ids = [data.spectrocloud_filter.filter.id]
role_ids = [for re in data.spectrocloud_role.resource_roles_editor : re.id]
}
}
```

The example below demonstrates how to create an user with only assigned teams.

```hcl
resource "spectrocloud_user" "user-test"{
first_name = "tf"
last_name = "test"
email = "[email protected]"
team_ids = [data.spectrocloud_team.team2.id]
}
```

### Importing existing user states

```hcl
# import existing user example
import {
to = spectrocloud_user.test_user
id = "{userUID}"
}
# To generate TF configuration.
terraform plan -generate-config-out=test_user.tf
# To import State file
terraform import spectrocloud_user.test_user {userUID}
```


<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `email` (String) The email of the user.
- `first_name` (String) The first name of the user.
- `last_name` (String) The last name of the user.

### Optional

- `project_role` (Block Set) List of project roles to be associated with the user. (see [below for nested schema](#nestedblock--project_role))
- `resource_role` (Block Set) (see [below for nested schema](#nestedblock--resource_role))
- `team_ids` (List of String) The team id's assigned to the user.
- `tenant_role` (Set of String) List of tenant role ids to be associated with the user.
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
- `workspace_role` (Block Set) List of workspace roles to be associated with the user. (see [below for nested schema](#nestedblock--workspace_role))

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--project_role"></a>
### Nested Schema for `project_role`

Required:

- `project_id` (String) Project id to be associated with the user.
- `role_ids` (Set of String) List of project role ids to be associated with the user.


<a id="nestedblock--resource_role"></a>
### Nested Schema for `resource_role`

Required:

- `filter_ids` (Set of String) List of filter ids.
- `project_ids` (Set of String) Project id's to be associated with the user.
- `role_ids` (Set of String) List of resource role ids to be associated with the user.


<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `create` (String)
- `delete` (String)
- `update` (String)


<a id="nestedblock--workspace_role"></a>
### Nested Schema for `workspace_role`

Required:

- `project_id` (String) Project id to be associated with the user.
- `workspace` (Block Set, Min: 1) List of workspace roles to be associated with the user. (see [below for nested schema](#nestedblock--workspace_role--workspace))

<a id="nestedblock--workspace_role--workspace"></a>
### Nested Schema for `workspace_role.workspace`

Required:

- `id` (String) Workspace id to be associated with the user.
- `role_ids` (Set of String) List of workspace role ids to be associated with the user.
10 changes: 5 additions & 5 deletions examples/resources/spectrocloud_user/data_source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ data "spectrocloud_project" "ranjith" {
name = "ranjith"
}

data "spectrocloud_role" "app_roles"{
data "spectrocloud_role" "app_roles" {
for_each = toset(var.app_role_var)
name = each.key
}

data "spectrocloud_role" "tenant_roles"{
data "spectrocloud_role" "tenant_roles" {
for_each = toset(var.tenant_role_var)
name = each.key
}
Expand All @@ -25,7 +25,7 @@ data "spectrocloud_workspace" "workspace2" {
name = "test-ws-2"
}

data "spectrocloud_role" "workspace_roles"{
data "spectrocloud_role" "workspace_roles" {
for_each = toset(var.workspace_role_var)
name = each.key
}
Expand All @@ -34,12 +34,12 @@ data "spectrocloud_filter" "filter" {
name = "test-tf"
}

data "spectrocloud_role" "resource_roles"{
data "spectrocloud_role" "resource_roles" {
for_each = toset(var.resource_role_var)
name = each.key
}

data "spectrocloud_role" "resource_roles_editor"{
data "spectrocloud_role" "resource_roles_editor" {
for_each = toset(var.resource_role_editor_var)
name = each.key
}
Expand Down
36 changes: 18 additions & 18 deletions examples/resources/spectrocloud_user/resource.tf
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
resource "spectrocloud_user" "user-test"{
resource "spectrocloud_user" "user-test" {
first_name = "tf"
last_name = "test"
email = "[email protected]"
team_ids = [data.spectrocloud_team.team2.id]
last_name = "test"
email = "[email protected]"
team_ids = [data.spectrocloud_team.team2.id]
project_role {
project_id = data.spectrocloud_project.default.id
role_ids = [for r in data.spectrocloud_role.app_roles : r.id]
role_ids = [for r in data.spectrocloud_role.app_roles : r.id]
}
project_role {
project_id = data.spectrocloud_project.ranjith.id
role_ids = [for r in data.spectrocloud_role.app_roles : r.id]
role_ids = [for r in data.spectrocloud_role.app_roles : r.id]
}

tenant_role = [for t in data.spectrocloud_role.tenant_roles : t.id]

workspace_role {
project_id = data.spectrocloud_project.default.id
workspace {
id = data.spectrocloud_workspace.workspace.id
id = data.spectrocloud_workspace.workspace.id
role_ids = [for w in data.spectrocloud_role.workspace_roles : w.id]
}
workspace {
id = data.spectrocloud_workspace.workspace2.id
id = data.spectrocloud_workspace.workspace2.id
role_ids = ["66fbea622947f81fc26983e6"]
}
}

resource_role {
project_ids = [data.spectrocloud_project.default.id, data.spectrocloud_project.ranjith.id]
filter_ids = [data.spectrocloud_filter.filter.id]
role_ids = [for r in data.spectrocloud_role.resource_roles : r.id]
filter_ids = [data.spectrocloud_filter.filter.id]
role_ids = [for r in data.spectrocloud_role.resource_roles : r.id]
}

resource_role {
project_ids = [data.spectrocloud_project.ranjith.id]
filter_ids = [data.spectrocloud_filter.filter.id]
role_ids = [for re in data.spectrocloud_role.resource_roles_editor : re.id]
filter_ids = [data.spectrocloud_filter.filter.id]
role_ids = [for re in data.spectrocloud_role.resource_roles_editor : re.id]
}

}

# import existing user example
#import {
# to = spectrocloud_user.test_user
# id = "66fcb5fe19eb6dc880776d59"
#}
#import {
# to = spectrocloud_user.test_user
# id = "66fcb5fe19eb6dc880776d59"
#}

# To generate TF configuration.
#terraform plan -generate-config-out=test_user.tf
#terraform plan -generate-config-out=test_user.tf

# To import State file
#terraform import spectrocloud_user.test_user 672c5ae21adfa1c28c9e37c9
#terraform import spectrocloud_user.test_user 672c5ae21adfa1c28c9e37c9
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,6 @@ github.com/spectrocloud/gomi v1.14.1-0.20240214074114-c19394812368 h1:eY0BOyEbGu
github.com/spectrocloud/gomi v1.14.1-0.20240214074114-c19394812368/go.mod h1:LlZ9We4kDaELYi7Is0SVmnySuDhwphJLS6ZT4wXxFIk=
github.com/spectrocloud/hapi v1.14.1-0.20240214071352-81f589b1d86d h1:OMRbHxMJ1a+G1BYzvUYuMM0wLkYJPdnEOFx16faQ/UY=
github.com/spectrocloud/hapi v1.14.1-0.20240214071352-81f589b1d86d/go.mod h1:MktpRPnSXDTHsQrFSD+daJFQ1zMLSR+1gWOL31jVvWE=
github.com/spectrocloud/palette-sdk-go v0.0.0-20241106055848-76d563f78474 h1:NRbW7hfLXSarRadga47u/bKl83gY8dYZ3MNv30xxetM=
github.com/spectrocloud/palette-sdk-go v0.0.0-20241106055848-76d563f78474/go.mod h1:dSlNvDS0qwUWTbrYI6P8x981mcbbRHFrBg67v5zl81U=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
Expand Down
17 changes: 9 additions & 8 deletions spectrocloud/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, m interface
if err != nil {
return diag.FromErr(err)
}
} else {

}
}
if d.HasChanges("tenant_role") {
Expand Down Expand Up @@ -424,13 +422,16 @@ func deleteWorkspaceResourceRoles(c *client.V1Client, oldWs interface{}, userUID

func deleteProjectResourceRoles(c *client.V1Client, oldPs interface{}, userUID string) error {
oldProjectRoles := oldPs.(*schema.Set).List()

for _, p := range oldProjectRoles {
pr := make([]*models.V1ProjectRolesPatchProjectsItems0, 0)
pr = append(pr, &models.V1ProjectRolesPatchProjectsItems0{
ProjectUID: p.(map[string]interface{})["project_id"].(string),
Roles: []string{},
})
deletePR := &models.V1ProjectRolesPatch{}
deletePR := &models.V1ProjectRolesPatch{
Projects: []*models.V1ProjectRolesPatchProjectsItems0{
{
ProjectUID: p.(map[string]interface{})["project_id"].(string),
Roles: []string{},
},
},
}
_ = c.AssociateUserProjectRole(userUID, deletePR)
}
return nil
Expand Down
Loading

0 comments on commit 4a1ca4c

Please sign in to comment.