def METHOD_NAME(api, security_group_id, security_group_rule):
    ret = {'changed': False}
    response = api.get('security_groups/%s/rules' % security_group_id)
    if not response.ok:
        api.module.fail_json(
            msg='Error getting security group rules "%s": "%s" (%s)' %
            (response.info['msg'], response.json['message'], response.json))
    existing_rule = get_sgr_from_api(
        response.json['rules'], security_group_rule)
    if not existing_rule:
        ret['changed'] = True
        if api.module.check_mode:
            return ret
        # Create Security Group Rule
        response = api.post('/security_groups/%s/rules' % security_group_id,
                            data=payload_from_object(security_group_rule))
        if not response.ok:
            api.module.fail_json(
                msg='Error during security group rule creation: "%s": "%s" (%s)' %
                (response.info['msg'], response.json['message'], response.json))
        ret['scaleway_security_group_rule'] = response.json['rule']
    else:
        ret['scaleway_security_group_rule'] = existing_rule
    return ret