Problem
Environment
- VPC
- External Static IP.
Solution
The only method to update the fields of a static IP is to recreate and reallocate the same static external IP.
There is no guarantee that the same static IP will be reallocated if it was released while not in use.
Follow these steps in order to have the best chance of getting the same static external IP allocated:
-
Create a new VM in the same project and any zone in the same region and assign it the external IP that needs to be reallocated.
$ gcloud compute instances create [VM_NAME] \ --zone [ZONE] \ --machine-type [MACHINE_TYPE] \ --image-project [IMAGE_PROJECT] \ --image-family [IMAGE_FAMILY] \ --subnet [SUBNET] \ --address [EXTERNAL_STATIC_IP_ADDRESS_TO_BE_REALLOCATED]
-
If billing is a concern, you can stop the VM at this point.
$ gcloud compute instances stop [VM_NAME] --zone [ZONE]
-
Verify that the static address now lists the newly created VM as a user.
$ gcloud compute addresses describe [EXTERNAL_STATIC_IP_NAME] --region [REGION]
-
The output should be similar to the following:
- address: [EXTERNAL_STATIC_IP_ADDRESS]
- addressType: EXTERNAL
- description: [DESCRIPTION]
- status: IN_USE
- users: link
-
Delete the static address.
$ gcloud compute addresses delete [EXTERNAL_STATIC_IP_NAME] --region [REGION] -q
-
Create a new static address specifying the same external static IP address along with the desired new updates. This should work because the IP is still used by the project.
$ gcloud compute addresses create [EXTERNAL_STATIC_IP_NAME] \ --region [REGION] \ --description “[NEW_DESCRIPTION]” \ --addresses [THE_SAME_EXTERNAL_STATIC_IP_ADDRESS]
-
Delete the VM created in the first step.
$ gcloud compute instances delete [VM_NAME] --zone [ZONE] -q
-
Verify that the static address now has the status RESERVED instead of IN_USE.
$ gcloud compute addresses describe [EXTERNAL_STATIC_IP_NAME] --region [REGION].