Paulo Steinitch
Paulo Steinitch

Reputation: 21

GCP deployment manager create project with new compute instance

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'
}

Upvotes: 0

Views: 1051

Answers (2)

M.E Taame
M.E Taame

Reputation: 113

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.

Upvotes: 0

M.E Taame
M.E Taame

Reputation: 113

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.

Upvotes: 0

Related Questions