The thing about flash is that, even with the camera on Manual, the flash exposure is still automatic (unless you turn the flash itself to manual). The two exposure systems are independent.
So you can set the shutter speed to anything up to the X-sync speed (normally about 1/250) and then choose a suitable aperture and ISO. With the flash set to ETTL, exposure is set by a brief pre-flash (which you hardly see) and is automatic.
The shutter speed does not affect the flash exposure at all. The flash duration is extremely short. It does affect the amount of ambient light that contributes to the exposure.
The aperture affects both the flash and ambient light contributions. If the aperture is too small, the flash won't have enough power even if it (automatically) gives everything it has.
You can apply Flash Exposure Compensation (FEC) using the camera buttons or the controls on the flashgun itself. If you want to do everything manually, the flash can be set to various outputs from full down to 1/16th power.
There is also high speed sync flash (aka focal plane flash) which allows you to use shutter speeds faster than the standard X-sync, but flash output is reduced considerably. (The term 'high speed' is a bit misleading because it actually increases the flash duration by pulsing it, so the whole image gets exposed as the shutter curtains move across.)
There's also second curtain flash where the flash fires at the end of the exposure rather than at the beginning which is the default mode. That's useful if you want to photograph, say, a moving car so the light trails are behind the vehicle. The flash needs to fire at the end. If it fires at the beginning, the light trails are in front of the car!
Phew.... I've bored you enough for now.
