MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

compute/createInstanceWithLocalSSD.js:15–181  ·  view source on GitHub ↗
(projectId, zone, instanceName)

Source from the content-addressed store, hash-verified

13// limitations under the License.
14
15function main(projectId, zone, instanceName) {
16 // [START compute_instances_create_with_local_ssd]
17 // TODO(developer): Uncomment and replace these variables before running the sample.
18 // const projectId = 'YOUR_PROJECT_ID';
19 // const zone = 'europe-central2-b';
20 // const instanceName = 'YOUR_INSTANCE_NAME';
21
22 const compute = require('@google-cloud/compute');
23
24 // Create a new VM instance with Debian 10 operating system and SSD local disk.
25 async function createInstanceWithLocalSSD() {
26 const diskSizeGb = 10;
27 const boot = true;
28 const autoDelete = true;
29 const diskType = `zones/${zone}/diskTypes/pd-standard}`;
30 const disks = [];
31
32 // Get the latest debian image.
33 // Retrieve the newest image that is part of a given family in a project.
34 // Args:
35 // project: project ID or project number of the Cloud project you want to get image from.
36 // family: name of the image family you want to get image from.
37 const imagesClient = new compute.ImagesClient();
38 const [newestDebian] = await imagesClient.getFromFamily({
39 project: 'debian-cloud',
40 family: 'debian-11',
41 });
42
43 // Create the disks to be included in the instance.
44 disks.push(
45 createDiskFromImage(
46 diskType,
47 diskSizeGb,
48 boot,
49 newestDebian.selfLink,
50 autoDelete
51 )
52 );
53 disks.push(createLocalSsdDisk(zone));
54
55 // Create the instance.
56 const [instance] = await createInstance(
57 projectId,
58 zone,
59 instanceName,
60 disks
61 );
62
63 if (instance !== null) {
64 console.log(`Instance created with local SSD: ${instance.name}`);
65 }
66 }
67
68 // Create an AttachedDisk object to be used in VM instance creation. Uses an image as the
69 // source for the new disk.
70 //
71 // Args:
72 // diskType: the type of disk you want to create. This value uses the following format:

Callers 1

Calls 1

Tested by

no test coverage detected