A controller-integrated rotary electric machine comprising: a first housing that houses a controller or a rotary electric machine main unit driven according to a command from the controller; and a second housing that is coaxially aligned with the first housing and has a groove, wherein the first housing is joined to the second housing by folding a thin-walled portion of the first housing along an abutting face of the second housing and performing swaging, wherein the first housing includes the thin-walled portion at an edge on an outer periphery side, and wherein the abutting face having a linearly inclined cross-sectional shape is formed from the outer periphery side toward a radial direction in the groove, wherein the second housing houses one of the controller and the rotary electric machine main unit, the one being not housed in the first housing, wherein the controller-integrated rotary electric machine, further comprises: a first axial positioning portion provided on the first housing and having a face perpendicular to the axial direction; and a second axial positioning portion provided on the second housing on an edge side with respect to the groove and having a face perpendicular to the axial direction, wherein the first housing is joined to the second housing by causing the first axial positioning portion to abut against the second axial positioning portion and performing swaging. a first housing that houses a controller or a rotary electric machine main unit driven according to a command from the controller; and a second housing that is coaxially aligned with the first housing and has a groove, wherein the first housing is joined to the second housing by folding a thin-walled portion of the first housing along an abutting face of the second housing and performing swaging, wherein the first housing includes the thin-walled portion at an edge on an outer periphery side, and wherein the abutting face having a linearly inclined cross-sectional shape is formed from the outer periphery side toward a radial direction in the groove, wherein the second housing houses one of the controller and the rotary electric machine main unit, the one being not housed in the first housing, wherein the controller-integrated rotary electric machine, further comprises: a first axial positioning portion provided on the first housing and having a face perpendicular to the axial direction; and a second axial positioning portion provided on the second housing on an edge side with respect to the groove and having a face perpendicular to the axial direction, wherein the first housing is joined to the second housing by causing the first axial positioning portion to abut against the second axial positioning portion and performing swaging. a first axial positioning portion provided on the first housing and having a face perpendicular to the axial direction; and a second axial positioning portion provided on the second housing on an edge side with respect to the groove and having a face perpendicular to the axial direction, wherein the first housing is joined to the second housing by causing the first axial positioning portion to abut against the second axial positioning portion and performing swaging.