diff --git a/.changelog/2917.txt b/.changelog/2917.txt new file mode 100644 index 0000000000..0bbb3ab2a6 --- /dev/null +++ b/.changelog/2917.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_cam_role: update the verification rules for field `document` +``` \ No newline at end of file diff --git a/tencentcloud/services/cam/resource_tc_cam_role.go b/tencentcloud/services/cam/resource_tc_cam_role.go index 029b614150..7d09c059b0 100644 --- a/tencentcloud/services/cam/resource_tc_cam_role.go +++ b/tencentcloud/services/cam/resource_tc_cam_role.go @@ -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 diff --git a/tencentcloud/services/cam/service_tencentcloud_cam.go b/tencentcloud/services/cam/service_tencentcloud_cam.go index 474b9e5433..8c0c7a2fba 100644 --- a/tencentcloud/services/cam/service_tencentcloud_cam.go +++ b/tencentcloud/services/cam/service_tencentcloud_cam.go @@ -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"` @@ -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.") } } }