40

How do I rename a Google Compute Engine VM instance?

I created a new LAMP server and I'd like to rename it in the "VM Instances" dashboard.

I've tried renaming the Custom metadata, but that didn't seem to replicate to the dashboard.

Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
mickeylieu
  • 403
  • 1
  • 4
  • 5

14 Answers14

42

I tried the solution provided by @Marius I . It works, but I lost my description, my metas, the tags and the permissions I've set on the old instance. I had to copy my metas, had to make sure the zone for the new instance was the same as the original, and had to check that the pricing was the same.

I think, it's best to just create a clone of your original instance, this way don't have to manually copy/set them on the new instance.

  1. As @Marius said, create a snapshot of your disk ( DO NOT skip this part: you may lose all your files/configuration )
  2. Make sure you completed the step 1.
  3. Clone your instance (“Create similar” button)
  4. Name your cloned instance the way you want.
  5. Make sure to select the snapshop of your disk created at #1 ( make sure you select the same typeof disk as well: if your original disk was SSD for example, you have to select if you want the new disk to be SSD too )
  6. Make sure your IPs are set correctly

You're done :)

Brian Dorsey
  • 4,588
  • 24
  • 27
gabriel-kaam
  • 1,230
  • 1
  • 12
  • 13
  • 1
    Please add a comment saying 'Clone doesn't copy your disk, only the config of your instance' - I lost all I had set up coz I didnt believe they wouldnt give warnings :( – killjoy May 18 '17 at 10:07
  • 1
    Hey @killjoy , sorry to hear that . but what did u lose exactly ? If you used a snapshot of your disk , it should preserve pretty much everything you had set up. – gabriel-kaam May 19 '17 at 11:14
  • 1
    @gabriel...No worries, I meant it was more of GCE's fault for not giving us a warning/indication of what clone does, but more importantly, it was my bad for not reading/implementing Step 1 and I went straightaway to do a clone as I jumped to the conclusion its a full clone :) In short, I did not create a snapshot and what I meant in my comment was for you to please highlight Step 1 as a must-do as I skipped it. – killjoy May 20 '17 at 13:36
  • Apparently Google Cloud renamed the button used to create a clone from "Clone" to "Create Similar". – moodboom Jan 30 '20 at 16:54
38

Another way to do this is:

  • snapshot the disk of the existing instance
  • create a new disk from that snapshot
  • create a new instance with that disk and give it the name you would like

It sounds time-consuming, but in reality should take 5 minutes.

Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
Marius I
  • 1,461
  • 12
  • 13
  • 4
    Warning - This answer does not retain the settings. Use the one below by gabriel – killjoy May 18 '17 at 13:00
  • 5
    Even easier: You can now clone the machine, name the new instance, and delete the old one. Literally takes 15 seconds. – labroid Jun 16 '17 at 06:41
26

you can't ...! Once VM is created, you can’t change the Instance Name

Raja Simon
  • 10,126
  • 5
  • 43
  • 74
12

There's now a "native" way to do this. The feature is currently in Beta and only available with gcloud and via the API. With gcloud you can run:

$ gcloud beta compute instances set-name CURRENT_NAME -—zone=ZONE -—new-name=NEW_NAME

Some caveats:

  • You'll need to shut down the VM first
  • The Developer Console UI won't be aware of the rename until you do a browser refresh

See the official documentation for more details.

neic
  • 107
  • 4
Sirui Sun
  • 616
  • 7
  • 6
11

Apart from the hacks above, it's not possible.

Yet, it has been requested on uservoice and has received 593 votes. (as of 2018) Currently, it's the topmost "planned" item.

serv-inc
  • 35,772
  • 9
  • 166
  • 188
  • 8
    483 votes as of today. Enjoyed the moderator comment "it's on the radar" and the user reponse "Where is the radar pointed? Mars?" – Wil Jul 24 '18 at 10:07
  • As of December 2019, it has 1,139 votes and is marked as "planned" – tutuDajuju Dec 10 '19 at 06:39
9

I got lost in the instructions, so I thought I include screenshots because the navigation is confusing. I hope this helps you.

  • Stop your instance
  • Click on the stopped instance name

enter image description here

  • In VM Instance Details, scroll down and click on the disk

enter image description here

  • Click on Create snapshot

enter image description here

  • give it a name like snapshot-1 (or your new instance name)
  • click on Create button

enter image description here

  • click on newly created snapshot

enter image description here

  • Click on Create Instance

enter image description here

  • Give your instance the new name and configure the rest of the VM.

enter image description here

Sun
  • 2,595
  • 1
  • 26
  • 43
  • Underrated answer – Nathan majicvr.com Apr 30 '20 at 17:09
  • 1
    Thanks. I was 3 years late to the party and things had changed enough with Google Cloud UI to warrant my answer. I only did it because there were a lot of confusing traps with just text answers, so it was important you clicked on the right thing. Not saying this is the best way, but this worked for me at the time. – Sun May 01 '20 at 19:31
  • Their UI also changes all the time, seemingly for no reason. Harder to find things that way: very counterproductive. It's like, "there are enough features in this service already, Google employee, you don't have to make it harder to find them just to satisfy your OCD" – Nathan majicvr.com May 01 '20 at 20:05
