Skip to content

Commit 456b4a5

Browse files
committed
feat(CodeArts/Pipeline): support permission management
1 parent 0021054 commit 456b4a5

12 files changed

+1038
-34
lines changed

docs/data-sources/codearts_pipeline_micro_services.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ subcategory: "CodeArts Pipeline"
33
layout: "huaweicloud"
44
page_title: "HuaweiCloud: huaweicloud_codearts_pipeline_micro_services"
55
description: |-
6-
Use this data source to get a list of CodeArts pipeline groups.
6+
Use this data source to get a list of CodeArts pipeline micro services.
77
---
88

99
# huaweicloud_codearts_pipeline_micro_services
1010

11-
Use this data source to get a list of CodeArts pipeline groups.
11+
Use this data source to get a list of CodeArts pipeline micro services.
1212

1313
## Example Usage
1414

docs/data-sources/codearts_pipeline_parameter_groups.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ subcategory: "CodeArts Pipeline"
33
layout: "huaweicloud"
44
page_title: "HuaweiCloud: huaweicloud_codearts_pipeline_parameter_groups"
55
description: |-
6-
Use this data source to get a list of CodeArts pipeline groups.
6+
Use this data source to get a list of CodeArts pipeline parameter groups.
77
---
88

99
# huaweicloud_codearts_pipeline_parameter_groups
1010

11-
Use this data source to get a list of CodeArts pipeline groups.
11+
Use this data source to get a list of CodeArts pipeline parameter groups.
1212

