Hello Georgi,
As the issue persists after you applied the previous workaround suggestion, this indicates the DNS resolution of metadata.google.internal still fails, as you are not using any proxy in your environment. You can try the following steps:
Try to create a new VM on the same subnet where the source VM resides and try to establish an SSH connection to the target VM.
Also try to create a new VM on the same subnet where the targeted VM resides and try to connect from the source VM, and also try to connect from the new VM residing on the source VM subnet.
These steps will narrow down the issue if the issue might be related to the /etc/resolv.conf not being restored successfully.
Also, As this is a technical question I would recommend that you open a case on Stack Overflow[1] or Server Fault[2] as they are more appropriate for these kind of technical questions[3]
Also you can open a case with GCP support[4], as this might require more in depth investigation to help identify and resolve the issue.
[4]https://cloud.google.com/support/docs/manage-cases