Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Create instance using template living in another project

Is it possible to use launch a compute engine instance in one project, using an instance template defined in another project?

For example, in project A, I define an instance template. In project B, I submit a Batch job that defines the fully qualified instance template name from Project A to use in the JSON configuration file. 

I have also added the custom service account from Project B as a Principal with Editor role on Project A IAM permissions. 

Solved Solved
2 3 795
1 ACCEPTED SOLUTION

It is not supported today. Mentioned in the API reference page:

https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs

 

Batch only supports global instance templates from the same project as the job. You can specify the global instance template as a full or partial URL.

 

 

View solution in original post

3 REPLIES 3

Hi eshajoshi,

It looks like it's not possible. The Cloud Console gives no option of doing that and when I tried to test it from the Cloud Shell, I received an error (names were redacted):

gcloud compute instances create example-instance --source-instance-template https://www.googleapis.com/compute/v1/projects/[PROJECT_NAME]/global/instanceTemplates/[INSTANCE_TEMPLATE]
Did you mean zone [europe-west4-a] for instance: [example-instance] (Y/n)?

ERROR: (gcloud.compute.instances.create) Could not fetch resource:
- Invalid value for field 'sourceInstanceTemplate': 'https://www.googleapis.com/compute/v1/projects/[PROJECT_NAME]/global/instanceTemplates/[INSTANCE_TEMPLATE]'. Cross project referencing is not allowed for this resource.

As a workaround, you may try this: https://stackoverflow.com/a/63419880/22925881 

While it may not be possible to use an instance template in another project, you can create an instance template in your project that references an image in a different project

It is not supported today. Mentioned in the API reference page:

https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs

 

Batch only supports global instance templates from the same project as the job. You can specify the global instance template as a full or partial URL.