* Starts a stopped Google Compute Engine instance (with encrypted disks). * * @param {string} projectId - project ID or project number of the Cloud project your instance belongs to. * @param {string} zone - name of the zone your instance belongs to. * @param {string} instanceName - name of the i
(projectId, zone, instanceName, key)
| 23 | * https://cloud.google.com/compute/docs/disks/customer-supplied-encryption#specifications |
| 24 | */ |
| 25 | function main(projectId, zone, instanceName, key) { |
| 26 | // [START compute_start_enc_instance] |
| 27 | /** |
| 28 | * TODO(developer): Uncomment and replace these variables before running the sample. |
| 29 | */ |
| 30 | // const projectId = 'YOUR_PROJECT_ID'; |
| 31 | // const zone = 'europe-central2-b' |
| 32 | // const instanceName = 'YOUR_INSTANCE_NAME' |
| 33 | // const key = 'YOUR_KEY_STRING' |
| 34 | |
| 35 | const compute = require('@google-cloud/compute'); |
| 36 | |
| 37 | async function startInstanceWithEncryptionKey() { |
| 38 | const instancesClient = new compute.InstancesClient(); |
| 39 | |
| 40 | const [instance] = await instancesClient.get({ |
| 41 | project: projectId, |
| 42 | zone, |
| 43 | instance: instanceName, |
| 44 | }); |
| 45 | |
| 46 | const [response] = await instancesClient.startWithEncryptionKey({ |
| 47 | project: projectId, |
| 48 | zone, |
| 49 | instance: instanceName, |
| 50 | instancesStartWithEncryptionKeyRequestResource: { |
| 51 | disks: [ |
| 52 | { |
| 53 | source: instance.disks[0].source, |
| 54 | diskEncryptionKey: { |
| 55 | rawKey: key, |
| 56 | }, |
| 57 | }, |
| 58 | ], |
| 59 | }, |
| 60 | }); |
| 61 | let operation = response.latestResponse; |
| 62 | const operationsClient = new compute.ZoneOperationsClient(); |
| 63 | |
| 64 | // Wait for the operation to complete. |
| 65 | while (operation.status !== 'DONE') { |
| 66 | [operation] = await operationsClient.wait({ |
| 67 | operation: operation.name, |
| 68 | project: projectId, |
| 69 | zone: operation.zone.split('/').pop(), |
| 70 | }); |
| 71 | } |
| 72 | |
| 73 | console.log('Instance with encryption key started.'); |
| 74 | } |
| 75 | |
| 76 | startInstanceWithEncryptionKey(); |
| 77 | // [END compute_start_enc_instance] |
| 78 | } |
| 79 | |
| 80 | main(...process.argv.slice(2)); |
no test coverage detected