Skip to content

Commit 10aaa5a

Browse files
committed
chore: update
1 parent 9651ce0 commit 10aaa5a

File tree

6 files changed

+39
-91
lines changed

6 files changed

+39
-91
lines changed

docs/data-sources/setting.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,9 @@ Read-Only:
214214
Read-Only:
215215

216216
- `description` (String)
217-
- `steps` (List of Object) (see [below for nested schema](#nestedobjatt--approval_flow--rules--flow--steps))
217+
- `roles` (List of String)
218218
- `title` (String)
219219

220-
<a id="nestedobjatt--approval_flow--rules--flow--steps"></a>
221-
### Nested Schema for `approval_flow.rules.flow.title`
222-
223-
Read-Only:
224-
225-
- `role` (String)
226-
227-
228220

229221

230222

docs/resources/setting.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,13 @@ Optional:
5555

5656
Required:
5757

58-
- `steps` (Block List, Min: 1) Approval flow following the step order. (see [below for nested schema](#nestedblock--approval_flow--rules--flow--steps))
58+
- `roles` (List of String) The role require to review in this step
5959
- `title` (String)
6060

6161
Optional:
6262

6363
- `description` (String)
6464

65-
<a id="nestedblock--approval_flow--rules--flow--steps"></a>
66-
### Nested Schema for `approval_flow.rules.flow.steps`
67-
68-
Required:
69-
70-
- `role` (String) The role require to review in this step
71-
72-
7365

7466
<a id="nestedblock--approval_flow--rules--conditions"></a>
7567
### Nested Schema for `approval_flow.rules.conditions`

examples/setup/approval_flow.tf

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@ resource "bytebase_setting" "approval_flow" {
77
description = "Need DBA and workspace admin approval"
88

99
# Approval flow following the step order.
10-
steps {
11-
role = "roles/projectOwner"
12-
}
13-
14-
steps {
15-
role = "roles/workspaceDBA"
16-
}
17-
18-
steps {
19-
role = "roles/workspaceAdmin"
20-
}
10+
roles = [
11+
"roles/projectOwner",
12+
"roles/workspaceDBA",
13+
"roles/workspaceAdmin"
14+
]
2115
}
2216

2317
# Match any condition will trigger this approval flow.

provider/data_source_setting.go

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -503,31 +503,25 @@ func getWorkspaceApprovalSetting(computed bool) *schema.Schema {
503503
Elem: &schema.Resource{
504504
Schema: map[string]*schema.Schema{
505505
"title": {
506-
Type: schema.TypeString,
507-
Computed: computed,
508-
Required: !computed,
506+
Type: schema.TypeString,
507+
Required: true,
508+
ValidateFunc: validation.StringIsNotEmpty,
509509
},
510510
"description": {
511511
Type: schema.TypeString,
512512
Computed: computed,
513513
Optional: true,
514514
},
515-
"steps": {
515+
"roles": {
516516
Type: schema.TypeList,
517-
Computed: computed,
518-
Required: !computed,
519-
Description: "Approval flow following the step order.",
520-
Elem: &schema.Resource{
521-
Schema: map[string]*schema.Schema{
522-
"role": {
523-
Type: schema.TypeString,
524-
Required: true,
525-
ValidateDiagFunc: internal.ResourceNameValidation(
526-
fmt.Sprintf("^%s", internal.RoleNamePrefix),
527-
),
528-
Description: "The role require to review in this step",
529-
},
530-
},
517+
Required: true,
518+
Description: "The role require to review in this step",
519+
Elem: &schema.Schema{
520+
Type: schema.TypeString,
521+
Description: `Role full name in roles/{id} format.`,
522+
ValidateDiagFunc: internal.ResourceNameValidation(
523+
fmt.Sprintf("^%s", internal.RoleNamePrefix),
524+
),
531525
},
532526
},
533527
},
@@ -717,14 +711,9 @@ func parseApprovalExpression(callExpr *v1alpha1.Expr_Call) ([]map[string]interfa
717711
func flattenWorkspaceApprovalSetting(ctx context.Context, client api.Client, setting *v1pb.WorkspaceApprovalSetting) ([]interface{}, error) {
718712
ruleList := []interface{}{}
719713
for _, rule := range setting.Rules {
720-
stepList := []interface{}{}
721-
for _, step := range rule.Template.Flow.Steps {
722-
rawStep := map[string]interface{}{}
723-
for _, node := range step.Nodes {
724-
rawStep["role"] = node.Role
725-
break
726-
}
727-
stepList = append(stepList, rawStep)
714+
roleList := []interface{}{}
715+
for _, role := range rule.Template.Flow.Roles {
716+
roleList = append(roleList, role)
728717
}
729718

730719
conditionList := []map[string]interface{}{}
@@ -746,7 +735,7 @@ func flattenWorkspaceApprovalSetting(ctx context.Context, client api.Client, set
746735
map[string]interface{}{
747736
"title": rule.Template.Title,
748737
"description": rule.Template.Description,
749-
"steps": stepList,
738+
"roles": roleList,
750739
},
751740
},
752741
}

provider/resource_setting.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -380,27 +380,16 @@ func convertToV1ApprovalSetting(d *schema.ResourceData) (*v1pb.WorkspaceApproval
380380
},
381381
}
382382

383-
stepList, ok := rawFlow["steps"].([]interface{})
383+
roleList, ok := rawFlow["roles"].([]interface{})
384384
if !ok {
385-
return nil, errors.Errorf("invalid steps")
385+
return nil, errors.Errorf("invalid roles")
386386
}
387-
388-
for _, step := range stepList {
389-
approvalStep := &v1pb.ApprovalStep{
390-
Type: v1pb.ApprovalStep_ANY,
391-
}
392-
393-
rawStep := step.(map[string]interface{})
394-
role := rawStep["role"].(string)
395-
if !strings.HasPrefix(role, "roles/") {
396-
return nil, errors.Errorf("invalid role name: %v, role name should in roles/{role} format", role)
387+
for _, raw := range roleList {
388+
role := raw.(string)
389+
if !strings.HasPrefix(role, internal.RoleNamePrefix) {
390+
return nil, errors.Errorf("invalid role format, role must in roles/{id} format")
397391
}
398-
approvalStep.Nodes = append(approvalStep.Nodes, &v1pb.ApprovalNode{
399-
Type: v1pb.ApprovalNode_ANY_IN_GROUP,
400-
Role: role,
401-
})
402-
403-
approvalRule.Template.Flow.Steps = append(approvalRule.Template.Flow.Steps, approvalStep)
392+
approvalRule.Template.Flow.Roles = append(approvalRule.Template.Flow.Roles, role)
404393
}
405394

406395
workspaceApprovalSetting.Rules = append(workspaceApprovalSetting.Rules, approvalRule)

provider/resource_setting_test.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestAccSetting_WorkspaceApproval(t *testing.T) {
3131
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.#", "1"),
3232
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.0.conditions.#", "1"),
3333
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.0.flow.#", "1"),
34-
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.0.flow.0.steps.#", "2"),
34+
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.0.flow.0.roles.#", "2"),
3535
),
3636
},
3737
// Update workspace approval setting
@@ -44,7 +44,7 @@ func TestAccSetting_WorkspaceApproval(t *testing.T) {
4444
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.#", "1"),
4545
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.0.conditions.#", "2"),
4646
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.0.flow.#", "1"),
47-
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.0.flow.0.steps.#", "1"),
47+
resource.TestCheckResourceAttr(resourceName, "approval_flow.0.rules.0.flow.0.roles.#", "1"),
4848
),
4949
},
5050
},
@@ -228,9 +228,7 @@ resource "bytebase_setting" "%s" {
228228
flow {
229229
title = "Test"
230230
description = "Test"
231-
steps {
232-
role = "roles/test"
233-
}
231+
roles = ["roles/test"]
234232
}
235233
}
236234
}
@@ -265,9 +263,7 @@ resource "bytebase_setting" "%s" {
265263
flow {
266264
title = "Test"
267265
description = "Test"
268-
steps {
269-
role = "invalid-role"
270-
}
266+
roles = ["invalid-role"]
271267
}
272268
}
273269
}
@@ -339,12 +335,10 @@ resource "bytebase_setting" "%s" {
339335
flow {
340336
title = "DDL Approval Flow"
341337
description = "Approval flow for DDL operations"
342-
steps {
343-
role = bytebase_role.approval_role_%s.name
344-
}
345-
steps {
346-
role = bytebase_role.approval_role_%s.name
347-
}
338+
roles = [
339+
bytebase_role.approval_role_%s.name,
340+
bytebase_role.approval_role_%s.name
341+
]
348342
}
349343
}
350344
}
@@ -377,9 +371,7 @@ resource "bytebase_setting" "%s" {
377371
flow {
378372
title = "Updated Approval Flow"
379373
description = "Updated approval flow"
380-
steps {
381-
role = bytebase_role.approval_role_%s.name
382-
}
374+
roles = [bytebase_role.approval_role_%s.name]
383375
}
384376
}
385377
}

0 commit comments

Comments
 (0)