I am deploying a Cloudfunction with VPC network as follows:
gcloud beta functions deploy my-function
--trigger-http
--region europe-west1
--memory 128MB
--runtime nodejs16
--entry-point entrypoint
--allow-unauthenticated
# needed to access compute instances
# https://console.cloud.google.com/networking/connectors/list
--vpc-connector cloud-function-connector
# vpc connector should be used only to access private network
--egress-settings private-ranges-only
Now, if my Cloudfunction uses IP address of compute resources, I can easily access them. However when I use their hostnames, the DNS are not resolved which ends up with:
Error: getaddrinfo ENOTFOUND my-compute-resource
What do I need to do to be able to use DNS for my compute instances?
To access a resource via a host name, you must use the Fully Qualified Domain Name (FQDN). Only using the host portion will fail.
A Compute Engine VM has the following FQDN format:
If you only specify the VM_NAME, for which ZONE and PROJECT_ID should the request resolve to? That answer also determines which internal DNS server should be queried for the answer.
To prevent that ambiguity, Google Cloud DNS requires FQDN.
Internal DNS names and Shared VPC