Cloud IAP makes it easier and secure for connecting VM instances on GCP.
This can be used in VSCode too!
Steps
Setup VM without external IP (connect through Cloud IAP)
Show SSH command
Modify command: add quotes, modify ssh bin path, and etc.
Set new remote host in VSCode via ‘Remote-SSH: Add New SSH Host’
Edit Host in generated ssh config
Caveats (VSCode on Windows11+WSL2)
When using Remote SSH feature on typical modern WSL2 env, where you use VSCode on Windows with WSL2 remote containers, the issues are:
VSCode on Windows env. needs SSH client running on Windows, not WSL2’s one.
Google Cloud SDK on Windows uses bundled putty as SSH client implementation, but current (as of v0.78.0) VSCode Remote SSH extension does not support putty.