Reputation: 1194
I have an existing Cloud Compute Engine instance that was mistakenly assigned the wrong static internal IP.
I cannot figure out a way to modify the internal IP address to the correct value using the Console or other means. I have tried reserving a new static internal IP, which is easy enough, but there is no way to assign it to an existing resource.
I am talking about Google Console -- not the OS. I know how to change the value in the OS itself.
When I view the resource directly on Google Console and try to edit nic0 in the Google Console, it does not give me any option to modify the existing static IP to a different address. It just says "static ip: 10.x.x.x".
I could easily enough just nuke this resource and make a new one, except for the policy of not being able to re-use the resource name. And I want this specific resource name, so killing it or cloning it is not an option. I just need to modify it's internal IP!
Edit to add: To be clear, I have no problem stopping the instance. I just don't want to destroy it due to reserved naming policy preventing re-use of resource names. I need to modify an in-place resource to a new internal static reserved IP.
Upvotes: 5
Views: 10889
Reputation: 11
For those who are searching for a way to change internal parameters from a GCP instance without the hassle of recreating it:
Export the instance's config with
gcloud compute instances export $INSTANCE_NAME \
--project $PROJECT_ID \
--zone $ZONE \
--destination=$FILE_PATH
(fill the variables with your parameters)
Edit the file that created by "--destination" and change the resource that you need
gcloud compute instances update-from-file $INSTANCE_NAME \
--project $PROJECT_ID \
--zone $ZONE \
--source=$FILE_PATH \
--most-disruptive-allowed-action REFRESH
# or
# --most-disruptive-allowed-action RESTART
# if what you are doing might require a reboot
This procedure saved me when I needed to change "canIPForward" from "false" to "true" without having to recreate the VM.
For more info about that, check this out: https://cloud.google.com/compute/docs/instances/update-instance-properties
Upvotes: 1
Reputation: 328
As of 2021 the accepted answer is incorrect. You can move the instance with the wrong internal static IP address to a different network and then move it back to the original network: This bizarelly allows you to reassign the internal IP.
Upvotes: 9
Reputation: 310
Once you have a VM instance created, you cant change internal IP. It is mentioned explicitly.
The only option you have is to create a new VM with a static IP. You can make a snapshot of the disk from the VM you are using, then create a new VM from that disk marking --private-network-ip.
Create a disk from a snapshot:
gcloud compute --project "your-project" disks create "instance-x" \
--size "100"
--zone "europe-west1-c" \
--source-snapshot "snapshot-x" \
--type "pd-standard"
Use the disk to create a new VM with a predefined internal IP:
gcloud compute --project=your-project instances create instance-x \
--zone=europe-west1-c \
--private-network-ip=your-ip \
--disk=name=instance-x,device-name=instance-x,mode=rw,boot=yes,auto-delete=yes
Upvotes: 7