Getting a new permanent IP address on google cloud compute

google-cloud-platformgoogle-compute-engine

I've created a few instances in google compute engine by using the web interface. I want to start doing it at the command line instead so that I can create more and automate the process. The web interface tells me what command I could use when creating an instance. I request a permanent public IP address, and I can see the command which works, but how do I know what addresses are available to request? For instance, let's stay I created serverA with the command "gcloud compute … instances create "serverA" .. –address 1.2.3.4 …" I reused an address I had been previously assigned, but I think I got lucky in that it worked, and I can't guess what other IP addresses to use when I want to create more instances on the command line. Is there a way to query for available addresses? Thank you.

Tom

Best Answer

UPDATE

A second approach to do this is by using the deployment manager. You can have a configuration file where you create the IP resource. In the same file you specify to deploy the VM with that IP assigned.

i.e. running

gcloud deployment-manager deployments create testdeploy --config=myconf.yaml

where myconf.yaml file content is

resources:
- name: test-rabbitmq-ip
  type: compute.v1.address
  properties:
    region: us-central1
- type: compute.v1.instance
  name: vm-my-first-deployment1
  properties:
    zone: us-central1-f
    machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/machineTypes/f1-micro
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-8-jessie-v20160923
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default
      # Access Config required to give the instance a public IP address
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT
        natIP: $(ref.test-rabbitmq-ip.address)
Related Topic