1313
## Example Usage
1414

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
subcategory: "CodeArts Pipeline"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_codearts_pipeline_user_permissions"
5+
description: |-
6+
Use this data source to get a list of CodeArts pipeline user permissions.
7+
---
8+
9+
# huaweicloud_codearts_pipeline_user_permissions
10+
11+
Use this data source to get a list of CodeArts pipeline user permissions.
12+
13+
## Example Usage
14+
15+
```hcl
16+
variable "codearts_project_id" {}
17+
variable "pipeline_id" {}
18+
19+
data "huaweicloud_codearts_pipeline_user_permissions" "test" {
20+
project_id = var.codearts_project_id
21+
pipeline_id = var.pipeline_id
22+
}
23+
```
24+
25+
## Argument Reference
26+
27+
The following arguments are supported:
28+
29+
* `region` - (Optional, String) Specifies the region in which to query the data source.
30+
If omitted, the provider-level region will be used.
31+
32+
* `project_id` - (Required, String) Specifies the CodeArts project ID.
33+
34+
* `pipeline_id` - (Required, String) Specifies the pipeline ID.
35+
36+
* `user_name` - (Optional, String) Specifies the user name.
37+
38+
## Attribute Reference
39+
40+
In addition to all arguments above, the following attributes are exported:
41+
42+
* `id` - The data source ID.
43+
44+
* `users` - Indicates the template list.
45+
The [users](#attrblock--users) structure is documented below.
46+
47+
<a name="attrblock--users"></a>
48+
The `users` block supports:
49+
50+
* `user_id` - Indicates the user ID.
51+
52+
* `user_name` - Indicates the user name.
53+
54+
* `operation_authorize` - Indicates whether the user has the permission to authorize.
55+
56+
* `operation_delete` - Indicates whether the user has the permission to delete.
57+
58+
* `operation_execute` - Indicates whether the user has the permission to execute.
59+
60+
* `operation_query` - Indicates whether the user has the permission to query.
61+
62+
* `operation_update` - Indicates whether the user has the permission to update.
63+
64+
* `role_id` - Indicates the role ID.
65+
66+
* `role_name` - Indicates the role name.

docs/resources/codearts_pipeline.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ The following arguments are supported:
171171

172172
* `tags` - (Optional, List) Specifies the tag IDs.
173173

174+
* `resource_level_permission_switch` - (Optional, Bool) Specifies whether to use resource level permission.
175+
Default to **false**, which means project level permission will be used.
176+
174177
<a name="block--sources"></a>
175178
The `sources` block supports:
176179

@@ -325,6 +328,11 @@ In addition to all arguments above, the following attributes are exported:
325328
* `triggers` - Indicates the pipeline trigger settings.
326329
The [triggers](#attrblock--triggers) structure is documented below.
327330

331+
* `role_permissions` - Indicates the role permissions.
332+
The [role_permissions](#attrblock--role_permissions) structure is documented below.
333+
334+
* `is_allow_edit` - Indicates whether the user is allowed to edit the permission.
335+
328336
<a name="attrblock--schedules"></a>
329337
The `schedules` block supports:
330338

@@ -335,6 +343,23 @@ The `triggers` block supports:
335343

336344
* `hook_id` - Indicates the callback ID.
337345

346+
<a name="attrblock--role_permissions"></a>
347+
The `role_permissions` block supports:
348+
349+
* `operation_authorize` - Indicates whether the role has the permission to authorize.
350+
351+
* `operation_delete` - Indicates whether the role has the permission to delete.
352+
353+
* `operation_execute` - Indicates whether the role has the permission to execute.
354+
355+
* `operation_query` - Indicates whether the role has the permission to query.
356+
357+
* `operation_update` - Indicates whether the role has the permission to update.
358+
359+
* `role_id` - Indicates the role ID.
360+
361+
* `role_name` - Indicates the role name.
362+
338363
## Import
339364

340365
The pipeline can be imported using `project_id` and `id` separated by a slash, e.g.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
subcategory: "CodeArts Pipeline"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_codearts_pipeline_permission"
5+
description: |-
6+
Manages a CodeArts pipeline permissionresource within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_codearts_pipeline_permission
10+
11+
Manages a CodeArts pipeline permissionresource within HuaweiCloud.
12+
13+
## Example Usage
14+
15+
### Modify user permission
16+
17+
```hcl
18+
variable "codearts_project_id" {}
19+
variable "pipeline_id" {}
20+
variable "user_id" {}
21+
22+
resource "huaweicloud_codearts_pipeline_permission" "user" {
23+
project_id = var.codearts_project_id
24+
pipeline_id = var.pipeline_id
25+
user_id = var.user_id
26+
operation_delete = true
27+
operation_execute = true
28+
operation_query = true
29+
operation_update = true
30+
}
31+
```
32+
33+
### Modify role permission
34+
35+
```hcl
36+
variable "codearts_project_id" {}
37+
variable "pipeline_id" {}
38+
variable "role_id" {}
39+
40+
resource "huaweicloud_codearts_pipeline_permission" "role" {
41+
project_id = var.codearts_project_id
42+
pipeline_id = var.pipeline_id
43+
role_id = var.role_id
44+
operation_delete = true
45+
operation_execute = true
46+
operation_query = true
47+
operation_update = true
48+
}
49+
```
50+
51+
## Argument Reference
52+
53+
The following arguments are supported:
54+
55+
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
56+
If omitted, the provider-level region will be used.
57+
Changing this creates a new resource.
58+
59+
* `project_id` - (Required, String) Specifies the CodeArts project ID.
60+
61+
* `pipeline_id` - (Required, String) Specifies the pipeline ID.
62+
63+
* `role_id` - (Optional, Int) Specifies the role ID.
64+
65+
* `user_id` - (Optional, String) Specifies the user ID.
66+
67+
-> Only one of `role_id` and `user_id` can be specified.
68+
69+
* `operation_authorize` - (Optional, Bool) Specifies whether the role has the permission to authorize.
70+
71+
* `operation_delete` - (Optional, Bool) Specifies whether the role has the permission to delete.
72+
73+
* `operation_execute` - (Optional, Bool) Specifies whether the role has the permission to execute.
74+
75+
* `operation_query` - (Optional, Bool) Specifies whether the role has the permission to query.
76+
77+
* `operation_update` - (Optional, Bool) Specifies whether the role has the permission to update.
78+
79+
## Attribute Reference
80+
81+
In addition to all arguments above, the following attributes are exported:
82+
83+
* `id` - The resource ID.
84+
85+
* `role_name` - Indicates the role name.
86+
87+
* `user_name` - Indicates the user name.
88+
89+
## Import
90+
91+
The pipeline permission can be imported using `project_id`, `pipeline_id`, `role_id` and `user_id`, e.g.
92+
93+
### Import role permission
94+
95+
```bash
96+
$ terraform import huaweicloud_codearts_pipeline_permission.test <project_id>/<pipeline_id>/role/<role_id>
97+
```
98+
99+
### Import user permission
100+
101+
```bash
102+
$ terraform import huaweicloud_codearts_pipeline_permission.test <project_id>/<pipeline_id>/user/<user_id>
103+
```

huaweicloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ func Provider() *schema.Provider {
723723
"huaweicloud_codearts_pipeline_run_variables": codeartspipeline.DataSourceCodeArtsPipelineRunVariables(),
724724
"huaweicloud_codearts_pipeline_service_endpoints": codeartspipeline.DataSourceCodeArtsPipelineServiceEndpoints(),
725725
"huaweicloud_codearts_pipeline_tags": codeartspipeline.DataSourceCodeArtsPipelineTags(),
726+
"huaweicloud_codearts_pipeline_user_permissions": codeartspipeline.DataSourceCodeArtsPipelineUserPermissions(),
726727

727728
"huaweicloud_codearts_build_tasks": codeartsbuild.DataSourceCodeArtsBuildTasks(),
728729
"huaweicloud_codearts_build_task_records": codeartsbuild.DataSourceCodeArtsBuildTaskRecords(),
@@ -2839,6 +2840,7 @@ func Provider() *schema.Provider {
28392840
"huaweicloud_codearts_pipeline_group": codeartspipeline.ResourceCodeArtsPipelineGroup(),
28402841
"huaweicloud_codearts_pipeline_group_swap": codeartspipeline.ResourceCodeArtsPipelineGroupSwap(),
28412842
"huaweicloud_codearts_pipeline": codeartspipeline.ResourceCodeArtsPipeline(),
2843+
"huaweicloud_codearts_pipeline_permission": codeartspipeline.ResourceCodeArtsPipelinePermission(),
28422844
"huaweicloud_codearts_pipeline_tag": codeartspipeline.ResourceCodeArtsPipelineTag(),
28432845
"huaweicloud_codearts_pipeline_action": codeartspipeline.ResourceCodeArtsPipelineAction(),
28442846
"huaweicloud_codearts_pipeline_by_template": codeartspipeline.ResourceCodeArtsPipelineByTemplate(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package codeartspipeline
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
9+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
10+
)
11+
12+
func TestAccDataSourcePipelineUserPermissions_basic(t *testing.T) {
13+
dataSource := "data.huaweicloud_codearts_pipeline_user_permissions.test"
14+
name := acceptance.RandomAccResourceName()
15+
dc := acceptance.InitDataSourceCheck(dataSource)
16+
17+
resource.ParallelTest(t, resource.TestCase{
18+
PreCheck: func() { acceptance.TestAccPreCheck(t) },
19+
ProviderFactories: acceptance.TestAccProviderFactories,
20+
CheckDestroy: nil,
21+
Steps: []resource.TestStep{
22+
{
23+
Config: testDataSourcePipelineUserPermissions_basic(name),
24+
Check: resource.ComposeTestCheckFunc(
25+
dc.CheckResourceExists(),
26+
resource.TestCheckResourceAttrSet(dataSource, "users.#"),
27+
resource.TestCheckResourceAttrSet(dataSource, "users.0.user_id"),
28+
resource.TestCheckResourceAttrSet(dataSource, "users.0.user_name"),
29+
resource.TestCheckResourceAttrSet(dataSource, "users.0.operation_query"),
30+
resource.TestCheckResourceAttrSet(dataSource, "users.0.operation_execute"),
31+
resource.TestCheckResourceAttrSet(dataSource, "users.0.operation_update"),
32+
resource.TestCheckResourceAttrSet(dataSource, "users.0.operation_delete"),
33+
resource.TestCheckResourceAttrSet(dataSource, "users.0.operation_authorize"),
34+
resource.TestCheckResourceAttrSet(dataSource, "users.0.role_id"),
35+
resource.TestCheckResourceAttrSet(dataSource, "users.0.role_name"),
36+
37+
resource.TestCheckOutput("is_user_name_filter_useful", "true"),
38+
),
39+
},
40+
},
41+
})
42+
}
43+
44+
func testDataSourcePipelineUserPermissions_basic(name string) string {
45+
return fmt.Sprintf(`
46+
%[1]s
47+
48+
data "huaweicloud_codearts_pipeline_user_permissions" "test" {
49+
project_id = huaweicloud_codearts_project.test.id
50+
pipeline_id = huaweicloud_codearts_pipeline.test.id
51+
}
52+
53+
// filter by user name
54+
data "huaweicloud_codearts_pipeline_user_permissions" "filter_by_user_name" {
55+
project_id = huaweicloud_codearts_project.test.id
56+
pipeline_id = huaweicloud_codearts_pipeline.test.id
57+
user_name = data.huaweicloud_codearts_pipeline_user_permissions.test.users[0].user_name
58+
}
59+
60+
locals {
61+
filter_result_by_user_name = [for v in data.huaweicloud_codearts_pipeline_user_permissions.filter_by_user_name.users[*].user_name :
62+
v == data.huaweicloud_codearts_pipeline_user_permissions.test.users[0].user_name]
63+
}
64+
65+
output "is_user_name_filter_useful" {
66+
value = length(local.filter_result_by_user_name) > 0 && alltrue(local.filter_result_by_user_name)
67+
}
68+
`, testPipeline_basic(name))
69+
}

0 commit comments

Comments
 (0)