1

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 the documentation.

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 ...
          },
        ],
      }
    };
halfer
  • 19,824
  • 17
  • 99
  • 186
unludo
  • 4,912
  • 7
  • 47
  • 71
  • Where do you add the HTTP config/label? In the network tags? – guillaume blaquiere Nov 30 '20 at 16:19
  • @guillaumeblaquiere no at the top level as you can see in the code sample. It's commented and I would like not to use this tag because I don't want http, I just want a public IP on the network interface – unludo Nov 30 '20 at 16:33
  • 1
    `accessConfigs` should be an array of object, not an object directly. – Hitobat Nov 30 '20 at 20:47

2 Answers2

3

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',
          }],
guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
0

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

network_interface {
    network = "default"
    access_config {}
}

Airus
  • 35
  • 4