diff --git a/packages/google-cloud-compute/src/zone.js b/packages/google-cloud-compute/src/zone.js index d39c868fb1b..b4e5f45a51a 100644 --- a/packages/google-cloud-compute/src/zone.js +++ b/packages/google-cloud-compute/src/zone.js @@ -582,23 +582,18 @@ class Zone extends common.ServiceObject { createVM(name, config, callback) { const self = this; const query = {}; - const body = Object.assign( - { - name: name, - machineType: 'n1-standard-1', - networkInterfaces: [ - { - network: 'global/networks/default', - }, - ], - }, - config - ); + const body = Object.assign({name}, config); if (body.template) { query.sourceInstanceTemplate = body.template; delete body.template; } - if (body.machineType.indexOf('/') === -1) { + if (!is.defined(query.sourceInstanceTemplate)) { + body.machineType = body.machineType || 'n1-standard-1'; + body.networkInterfaces = body.networkInterfaces || [ + {network: 'global/networks/default'}, + ]; + } + if (body.machineType && body.machineType.indexOf('/') === -1) { // The specified machineType is only a partial name, e.g. 'n1-standard-1'. body.machineType = format('zones/{zoneName}/machineTypes/{machineType}', { zoneName: this.name, diff --git a/packages/google-cloud-compute/test/zone.js b/packages/google-cloud-compute/test/zone.js index 6c03fd667fb..728c6b7bfe4 100644 --- a/packages/google-cloud-compute/test/zone.js +++ b/packages/google-cloud-compute/test/zone.js @@ -791,6 +791,27 @@ describe('Zone', () => { zone.createVM(NAME, CONFIG, assert.ifError); }); + + it('should not set default value for machineType', done => { + zone.request = function (reqOpts) { + assert.strictEqual(typeof reqOpts.json.machineType, 'undefined'); + done(); + }; + + zone.createVM(NAME, CONFIG, assert.ifError); + }); + + it('should not set default value for network', done => { + zone.request = function (reqOpts) { + assert.strictEqual( + typeof reqOpts.json.networkInterfaces, + 'undefined' + ); + done(); + }; + + zone.createVM(NAME, CONFIG, assert.ifError); + }); }); describe('config.machineType', () => {