2

I'm trying to migrate a VM on GCP from one project to another. I succeeded until a point where it came to transferring the static IP address.

I detached it from the old VM and then deleted/released it. I went to the new project and attempted to create the new instance with the command:

gcloud compute instances create <name> --address x.x.x.x

And got error:

ERROR: (gcloud.compute.addresses.create) Could not fetch resource:
- Invalid value for field 'resource.address': 'x.x.x.x'. Specified 
IP address is not allocated to the project or does n
ot belong to the specified scope.

I thought instead maybe I needed to reserve the IP address first, and tried:

gcloud compute addresses create <name> --addresses 
x.x.x.x --region us-east1

And from that, got essentially the same thing --

ERROR: (gcloud.compute.addresses.create) Could not fetch 
resource:- Invalid value for field 'resource.address': 'x.x.x.x'. 
Specified IP address is not allocated to the project or does n
ot belong to the specified scope.

I'm following their docs really closely: - https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address

If it had already been claimed in their automatic IP generation by another instance, I would think the error message would be different than this. I also used another gcloud command to look at all my IP reservations and confirm that it is not active on the old project.

JTK
  • 101
  • 3
  • 14

2 Answers2

3

You can only select an IP address that has already been reserved and assigned to your project. You cannot just select any IP address. You will need to reserve a new IP address and update the DNS Resource Records on your DNS servers.

John Hanley
  • 74,467
  • 6
  • 95
  • 159
  • They do let you request a specific IP address, I did it on a previous project because I sandboxed this process to test it out before trying it on a real VM. I had done that successfully just minutes before running into this – JTK Sep 22 '19 at 15:18
  • @JTK - Show me the process on how to pick any IP address and assign this to a Google service. This neither makes sense technically with how the Internet works nor is this supported by any Google API that I am aware of. The exception is for enterprise customers who bring their own IP addresses to Google. – John Hanley Sep 22 '19 at 15:21
0

With your gcloud command, make sure to specify --subnet, i.e.:

gcloud --project=project-id compute addresses create \
    "address-name" \
    --region=us-central1 \
    --subnet=default \
    --addresses=X.X.X.X

You can then specify any X.X.X.X that fits in the default subnet.

Gillespie
  • 5,780
  • 3
  • 32
  • 54