Skip to content

Commit 8d3833b

Browse files
authored
fix(cam): [120275586] tencentcloud_cam_role update the verification rules for field document (#2917)
* add * add * add
1 parent 5486b08 commit 8d3833b

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

.changelog/2917.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_cam_role: update the verification rules for field `document`
3+
```

tencentcloud/services/cam/resource_tc_cam_role.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,12 @@ func resourceTencentCloudCamRoleCreate(d *schema.ResourceData, meta interface{})
9898

9999
name := d.Get("name").(string)
100100
document := d.Get("document").(string)
101-
102-
camService := CamService{
103-
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
101+
camService := CamService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
102+
documentErr := camService.PolicyDocumentForceCheck(document)
103+
if documentErr != nil {
104+
return documentErr
104105
}
105-
//documentErr := camService.PolicyDocumentForceCheck(document)
106-
//if documentErr != nil {
107-
// return documentErr
108-
//}
106+
109107
request := cam.NewCreateRoleRequest()
110108
request.RoleName = &name
111109
request.PolicyDocument = &document

tencentcloud/services/cam/service_tencentcloud_cam.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,8 @@ func (me *CamService) PolicyDocumentForceCheck(document string) error {
11911191
type Statement struct {
11921192
Resource interface{} `json:"resource"`
11931193
//to avoid json unmarshal eats up with '/'
1194-
Action []json.RawMessage `json:"action"`
1195-
Principal Principal `json:"principal"`
1194+
Action interface{} `json:"action"`
1195+
Principal Principal `json:"principal"`
11961196
}
11971197
type Document struct {
11981198
Version string `json:"version"`
@@ -1212,15 +1212,9 @@ func (me *CamService) PolicyDocumentForceCheck(document string) error {
12121212
}
12131213

12141214
if state.Action != nil {
1215-
if reflect.TypeOf(state.Action) == reflect.TypeOf("string") {
1216-
return fmt.Errorf("The format of `action` in policy document is invalid, its type must be array.")
1217-
}
1218-
1219-
}
1220-
//multi value case in elemant `principal.qcs`:input :root/[uin of the user], output:[uin of the user]
1221-
for _, qcs := range state.Principal.Qcs {
1222-
if strings.Contains(qcs, "root") {
1223-
return fmt.Errorf("`root` format is not supported, please replace it with uin.")
1215+
actionType := reflect.TypeOf(state.Action).Kind()
1216+
if actionType != reflect.String && actionType != reflect.Slice {
1217+
return fmt.Errorf("The format of `action` in policy document is invalid, its type must be array or string.")
12241218
}
12251219
}
12261220
}

0 commit comments

Comments
 (0)