-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLT-1454: Added User Management support in terraform (#538)
* PLT-1470 (#536) * PLT-1470: Added data source support for team. * initial draft * schema design completed * draft-2 user managements * completed initial drafts * PLT-1454: Added user management and import support. * PLT-1454: Added unit test for user management * added documentation * refreshed sdk * Update resource_user_import.go * updated sdk * reviewable fix
- Loading branch information
1 parent
5780ac9
commit 0fe74d1
Showing
16 changed files
with
1,518 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "spectrocloud_team Data Source - terraform-provider-spectrocloud" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# spectrocloud_team (Data Source) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "spectrocloud_team" "team1" { | ||
name = "team2" | ||
# (alternatively) | ||
# id = "5fd0ca727c411c71b55a359c" | ||
} | ||
output "team-id" { | ||
value = data.spectrocloud_team.team1.id | ||
} | ||
output "team-role-ids" { | ||
value = data.spectrocloud_team.team1.role_ids | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `id` (String) The unique ID of the team. If provided, `name` cannot be used. | ||
- `name` (String) The name of the team. If provided, `id` cannot be used. | ||
|
||
### Read-Only | ||
|
||
- `role_ids` (List of String) The roles id's assigned to the team. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
data "spectrocloud_team" "team1" { | ||
name = "team2" | ||
|
||
# (alternatively) | ||
# id = "5fd0ca727c411c71b55a359c" | ||
} | ||
|
||
output "team-id" { | ||
value = data.spectrocloud_team.team1.id | ||
} | ||
|
||
output "team-role-ids" { | ||
value = data.spectrocloud_team.team1.role_ids | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
terraform { | ||
required_providers { | ||
spectrocloud = { | ||
version = ">= 0.1" | ||
source = "spectrocloud/spectrocloud" | ||
} | ||
} | ||
} | ||
|
||
variable "sc_host" { | ||
description = "Spectro Cloud Endpoint" | ||
default = "api.spectrocloud.com" | ||
} | ||
|
||
variable "sc_api_key" { | ||
description = "Spectro Cloud API key" | ||
} | ||
|
||
variable "sc_project_name" { | ||
description = "Spectro Cloud Project (e.g: Default)" | ||
default = "Default" | ||
} | ||
|
||
provider "spectrocloud" { | ||
host = var.sc_host | ||
api_key = var.sc_api_key | ||
project_name = var.sc_project_name | ||
} |
4 changes: 4 additions & 0 deletions
4
examples/data-sources/spectrocloud_team/terraform.template.tfvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Spectro Cloud credentials | ||
sc_host = "{Enter Spectro Cloud API Host}" #e.g: api.spectrocloud.com (for SaaS) | ||
sc_api_key = "{Enter Spectro Cloud API Key}" | ||
sc_project_name = "{Enter Spectro Cloud Project Name}" #e.g: Default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
data "spectrocloud_project" "default" { | ||
name = "Default" | ||
} | ||
|
||
data "spectrocloud_project" "ranjith" { | ||
name = "ranjith" | ||
} | ||
|
||
data "spectrocloud_role" "app_roles" { | ||
for_each = toset(var.app_role_var) | ||
name = each.key | ||
} | ||
|
||
data "spectrocloud_role" "tenant_roles" { | ||
for_each = toset(var.tenant_role_var) | ||
name = each.key | ||
} | ||
|
||
data "spectrocloud_workspace" "workspace" { | ||
name = "test-ws-tf" | ||
} | ||
|
||
data "spectrocloud_workspace" "workspace2" { | ||
name = "test-ws-2" | ||
} | ||
|
||
data "spectrocloud_role" "workspace_roles" { | ||
for_each = toset(var.workspace_role_var) | ||
name = each.key | ||
} | ||
|
||
data "spectrocloud_filter" "filter" { | ||
name = "test-tf" | ||
} | ||
|
||
data "spectrocloud_role" "resource_roles" { | ||
for_each = toset(var.resource_role_var) | ||
name = each.key | ||
} | ||
|
||
data "spectrocloud_role" "resource_roles_editor" { | ||
for_each = toset(var.resource_role_editor_var) | ||
name = each.key | ||
} | ||
|
||
data "spectrocloud_team" "team2" { | ||
name = "team2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
terraform { | ||
required_providers { | ||
spectrocloud = { | ||
version = ">= 0.1" | ||
source = "spectrocloud/spectrocloud" | ||
} | ||
} | ||
} | ||
|
||
provider "spectrocloud" { | ||
host = var.sc_host | ||
api_key = var.sc_api_key | ||
project_name = var.sc_project_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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] | ||
} | ||
|
||
} | ||
|
||
# import existing user example | ||
#import { | ||
# to = spectrocloud_user.test_user | ||
# id = "66fcb5fe19eb6dc880776d59" | ||
#} | ||
|
||
# To generate TF configuration. | ||
#terraform plan -generate-config-out=test_user.tf | ||
|
||
# To import State file | ||
#terraform import spectrocloud_user.test_user 672c5ae21adfa1c28c9e37c9 |
4 changes: 4 additions & 0 deletions
4
examples/resources/spectrocloud_user/terraform.template.tfvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Spectro Cloud credentials | ||
sc_host = "{Enter Spectro Cloud API Host}" #e.g: api.spectrocloud.com (for SaaS) | ||
sc_api_key = "{Enter Spectro Cloud API Key}" | ||
sc_project_name = "{Enter Spectro Cloud Project Name}" #e.g: Default |
Oops, something went wrong.