google-cloud-platformgoogle-compute-enginestatic-ip-addressstartupscript

Reference ephemeral external IP address in startup script for compute engine


Is there a special variable that references the assigned ephemeral external IP address so I can define it in the startup script?


Solution

  • If your VM start with an ephemeral IP, you can get it directly from the metadata server at this path /instance/network-interfaces/0/access-configs/0/external-ip

    In your startup script, you can include that line if you want to get it

    curl -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip