Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/nodejs-compute #2853

Merged
merged 174 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 173 commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
5c664af
Added sendgrid example app. Also used for Compute Engine snippet.
jmdobry Dec 4, 2015
e215da8
Add Logging examples.
jmdobry Jan 14, 2016
897d9c1
Added 14 Google App Engine samples.
jmdobry Jan 19, 2016
04f79f6
New Compute Engine samples.
jmdobry Apr 5, 2016
f213b4c
Upgraded dependencies, no longer testing on Node v0.10, switched to C…
jmdobry Apr 13, 2016
d603873
Added requested Mailjet samples.
jmdobry Apr 19, 2016
9008ef1
Switched from JSHint to Semistandard and upgraded dependencies.
jmdobry May 23, 2016
8aa7ac7
Finished a bunch more Readme files.
jmdobry May 25, 2016
5e7ec7f
Update mailjet.js (#125)
Jun 14, 2016
cad2e8c
Refactored tests (#159)
jmdobry Aug 3, 2016
2deb9e5
* Refactored Pub/Sub samples into nice command-line programs, like th…
jmdobry Aug 10, 2016
172baa2
Switch to individual API packages. (#169)
jmdobry Aug 16, 2016
2151afb
Upgrade Sendgrid version in Compute sample (#211)
Sep 13, 2016
bd0e674
Upgrade apps for env:flex. (#241)
jmdobry Oct 20, 2016
34048d0
Revert "Upgrade apps for env:flex." (#242)
jmdobry Oct 20, 2016
6cd33bd
Upgrade GAE apps to env: flex (#253)
jmdobry Nov 14, 2016
bf5e742
Update storage samples. (#263)
jmdobry Dec 9, 2016
1be09d8
Switch from Mocha to Ava for faster tests (#289)
jmdobry Jan 6, 2017
0333dd1
Switch to Yarn for CI build. (#290)
jmdobry Jan 9, 2017
172d9e1
Vision snippets. (#294)
jmdobry Jan 10, 2017
9b28552
Update dependencies.
jmdobry Feb 6, 2017
f6c1033
Travis: fix failing tests + update dependencies (#335)
Apr 5, 2017
076c48b
Cleanup App Engine samples and re-work tests. (#354)
jmdobry Apr 24, 2017
cfc2f7d
Upgrade to repo tools v1.4.7 (#370)
jmdobry May 2, 2017
3f01c09
Upgrade repo tools and regenerate READMEs. (#384)
jmdobry May 10, 2017
409573d
Upgrade repo tools and regenerate READMEs.
jmdobry May 16, 2017
df13d05
Add + run dependency updating (bash) script (#401)
Jun 19, 2017
48e73a3
Update dependencies + fix a few tests (#448)
Aug 5, 2017
14146f3
Build updates. (#462)
jmdobry Aug 23, 2017
31a1697
Update dependencies (#468)
Aug 31, 2017
2da63ac
Repo Migration (#7)
lukesneeringer Oct 31, 2017
001a915
Version bump to 0.8.0 (#8)
lukesneeringer Oct 31, 2017
053f6db
0.9.1 (#42)
stephenplusplus Feb 16, 2018
e7a2be6
v0.10.0 (#54)
stephenplusplus Mar 16, 2018
cfc531b
Upgrade repo-tools and regenerate scaffolding. (#55)
jmdobry Mar 16, 2018
a9eac28
Update @google-cloud/common to the latest version 🚀 (#57)
greenkeeper[bot] Mar 22, 2018
77b6016
Fix link (#62)
jmdobry Apr 10, 2018
e9db288
Fix quickstart code sample (#69)
fhinkel Apr 27, 2018
b029595
chore: lock files maintenance (#71)
alexander-fenster May 2, 2018
1eeefdc
Update repo-tools to 2.3.0 (#72)
fhinkel May 2, 2018
410e9f0
Fix Readme.md in /samples (#73)
fhinkel May 2, 2018
5940b04
test: make samples tests pass (#77)
alexander-fenster May 7, 2018
b4d46f1
chore: lock files maintenance (#78)
alexander-fenster May 8, 2018
8709c9c
Add sample demonstrating startup script (#80)
fhinkel May 9, 2018
da52371
Increase timeout in startup sample test (#86)
fhinkel May 21, 2018
bffc92f
Fix problem with multiple deletes in test (#85)
fhinkel May 21, 2018
12293ce
chore: lock files maintenance (#88)
alexander-fenster May 22, 2018
672fab3
Simplify JS and use HTML standard (#91)
fhinkel May 23, 2018
656df22
Fix formatting (#92)
fhinkel May 29, 2018
d5a00d1
fix: update all the dependencies (#95)
JustinBeckwith Jun 10, 2018
2db99f7
Add mailjet and sendgrid back in (#110)
fhinkel Jun 21, 2018
4521610
chore: update sample lockfiles (#117)
JustinBeckwith Jun 25, 2018
6b90b4c
refactor: drop repo-tool as an exec wrapper (#118)
JustinBeckwith Jun 26, 2018
9335c13
chore(deps): update dependency ava to v0.25.0 (#120)
renovate[bot] Jun 27, 2018
7f69e58
chore(deps): update dependency @google-cloud/nodejs-repo-tools to v2.…
renovate[bot] Jun 27, 2018
3d3742a
chore(deps): lock file maintenance (#123)
renovate[bot] Jul 3, 2018
199945f
chore(deps): lock file maintenance (#127)
renovate[bot] Jul 10, 2018
6f97e4f
fix: drop support for node.js 4.x and 9.x (#126)
JustinBeckwith Jul 10, 2018
e99ea7f
chore(deps): lock file maintenance (#128)
renovate[bot] Jul 10, 2018
b3a6d85
chore(deps): lock file maintenance (#129)
renovate[bot] Jul 10, 2018
06b2d5e
chore(deps): update dependency @google-cloud/nodejs-repo-tools to v2.…
renovate[bot] Jul 12, 2018
8ef2cc8
chore(deps): lock file maintenance (#131)
renovate[bot] Jul 17, 2018
5608552
chore(deps): lock file maintenance (#134)
renovate[bot] Jul 24, 2018
9ac1a9f
chore: require node 8 for samples (#136)
JustinBeckwith Jul 30, 2018
29e0e7b
chore(deps): lock file maintenance (#138)
renovate[bot] Jul 31, 2018
1feb88e
chore(deps): lock file maintenance (#141)
renovate[bot] Aug 7, 2018
286e07f
chore: ignore package-lock.json (#142)
JustinBeckwith Aug 7, 2018
f08998a
fix(deps): update dependency googleapis to v33 (#144)
renovate[bot] Aug 22, 2018
48df157
Enable no-var in eslint (#153)
JustinBeckwith Sep 18, 2018
ce47c47
Enable prefer-const in the eslint config (#155)
JustinBeckwith Sep 20, 2018
eb77011
fix(deps): update dependency googleapis to v34 (#162)
renovate[bot] Sep 28, 2018
b9c3f6a
docs(samples): update samples to use async/await and mocha (#183)
muraliQlogic Nov 3, 2018
ea6e3ca
fix(deps): upgrade to the latest gce-images (#201)
JustinBeckwith Nov 9, 2018
86a8105
chore(deps): update dependency @google-cloud/nodejs-repo-tools to v3 …
renovate[bot] Nov 10, 2018
37fb82b
fix(deps): update dependency googleapis to v35 (#205)
renovate[bot] Nov 10, 2018
55a5655
fix(deps): update dependency googleapis to v36 (#225)
renovate[bot] Dec 7, 2018
b4cea9d
fix: improve the samples and tests (#236)
JustinBeckwith Dec 12, 2018
ab583c2
chore: remove repo-tools from a few spots (#239)
JustinBeckwith Dec 15, 2018
614f364
Release v0.11.0 (#242)
JustinBeckwith Dec 21, 2018
fae7dd0
fix: modernize the samples (#240)
JustinBeckwith Dec 22, 2018
767ecab
docs: use the latest sendgrid npm module (#246)
JustinBeckwith Jan 2, 2019
29681bf
fix(deps): update dependency nodemailer to v5 (#247)
renovate[bot] Jan 14, 2019
530eaa8
build: check broken links in generated docs (#248)
jkwlui Jan 14, 2019
728b2c8
chore(deps): update dependency mocha to v6 (#269)
renovate[bot] Feb 19, 2019
d2d8fc9
Release v0.12.0 (#276)
JustinBeckwith Mar 13, 2019
93a8e54
fix(deps): update dependency nodemailer to v6
renovate[bot] Mar 25, 2019
37f05ff
refactor: use execSync for tests (#286)
JustinBeckwith Apr 12, 2019
39f62d9
docs: use repo-metadata to generate README (#289)
JustinBeckwith Apr 30, 2019
9e536dd
chore: release 1.0.0 (#312)
yoshi-automation May 20, 2019
fbb774a
chore: release 1.0.1 (#314)
yoshi-automation May 22, 2019
74ba13f
chore: release 1.1.0 (#324)
yoshi-automation Jun 20, 2019
0f83260
chore: release 1.1.1 (#334)
yoshi-automation Jun 26, 2019
ac9c023
chore: release 1.1.2 (#340)
yoshi-automation Aug 1, 2019
4daa4d8
chore: release 1.1.3 (#345)
yoshi-automation Aug 26, 2019
9fc8af4
chore: release 1.1.4 (#347)
yoshi-automation Aug 28, 2019
c80c322
chore: release 1.1.5 (#351)
yoshi-automation Sep 10, 2019
fc3bf79
chore: release 1.1.6 (#366)
release-please[bot] Nov 15, 2019
7c40a22
chore: update license headers
JustinBeckwith Nov 25, 2019
06798b8
chore: release 1.1.7 (#372)
release-please[bot] Dec 2, 2019
2fa0778
chore: release 1.1.8 (#376)
release-please[bot] Dec 5, 2019
6c3d812
chore(deps): update dependency mocha to v7 (#386)
renovate-bot Jan 6, 2020
bf211ad
chore: release 1.2.0 (#393)
release-please[bot] Jan 23, 2020
646d7e5
chore(deps): update dependency uuid to v7
renovate-bot Feb 26, 2020
9934c34
fix(deps): update dependency @sendgrid/mail to v7 (#424)
renovate-bot Apr 2, 2020
a9fd2c6
build!: update to latest version of gts and typescript (#433)
sofisl Apr 15, 2020
d338b7e
chore(deps): update dependency uuid to v8 (#441)
renovate-bot May 1, 2020
ff7ac28
chore: release 2.0.0 (#436)
release-please[bot] Jun 5, 2020
c3c14d0
chore(deps): update dependency mocha to v8 (#447)
renovate-bot Jun 11, 2020
6be7c39
test: cleanup logic causes errors (#452)
bcoe Jun 18, 2020
2a23c5e
chore: release 2.0.1 (#446)
release-please[bot] Jun 29, 2020
9469503
chore: release 2.0.2 (#462)
release-please[bot] Jul 9, 2020
35c96f8
chore: release 2.0.3 (#473)
release-please[bot] Jul 27, 2020
c6e431c
chore: release 2.1.0 (#481)
release-please[bot] Aug 10, 2020
3057895
test: remove prettier dep fixing linting (#497)
bcoe Sep 25, 2020
8a4239f
chore: release 2.2.0 (#501)
release-please[bot] Sep 30, 2020
a2b3640
chore: release 2.3.0 (#508)
release-please[bot] Oct 15, 2020
bd07163
chore: release 2.4.0 (#517)
release-please[bot] Nov 5, 2020
cdb578b
chore: release 2.4.1 (#524)
release-please[bot] Dec 2, 2020
1eba89e
chore: release 2.4.2 (#535)
release-please[bot] Jan 8, 2021
298ec5a
chore: release 2.4.3 (#542)
release-please[bot] Jan 27, 2021
f59446d
chore: release 2.4.4 (#552)
release-please[bot] May 5, 2021
34ef8ed
docs: fixes small typo (#553)
haraldreingruber May 19, 2021
f44c805
chore: release 2.5.0 (#561)
release-please[bot] May 25, 2021
2692f4a
chore: release 2.5.1 (#571)
release-please[bot] Jun 10, 2021
11f35b3
chore: release 2.6.0 (#583)
release-please[bot] Jun 29, 2021
b30c442
feat!: new generated version of compute API (#537)
alexander-fenster Aug 11, 2021
2b69657
chore(compute): change LRO wrappers (#605)
FrodoTheTrue Aug 12, 2021
429b53f
chore(samples): remove default rest and compute_protos (#608)
FrodoTheTrue Aug 13, 2021
50620e7
chore: release 3.0.0 (#599)
release-please[bot] Aug 17, 2021
864bb21
feat: add minimum wrapper for compute LRO method (#618)
summer-ji-eng Sep 13, 2021
619078d
test: address race condition with setUsageExportBucket (#622)
bcoe Sep 14, 2021
4eb65b5
chore(samples): start/stop samples (#631)
FrodoTheTrue Oct 15, 2021
9806691
chore(docs): firewall samples
FrodoTheTrue Oct 19, 2021
30e0cd4
chore(samples): create instance from template samples (#640)
FrodoTheTrue Nov 10, 2021
2809f17
test: retry flaky firewall tests (#646)
bcoe Nov 11, 2021
1ea406a
chore(samples): add custom hostname instances samples (#650)
FrodoTheTrue Dec 14, 2021
38265b8
chore(samples): update enums and style (#656)
FrodoTheTrue Dec 16, 2021
d7725cb
fix(deps): update google-gax with http grpc status code mapping (#655)
summer-ji-eng Jan 11, 2022
e5f8b0a
fix!: drop support for Node.js 10 (#668)
alexander-fenster Jan 11, 2022
7b2da88
chore(samples): bump version in samples (#658)
FrodoTheTrue Jan 12, 2022
cc162f3
chore(samples): add create start instance samples
FrodoTheTrue Jan 18, 2022
6baa22d
chore(samples): add periodical instances deletion (#680)
FrodoTheTrue Feb 8, 2022
77b860b
chore(main): release 3.1.2 (#689)
release-please[bot] Feb 16, 2022
7eb38ac
chore(samples): fix function name (#694)
FrodoTheTrue Feb 24, 2022
d5002b1
chore(samples): add delete protection samples (#696)
FrodoTheTrue Mar 8, 2022
b4787c5
chore(samples): add create instance templates samples (#695)
FrodoTheTrue Mar 9, 2022
9607aae
chore(samples): create windows images samples (#703)
FrodoTheTrue Mar 22, 2022
4192ae0
chore(samples): add creating managing windows instances samples (#704)
FrodoTheTrue Mar 22, 2022
015a005
chore(samples): add test comments (#705)
FrodoTheTrue Mar 24, 2022
86de6df
chore(main): release 3.2.0 (#711)
release-please[bot] Apr 13, 2022
7d4cd7e
chore(main): release 3.2.1 (#713)
release-please[bot] May 9, 2022
f476812
chore(samples): fix function name (#719)
FrodoTheTrue May 17, 2022
9883cee
build: update library to use Node 12 (#729)
sofisl May 19, 2022
3886dca
chore(deps): update dependency @google-cloud/storage to v6 (#734)
renovate-bot Jun 6, 2022
3e0c3af
chore(main): release 3.3.0 (#731)
release-please[bot] Jun 6, 2022
bef3bf4
chore(samples): add suspend/resume samples (#735)
FrodoTheTrue Jun 7, 2022
b30b005
chore(samples): add preemptible vm samples (#732)
FrodoTheTrue Jun 7, 2022
847581f
chore(samples): minor changes in a sample comment
savijatv Jun 20, 2022
cd417ca
chore(main): release 3.4.0 (#749)
release-please[bot] Jul 4, 2022
237b8d7
test(samples): do not try creating an instance if it already exists (…
sofisl Jul 13, 2022
b542288
chore(samples): add moving instances between zones samples (#747)
FrodoTheTrue Jul 14, 2022
66e81ad
chore(samples): add custom machine type samples (#742)
FrodoTheTrue Jul 20, 2022
664fb09
test: turn off flaky tests (#791)
bcoe Sep 8, 2022
11f717a
chore(main): release 3.5.0 (#776)
release-please[bot] Sep 8, 2022
01ef19e
chore(deps): update dependency uuid to v9 (#789)
renovate-bot Sep 8, 2022
30f08da
chore(main): release 3.5.1 (#793)
release-please[bot] Oct 6, 2022
7e83f34
Add workflows config
Nov 15, 2022
b289c76
Remove unused tests
Nov 15, 2022
6602ca0
Increase test timeout to 2 hours
Nov 16, 2022
c87e950
Remove unused cleanup code to fix tests
Nov 16, 2022
ff109be
Fix lint
Nov 16, 2022
9d2474d
Fix lint, take 3 (delete more code)
Nov 16, 2022
3ca793c
Add paths param to pull_request_target
Nov 21, 2022
e44f5d3
Merge branch 'main' into nodejs-compute-migration
Nov 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/compute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: compute
on:
push:
branches:
- main
paths:
- 'compute/**'
pull_request:
paths:
- 'compute/**'
pull_request_target:
types: [labeled]
paths:
- 'compute/**'
schedule:
- cron: '0 0 * * 0'
jobs:
test:
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
contents: 'write'
pull-requests: 'write'
id-token: 'write'
steps:
- uses: actions/checkout@v3
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- uses: google-github-actions/auth@v1.0.0
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com'
create_credentials_file: 'true'
access_token_lifetime: 600s
- uses: actions/setup-node@v3
with:
node-version: 14
- run: npm install
working-directory: compute
- run: npm test
working-directory: compute
env:
MOCHA_REPORTER_SUITENAME: compute
MOCHA_REPORTER_OUTPUT: compute_sponge_log.xml
MOCHA_REPORTER: xunit
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
}
- if: ${{ github.event_name == 'schedule' && always() }}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"cloud-tasks/tutorial-gcf/function",
"composer",
"composer/functions/composer-storage-trigger",
"compute",
"container-analysis/snippets",
"containerengine/hello-world",
"container/snippets",
Expand Down
96 changes: 96 additions & 0 deletions compute/create-instance-templates/createTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* Creates a new instance template with the provided name and a specific instance configuration.
*
* @param {string} projectId - Project ID or project number of the Cloud project you use.
* @param {string} templateName - Name of the new template to create.
*/
function main(projectId, templateName) {
// [START compute_template_create]
/**
* TODO(developer): Uncomment and replace these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const templateName = 'your_template_name';

const compute = require('@google-cloud/compute');

// Create a new instance template with the provided name and a specific instance configuration.
async function createTemplate() {
const instanceTemplatesClient = new compute.InstanceTemplatesClient();

const [response] = await instanceTemplatesClient.insert({
project: projectId,
instanceTemplateResource: {
name: templateName,
properties: {
disks: [
{
// The template describes the size and source image of the boot disk
// to attach to the instance.
initializeParams: {
diskSizeGb: '250',
sourceImage:
'projects/debian-cloud/global/images/family/debian-11',
},
autoDelete: true,
boot: true,
},
],
machineType: 'e2-standard-4',
// The template connects the instance to the `default` network,
// without specifying a subnetwork.
networkInterfaces: [
{
// Use the network interface provided in the networkName argument.
name: 'global/networks/default',
// The template lets the instance use an external IP address.
accessConfigs: [
{
name: 'External NAT',
type: 'ONE_TO_ONE_NAT',
networkTier: 'PREMIUM',
},
],
},
],
},
},
});
let operation = response.latestResponse;
const operationsClient = new compute.GlobalOperationsClient();

// Wait for the create operation to complete.
while (operation.status !== 'DONE') {
[operation] = await operationsClient.wait({
operation: operation.name,
project: projectId,
});
}

console.log('Instance template created.');
}

createTemplate();
// [END compute_template_create]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});

main(...process.argv.slice(2));
84 changes: 84 additions & 0 deletions compute/create-instance-templates/createTemplateFromInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* Creates a new instance template based on an existing instance.
*
* @param {string} projectId - Project ID or project number of the Cloud project you use.
* @param {string} instance - The instance to base the new template on. This value uses
* the following format: "projects/{project}/zones/{zone}/instances/{instance_name}"
* @param {string} templateName - Name of the new template to create.
*/
function main(projectId, instance, templateName) {
// [START compute_template_create_from_instance]
/**
* TODO(developer): Uncomment and replace these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const instance = 'projects/project/zones/zone/instances/instance';
// const templateName = 'your_template_name';

const compute = require('@google-cloud/compute');

// Create a new instance template based on an existing instance.
// This new template specifies a different boot disk.
async function createTemplateFromInstance() {
const instanceTemplatesClient = new compute.InstanceTemplatesClient();

const [response] = await instanceTemplatesClient.insert({
project: projectId,
instanceTemplateResource: {
name: templateName,
sourceInstance: instance,
sourceInstanceParams: {
diskConfigs: [
{
// Device name must match the name of a disk attached to the instance
// your template is based on.
deviceName: 'disk-1',
// Replace the original boot disk image used in your instance with a Rocky Linux image.
instantiateFrom: 'CUSTOM_IMAGE',
customImage:
'projects/rocky-linux-cloud/global/images/family/rocky-linux-8',
// Override the auto_delete setting.
autoDelete: true,
},
],
},
},
});
let operation = response.latestResponse;
const operationsClient = new compute.GlobalOperationsClient();

// Wait for the create operation to complete.
while (operation.status !== 'DONE') {
[operation] = await operationsClient.wait({
operation: operation.name,
project: projectId,
});
}

console.log('Instance template created.');
}

createTemplateFromInstance();
// [END compute_template_create_from_instance]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});

main(...process.argv.slice(2));
95 changes: 95 additions & 0 deletions compute/create-instance-templates/createTemplateWithSubnet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* Creates an instance template that uses a provided subnet.
*
* @param {string} projectId - Project ID or project number of the Cloud project you use.
* @param {string} network - The network to be used in the new template. This value uses
* the following format: "projects/{project}/global/networks/{network}"
* @param {string} subnetwork - The subnetwork to be used in the new template. This value
* uses the following format: "projects/{project}/regions/{region}/subnetworks/{subnetwork}"
* @param {string} templateName - Name of the new template to create.
*/
function main(projectId, network, subnetwork, templateName) {
// [START compute_template_create_with_subnet]
/**
* TODO(developer): Uncomment and replace these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const network = 'projects/project/global/networks/network';
// const subnetwork = 'projects/project/regions/region/subnetworks/subnetwork';
// const templateName = 'your_template_name';

const compute = require('@google-cloud/compute');

// Create an instance template that uses a provided subnet.
async function createTemplateWithSubnet() {
const instanceTemplatesClient = new compute.InstanceTemplatesClient();

const [response] = await instanceTemplatesClient.insert({
project: projectId,
instanceTemplateResource: {
name: templateName,
properties: {
// The template describes the size and source image of the boot disk
// to attach to the instance.
disks: [
{
// The template describes the size and source image of the boot disk
// to attach to the instance.
initializeParams: {
diskSizeGb: '250',
sourceImage:
'projects/debian-cloud/global/images/family/debian-11',
},
autoDelete: true,
boot: true,
},
],
machineType: 'e2-standard-4',
// The template connects the instance to the specified network and subnetwork.
networkInterfaces: [
{
network,
subnetwork,
},
],
},
},
});
let operation = response.latestResponse;
const operationsClient = new compute.GlobalOperationsClient();

// Wait for the create operation to complete.
while (operation.status !== 'DONE') {
[operation] = await operationsClient.wait({
operation: operation.name,
project: projectId,
});
}

console.log('Instance template created.');
}

createTemplateWithSubnet();
// [END compute_template_create_with_subnet]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});

main(...process.argv.slice(2));
Loading