Health insurers consider pregnancy as a pre-existing condition. Therefore, if you buy maternity insurance when pregnant, you cannot benefit from the cover. As most maternity health insurance policies come with a waiting period.
Hence, you must opt for maternity insurance cover well in advance.