Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2917.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cam_role: update the verification rules for field `document`
```
12 changes: 5 additions & 7 deletions tencentcloud/services/cam/resource_tc_cam_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,12 @@ func resourceTencentCloudCamRoleCreate(d *schema.ResourceData, meta interface{})

name := d.Get("name").(string)
document := d.Get("document").(string)

camService := CamService{
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
camService := CamService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
documentErr := camService.PolicyDocumentForceCheck(document)
if documentErr != nil {
return documentErr
}
//documentErr := camService.PolicyDocumentForceCheck(document)
//if documentErr != nil {
// return documentErr
//}

request := cam.NewCreateRoleRequest()
request.RoleName = &name
request.PolicyDocument = &document
Expand Down
16 changes: 5 additions & 11 deletions tencentcloud/services/cam/service_tencentcloud_cam.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,8 +1191,8 @@ func (me *CamService) PolicyDocumentForceCheck(document string) error {
type Statement struct {
Resource interface{} `json:"resource"`
//to avoid json unmarshal eats up with '/'
Action []json.RawMessage `json:"action"`
Principal Principal `json:"principal"`
Action interface{} `json:"action"`
Principal Principal `json:"principal"`
}
type Document struct {
Version string `json:"version"`
Expand All @@ -1212,15 +1212,9 @@ func (me *CamService) PolicyDocumentForceCheck(document string) error {
}

if state.Action != nil {
if reflect.TypeOf(state.Action) == reflect.TypeOf("string") {
return fmt.Errorf("The format of `action` in policy document is invalid, its type must be array.")
}

}
//multi value case in elemant `principal.qcs`:input :root/[uin of the user], output:[uin of the user]
for _, qcs := range state.Principal.Qcs {
if strings.Contains(qcs, "root") {
return fmt.Errorf("`root` format is not supported, please replace it with uin.")
actionType := reflect.TypeOf(state.Action).Kind()
if actionType != reflect.String && actionType != reflect.Slice {
return fmt.Errorf("The format of `action` in policy document is invalid, its type must be array or string.")
}
}
}
Expand Down
Loading