---
title: "GCEインスタンスの名前を変更する | grasys blog"
url: "https://blog.grasys.io/post/tsunoda/gce-instance-change/"
description: "こんにちはtsunodaです。 まだbetaですが、GCEインスタンスの名前が変更できるようになりましたね。 tagは？disk nameはどうなんの？とか気になったので、どこまで変更してくれるのかやってみました。 検証環境 インスタンス名は、 tsunoda-test001 から tsunoda-alpha001…"
---

# GCEインスタンスの名前を変更する

-   ![](/_astro/noicon.CTHOhNiB_1HMs6A.webp)[tsunoda](/authors/tsunoda/)
-   公開日：2023年4月14日
-   カテゴリー：[Tech](/categories/tech/)
-   タグ：[#Compute Engine](/tags/compute-engine/)[#gcloud](/tags/gcloud/)[#Google Cloud](/tags/google-cloud/)

![GCEインスタンスの名前を変更する](/_astro/hero.VAxIMA26_Z1bY0uw.webp)

こんにちはtsunodaです。

まだbetaですが、GCEインスタンスの名前が変更できるようになりましたね。

tagは？disk nameはどうなんの？とか気になったので、どこまで変更してくれるのかやってみました。

## 検証環境

Plain textcontent\_copy

```
Platform:Google Cloud (GCP)
OS：CentOS7
Region：asia-northeast1
GCE:
n1-standard-2
attach-disk付き (boot-disk名=tsunoda-test001、attach-disk名=tsunoda-test001-data)
静的IP付与
HashiCorp consul導入
```

インスタンス名は、**tsunoda-test001** から **tsunoda-alpha001** への変更を試します。

インスタンス名変更後、以下がどうなるか確認しました。

Plain textcontent\_copy

```
tag
boot-disk
attach-disk
静的IP
HashiCorp consulのconsulメンバー登録名
```

## インスタンス名変更

Plain textcontent\_copy

```
# gcloud compute instances list | grep tsunoda | awk '{print $1}'

tsunoda-test001
```

変更するにはインスタンスの停止が必要なので、停止。

Plain textcontent\_copy

```
$ shutdown -h now
```

**インスタンス名変更** (tsunoda-test001 → tsunoda-alpha001へ変更)

Plain textcontent\_copy

```
gcloud beta compute instances set-name tsunoda-test001 \
--new-name=tsunoda-alpha001
```

Plain textcontent\_copy

```
# gcloud compute instances list | grep tsunoda | awk '{print $1}'

tsunoda-alpha001
```

変更されました。

起動

Plain textcontent\_copy

```
gcloud compute instances start tsunoda-alpha001 --zone asia-northeast1-a
```

## tagはどうなった？

Before

Plain textcontent\_copy

```
# curl -s -H "Metadata-Flavor:Google" http://metadata/computeMetadata/v1/instance/tags

["tsunoda-test"]
```

After

Plain textcontent\_copy

```
# curl -s -H "Metadata-Flavor:Google" http://metadata/computeMetadata/v1/instance/tags

["tsunoda-test"]
```

tagは変わらず。新名称での追加も無し。必要であればtagを更新しなければです。

名称変更時にtagも自動で追加してくれると良いかもしれないですね。

ちなみにその他の名称系メタデータ(hostnameやname)は変更されていました。

## disk nameはどうなった？

Before

Plain textcontent\_copy

```
# gcloud compute disks list | grep tsunoda | awk '{print $1}'
tsunoda-test001
tsunoda-test001-data
```

After

Plain textcontent\_copy

```
# gcloud compute disks list | grep tsunoda | awk '{print $1}'
tsunoda-test001
tsunoda-test001-data
```

ディスク名も変更はされませんでした。

インスタンス名に合わせてこちらが指定しただけなので意図通り。

## 静的IPの紐付けは？

Before

Plain textcontent\_copy

```
# gcloud compute addresses list | grep tsunoda
tsunoda-test001                         xx.xxx.xxx.xx    EXTERNAL   
```

After

Plain textcontent\_copy

```
# gcloud compute addresses list | grep tsunoda
tsunoda-test001                         xx.xxx.xxx.xx    EXTERNAL   
```

これも変わらず。

コンソールで確認すると、使用リソース名も変更前のままでした。

![インスタンス名の変更後も維持された静的IPアドレス](/_astro/01-after_ip_console-1-1024x122-261b8ffe.vilENqBO_1oa9Mf.webp)

IPの変更はもちろんなく、引き続き同じ静的IPが付与されてました。

インスタンス名が変わっているのにIPの紐付けは以前のインスタンス名のままなので正直気持ち悪い。。

## HashiCorp consulの登録名はどうなった？

弊社でもよく使用しているHashiCorp社のconsul

今回はこちらも試しました。

server：tsunoda-web

client：tsunoda-test001 (変更後はtsunoda-alpha001)

Before

Plain textcontent\_copy

```
# consul members
Node             Address           Status  Type  
tsunoda-web      10.146.0.5:8301   alive   server 
tsunoda-test001  10.146.0.89:8301  alive   client 
```

After (server側)

Plain textcontent\_copy

```
# consul members
Node              Address           Status  Type 
tsunoda-web       10.146.0.5:8301   alive   server 
tsunoda-alpha001  10.146.0.89:8301  alive   client
tsunoda-test001   10.146.0.89:8301  failed  client
```

server側では変更後のインスタンス名(tsunoda-alpha001)が追加され、変更前のインスタンス名(tsunoda-test001)がfailedとなっていました。

After (client側)

Plain textcontent\_copy

```
# consul members
Node              Address           Status  Type    
tsunoda-web       10.146.0.5:8301   alive   server 
tsunoda-alpha001  10.146.0.89:8301  alive   client
```

client側は変更後にインスタンス起動しているのでfailedは無くスッキリしていました。

hostnameが変わるのでこちらも意図通り。

## まとめ

[ドキュメント](https://cloud.google.com/compute/docs/instances/rename-instance?hl=ja)に大体記載はあり、まぁそうですよねという感じではありますが、本当にインスタンス名のみ変更されますね。

disk名や静的IPなど、そのインスタンスに付随しているものは以前の名称のまま。

これは管理する上でズレが生じちょっとかゆいなぁと思いました。どれがどれだっけ？とかなりそう。

他にはマネージドインスタンスグループ内のインスタンス名は変更できなかったりもします。

ちなみにterraformで作成したインスタンスの名前を変更し、作成に使ったtfファイルで設定の更新や削除をしようとすると、インスタンス名が変更されているので対象ではなくなります。。

現状は新しい名前でインスタンスを再作成した方が管理しやすそうな雰囲気です。

インスタンス名変更に伴い、付随するものも統一して変更できるような機能があるともっと幸せになりそうです。

## この記事を書いた人

[![](/_astro/tsunoda.CrA_Wh9V_Z1aOeCP.webp)](/authors/tsunoda/)

### [tsunoda](/authors/tsunoda/)

tsunodaのプロフィールと執筆記事をご覧いただけます。

[プロフィールと記事一覧](/authors/tsunoda/)