5
votes

I'm trying to set up Terraform for use with GCP and I'm having trouble creating a new project from the gcloud cli: Terraform Lab

The command I'm using is

gcloud projects create testproject

The error I get over and over is:

ERROR: (gcloud.projects.create) Project creation failed. The project ID you specified is already in use by another project. Please try an alternative ID.

Here's what I did so far:

  1. I created an "organization" and a user in Cloud Identity
  2. Logged into GCP console in the browser with the user I created
  3. The user has "Organization Administrator" role
  4. Using the Cloud Shell or gcloud configured on my home computer, I am not able to create a new project. I am able to do things like "gcloud projects list" and "gcloud organizations list" successfully in both cases (cloud shell & local gcloud install)
  5. I have tried this with different project ID names that are within the format requirements (eg 6-30 chars, lowercase, etc). I can also confirm that the project IDs do not exist.
  6. However, I am able to successfully create projects via GCP web console (https://console.cloud.google.com) (using the same IAM account configured in gcloud cli)
  7. I have tried "gcloud init" several times making sure I am using the right IAM account, just in case.

Here's the error I get when I try to create a new project from the "gcloud init" command:

Enter a Project ID. Note that a Project ID CANNOT be changed later.
Project IDs must be 6-30 characters (lowercase ASCII, digits, or
hyphens) in length and start with a lowercase letter. vincetest
WARNING: Project creation failed: HttpError accessing 
<https://cloudresourcemanager.googleapis.com/v1/projects?alt=json>: 
response: <{'status': '409', 'content-length': '268', 'x-xss
-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 
'transfer-encoding': 'chunked', 'vary': 'Origin, X-Origin, Referer', 
'server': 'ESF', '-content-encoding': 'gzip',
 'cache-control': 'private', 'date': 'Fri, 28 Sep 2018 18:38:11 GMT', 
 'x-frame-options': 'SAMEORIGIN', 'content-type': 'application/json; 
 charset=UTF-8'}>, content <{
  "error": {
    "code": 409,
    "message": "Requested entity already exists",
    "status": "ALREADY_EXISTS",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ResourceInfo",
        "resourceName": "projects/vincetest"
      }
    ]
  }
}
>

Creating the project from the web page console worked fine.

5
The gcloud docs say "Note that you can't reuse the project ID of a deleted project."Hitobat

5 Answers

6
votes

Project IDs are unique across all projects. That means if any user ever had a project with that ID, you cannot use it. testproject is pretty common, so it's not surprising it's already taken.

Try a more unique ID. One common technique is to user your organization's name as a prefix.

0
votes

Here is another link with more information about creating projects. With detail on how to do it in the console, gcloud, API, and Python.

Another issue that comes up: Verify that you are using the right account when invoking the commands:

gcloud auth list

If you are trying to check the existence of the project by using :

gcloud projects describe project-name

before you try to create it like in this post. The issue is that if you don't have rights to it you get the same sort of error if it exists or not.

User [[email protected]] does not have permission to access project [project-name] (or it may not exist): User is not authorized.

I even tried to create a new project with the same name as a project in a different unrelated org. The key seems to be to add anything alpha or numeric to make it distinct.

Hope that helps.

0
votes

Google cloud collects all projects in the world which related to GCP(google cloud platform)

So you should create a project with a unique ID.

0
votes

To set your Cloud Platform project using Cloudshell use: gcloud config set project [PROJECT_ID] replacing [PROJECT_ID] with your project name.

Then your CLI would look like

> admin_@cloudshell:~/underperformance_notifications (PROJECT_ID)$

-4
votes

I think I figured it out.

The project ID must be followed by some numbers:

gcloud projects create tf-admin-001 --name tf-admin --organization xxxx --set-as-default

Geez. It does not specifically say so here: gcloud docs