Search code examples
google-cloud-platformgcloudgoogle-cloud-compute-enginegoogle-cloud-instance-template

GCP create instance-template for instances with public ip


I am trying to create an instance-template, where a instance create with this template automatically gets an public ipv4 asigned.

Currently I am using something like following gcloud command:

gcloud compute instance-templates create TEMPLATENAME \
    --project=PROJECT \
    --machine-type=e2-small \
    --network-interface=network=default,network-tier=PREMIUM \
    --maintenance-policy=MIGRATE --provisioning-model=STANDARD \
    --service-account=SERVICE_ACCOUNT \
    --scopes=https://www.googleapis.com/auth/cloud-platform \
    --tags=http-server,https-server \
    --create-disk=CREATE_DISK \
    --no-shielded-secure-boot \
    --shielded-vtpm \
    --shielded-integrity-monitoring \
    --reservation-affinity=any

This command is generated by the Google Cloud Console, but I have to use gcloud since I have to use a image-family to create the disk (which is to my knowledge not supported using gui).

If running this command I get the following result: enter image description here

The result I want to get is: enter image description here

What am I missing?


Solution

  • In order to get an ephemeral IP adress has to be set as empty string in the network interface flag.

    --network-interface=network=default,network-tier=PREMIUM,adress=''
    

    see https://cloud.google.com/sdk/gcloud/reference/compute/instance-templates/create?hl=de#--network-interface