0

I followed this tutorial for creating projects with deployment mangaer: https://cloud.google.com/blog/products/gcp/automating-project-creation-with-google-cloud-deployment-manager

Its working nicely, but I am having trouble figuring out how to create a compute instance inside the newly created project.

Everything I try gives me an error: Machine type specified 'f1-micro' is in a different project '58535xxxxxx' than the instance '919628xxxxxx'.","reason":"invalid"

The instance is trying to be created on the 'ProjectCreation' project (from the tutorial) instead of the newly created project.

The project gets created (the '58535..' number) and I try to reference that in the machineType url. Like :

'https://www.googleapis.com/compute/v1/projects/' + project_id +'/zones/us-central1-f/machineTypes/f1-micro'

I have tried in both the config.yaml and have tried adding an additional resource in the project.py. Both with the same results.

For the python I tried adding to the resources array in project.py:

{
'name': 'server-paul-1',
'type': 'compute.v1.instance',
'metadata': {
    'dependsOn': [project_id]
},
'properties': {
    'zone': 'us-central1-f',
    'machineType': 'https://www.googleapis.com/compute/v1/projects/' + project_id +'/zones/us-central1-f/machineTypes/f1-micro'
}
  • Please post your actual deployment yaml and deployment command. – John Hanley Dec 03 '18 at 21:55
  • Thanks for the reply John. The deployment is found in the tutorial and the only values I've changed are the variables relevant to me: `organization-id, billing-account-name, etc.`. This deployment file can be found @ https://github.com/GoogleCloudPlatform/deploymentmanager-samples/blob/master/examples/v2/project_creation/config.yaml . It references `project.py` and others found in the same directory as the `config.yaml` file – Paulo Steinitch Dec 04 '18 at 15:42

2 Answers2

0

According to the shared documentation, we stated the following:

“We recommend that you use the DM Creation Project primarily to create new projects and their resources. AVOID creating other GCP resources in the Creation project.”

Therefore, I would suggest that you create a new project first and its resources. After that manage the newly created GCP resources, including Compute Engine.

Project resources: 1- the name of the new project you want to create. It must be unique among all project names. 2- Set the organization-id parameter or the parent-folder-id parameter. If both are given, parent-folder-id takes precedence. 3- Set the billing account to use. 4- Set the APIs to turn on. 5- Set the service accounts to create. 6- Set the desired IAM policy for the project.

More details about how to add a configuration and the list of resources, and their respective properties, can be found in the following link.

This being said, please feel free to file a Feature request to be able to add more project resources in the creation process including (Compute Engine, Container Engine, Cloud SQL, BigQuery, etc). I can't guarantee an implementation or provide you with an ETA for it. Rest assured that Google strives on improving its products and that your feedback helps us do just that.

M.E Taame
  • 113
  • 6
  • Thank you Taame. Perhaps I wasn't clear in my question, but I do not want to add a compute instance to the 'DM Creation Project' . I want to add a compute instance to the new project that is being created. Am I missing something? Is it not possible to create a new project with a compute engine at the same time with deployment manager? – Paulo Steinitch Dec 04 '18 at 16:25
  • There is this line: `For example, if you want to create a new project as part of a deployment, you need to ensure that the project is created before you add any resources to it.` found @ https://cloud.google.com/deployment-manager/docs/configuration/create-explicit-dependencies which makes it sound like it is totally possilbe – Paulo Steinitch Dec 04 '18 at 19:02
0

Declarations in Deployment manager are run in parallel, not in sequence. The creation of a project and the creation of other GCP projects are done in parallel. If the project doesn't exist yet, the resource cannot be created.

Deployment Manager will try to run all resource modifications in parallel (unless you specify a dependency between resources). Deployment Manager is a declarative configuration, it will run the deployments in parallel either they are independent of each other or not. The workaround is to use references.

As you noticed in the shared documentation about Dependencies that you provided in the last comment. We always recommend our customers to ensure that the project is created first before adding any resources and that's the reason why I suggested that you create a Feature request to make sure that our product team simplifies the creation steps to make sure that we can do it smoothly with a lot of ease when managing project resources.

M.E Taame
  • 113
  • 6