简体   繁体   中英

Gcloud compute api createVM not creating public ip

I use "@google-cloud/compute": "^2.1.0" to create a VM, and I set 'ONE_TO_ONE_NAT' as shown below.

The issue is that the VM is not created with a public IP.

If I add http:true in the config, then the public IP is created but I would like to avoid the http tag in the config.

For me it looks like a bug as it should work according to thedocumentation .

Any idea why it is not working? (apart from a bug)

   const config = {
      //http: true,
      machineType: machineType,
      disks: [
        {
          boot: true,
          initializeParams: {
            sourceImage: SOURCE_IMAGE_PREFIX + projectId + SOURCE_IMAGE_PATH,
          },
        },
      ],
      networkInterfaces: [
        {
          network: 'global/networks/default',
          accessConfigs: {
            type: 'ONE_TO_ONE_NAT',
            name: 'External NAT',
          },
        },
      ],
      metadata: {
        items: [
          {
            key: 'startup-script',
            value: `#! /bin/bash
                sudo docker run ...
          },
        ],
      }
    };

It's just a mistake, that took lot of time to find!!!

accessConfigs is an array,! add [], like this

          accessConfigs: [{
            type: 'ONE_TO_ONE_NAT',
            name: 'External NAT',
          }],

An empty access_config block would assign an external ephemeral IP to your instance.

network_interface {
    network = "default"
    access_config {}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM