0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

gcloudでインスタンスを作ってすぐに削除する【Google Compute Engine】

Last updated at Posted at 2022-04-24
gcloud compute instances create hoge-vm --zone=us-west1-b --scopes=compute-rw --metadata startup-script='#!/bin/bash
NAME=$(curl metadata.google.internal/computeMetadata/v1/instance/name -H "Metadata-Flavor: Google")
ZONE=$(curl metadata.google.internal/computeMetadata/v1/instance/zone -H "Metadata-Flavor: Google" | cut -d/ -f4)
gcloud compute instances delete $NAME --zone=$ZONE --quiet'

インスタンスを作成して即削除できます。他に実行したい処理があれば、startup-scriptに書いてください

--scopes=compute-rwがないと権限ないと怒られる

hoge-vm login: Apr 24 01:23:07 hoge-vm google_metadata_script_runner[481]: startup-script: ERROR: (gcloud.compute.instances.delete) Could not fetch resource:
Apr 24 01:23:07 hoge-vm google_metadata_script_runner[481]: startup-script:  - Request had insufficient authentication scopes.
Apr 24 01:23:07 hoge-vm google_metadata_script_runner[481]: startup-script:
Apr 24 01:23:07 hoge-vm google_metadata_script_runner[481]: startup-script exit status 1
Apr 24 01:23:07 hoge-vm google_metadata_script_runner[481]: Finished running startup scripts.

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?