1

When dealing with a robust system, it's necessary to have a way to bring up a system quickly when it goes down. This could be via custom scripts, salt, ansible, etc.

So, if you want to change your instance name, delete the instance, create a new one with the correct name, and run your script again :)

John Asmuth
  • 1,052
  • 5
  • 7
1

To answer your question directly. You cannot edit the VM Instance name.

However, you can create New VM instance using your old disk. To meet the VM instance name that you want.

Kindly see below procedure:

  1. Go to Compute Engine Page
  2. Go to Disk Page
  3. Select the disk of your VM instance that you want to create a snapshot
  4. Click the three dot image same line of your disk
  5. Select +Create Snapshot (You will be go to Create Snapshot page). Kindly name your snapshot (backup)
  6. Just Click Create.

Then once you have created a snapshot for your VM instance disk, you may now proceed on creating your new instance from snapshot pointing to other region which you can consider such: us-central1, us-west1 and us-west2. Please see below procedure:

  1. Go to Snapshot Page
  2. Select snapshot "backup" (You should be on Snapshot details Page)
  3. Click Create Instance (Choose best name for your new VM Instance)
  4. Please select the region best fit for you (us-central1, us-west1 and us-west2) except us-east1.
  5. Lastly, Click Create
Kervin L
  • 474
  • 4
  • 5
1

Machine images are now in pre-GA!

This is currently the easiest way to clone an instance without losing your instance configurations, check this comparison table.

Detailed steps:

  1. Go to Compute Engine > Virtual Machines > Machine Images
  2. Click on create Machine Image
  3. Select your current instance under Source VM instance and click create
  4. Once the image becomes ready go to Machine image details and click on create instance
  5. The form will be populated by your existing instance configuration and you'll be able to change them before creating the instance!
Abdessamad
  • 171
  • 2
  • 3
  • 1
    I don't know why this has no upvotes. I did exactly this pathway and had a perfect clone in about a minute. – FontFamily Sep 05 '21 at 17:20
1

Sorry to resurrect this thread after so long, but when I searched for an answer I kept ending up in this article... :-)

The Cloud SDK now allows renaming an instance directly, provided it's stopped:

The command looks like this:

gcloud beta compute instances set-name INSTANCE_NAME --new-name=NEW_NAME [--zone=ZONE] [GCLOUD_WIDE_FLAG …]

This is not available yet in the UI.

Jay Frias
  • 53
  • 7
  • It's perfectly fine to add a new answer if it provides a distinct and useful contribution to the Q&A. However it does seem that this information is already provided in [this existing answer](https://stackoverflow.com/a/65099854/5320906). – snakecharmerb Sep 17 '21 at 12:24
  • The command isn't an exact copy though. If you could elaborate on the difference, that would be good. – General Grievance Sep 17 '21 at 13:20
1

The following worked for me:

gcloud beta compute instances set-name currentname --new-name=newname

pkal
  • 45
  • 4
1

Googler checking in. We're rolling out this feature (renaming a VM) to all users in the cloud console. Public documentation.

In the Google Cloud console:

  • Go to the VM instances page.
  • Go to VM instances
  • In the Name column, click the name of the VM.
  • Click Stop stop.
  • Click Edit edit.
  • In Basic information > Rename > VM instance name, enter a new name
  • for the VM.
  • Click Save. Click Start / Resume play_arrow.

Using the gcloud Command Line Interface:

gcloud compute instances stop INSTANCE_NAME
gcloud beta compute instances set-name INSTANCE_NAME --new-name=NEW_INSTANCE_NAME

I also wanted to let you all know that we monitor these forums and use your feedback to influence our roadmap. Thank you for your engagement!

Brian Dorsey
  • 4,588
  • 24
  • 27
  • This command can change the instance name to something like `my-test-instance`, but cannot change the name to something like `example.com`, which appears to be only possible during VM creation [reference](https://cloud.google.com/compute/docs/instances/custom-hostname-vm) The latter is important for a correctly set `hostname` for features like SSL/Apache. Is anything changing in the near future? – John Hanley Apr 23 '23 at 22:24
  • An instance name like `example.com` is not supported on instance name or instance rename (the same validation logic is used for both cases). Instance names must match the following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`. – Don Bushell Apr 24 '23 at 23:31
  • Correct. However, people get confused between the VM instance name and the hostname. Unless the hostname is set when the Compute Engine instance is created (which cannot be changed later), the instance name is used for the hostname and the internal (private) DNS name. That can cause issues with, for example, Apache. This [document](https://cloud.google.com/compute/docs/instances/custom-hostname-vm) explains what I am referring to. What I was asking is for a feature to rename the Compute Engine instance hostname after an instance has been created. – John Hanley Apr 24 '23 at 23:41
0

I am trying to do this 03/2019 and I saw a new option on panel

click Instance link
on top menu you will see "Create Similar"

could work if you need same machine without data. (solved my case) if you need a full copy then you should create a snapshot and clone it.

Alp Altunel
  • 3,324
  • 1
  • 26
  • 27
0

This is now possible via the web console: Screenshot