2
votes

I am trying to create an instance with the Google Java API however I am getting an error:

{ "code" : 400, "errors" : [ { "domain" : "global", "message" : "Invalid value for field 'resource.machineType': 'https://www.googleapis.com/compute/v1/projects/...snip.../zones/europe-west1-a/machineTypes/n1-standard-1'. Cross-project references for this resource type are not allowed.", "reason" : "invalid" } ], "message" : "Invalid value for field 'resource.machineType': 'https://www.googleapis.com/compute/v1/projects/...snip.../zones/europe-west1-a/machineTypes/n1-standard-1'. Cross-project references for this resource type are not allowed." }

The code I am using:

    Compute compute = getComputeService();

    // uri reveals: https://www.googleapis.com/compute/v1/projects/...projectid.../zones/europe-west1-a/machineTypes/n1-standard-1

    String uri = GOOGLE_BASE + this.project + "/zones/" + zone + INSTANCETYPES + type;

    Instance instance = new Instance();
    instance.setName(name);
    instance.setZone(zone);
    instance.setMachineType(uri);

    List<AttachedDisk> disks = new ArrayList<AttachedDisk>();
    AttachedDisk boot = new AttachedDisk();
    boot.setAutoDelete(false);
    boot.setType(disk.getType());
    boot.setBoot(true);
    boot.setDeviceName(disk.getName());
    disks.add(boot);

    List<NetworkInterface> interfaces = new ArrayList<NetworkInterface>();
    NetworkInterface nat = new NetworkInterface();
    nat.setName("External NAT");
    nat.setNetwork("ONE_TO_ONE_NAT");


    instance.setNetworkInterfaces(interfaces);
    instance.setDisks(disks);

    Instances.Insert request = compute.instances().insert(name, zone, instance);

    Operation result = request.execute();
1

1 Answers

0
votes

As per this link, I believe that your request should look like:

Instances.Insert request = compute.instances().insert(this.project, zone, instance);