建立及管理專案

Google Cloud 專案是建立、啟用及使用所有 Google Cloud 服務的基本要件,例如管理 API、啟用計費功能、新增及移除協作者,以及管理 Google Cloud 資源的權限。

本頁說明如何使用 Cloud Resource Manager API 和 Google Cloud 控制台,建立及管理 Google Cloud 專案。

事前準備

請參閱資源階層概要中的專案資源。如需設定資源階層結構的指引,請參閱為 Google Cloud 登陸地帶決定資源階層結構

以下項目可用來識別專案:

  • 專案名稱:專案的可理解文字名稱。

    Google API 無法使用專案名稱。您可以在建立專案期間或之後隨時編輯專案名稱。專案名稱不必是專屬名稱。

  • 專案 ID:專案的全域專屬 ID。

    專案 ID 是專屬字串,用於區分 Google Cloud中的專案。輸入專案名稱後,Google Cloud 主控台會產生專屬專案 ID,其中可包含字母、數字和連字號。建議您使用系統產生的專案 ID,但您可以在建立專案時編輯該 ID。專案建立後,專案 ID 就會永久存在。

    專案 ID 必須符合下列規定:

    • 長度必須介於 6 至 30 個字元之間。
    • 只能使用小寫英文字母、數字和連字號。
    • 開頭必須是英文字母。
    • 結尾不得為連字號。
    • 不得正在使用或曾使用過,包括已刪除的專案。
    • 不得包含受限制的字串,例如 googlessl。建議不要在專案 ID 中使用字串 undefinednull

  • 專案編號:系統自動為專案產生的專屬 ID。

請勿在專案名稱、專案 ID 或其他資源名稱中加入個人識別資訊 (PII) 或安全性資料等機密資訊。許多其他 Google Cloud 資源的名稱都會使用專案 ID,因此任何對專案或相關資源的參照都會公開專案 ID 和資源名稱。

建立專案

您必須具有 resourcemanager.projects.create權限才能建立專案。專案建立者角色 (roles/resourcemanager.projectCreator) 等角色都具備這項權限。

根據預設,系統會將「專案建立者」角色授予新機構資源的整個網域,以及免費試用的使用者。

如要進一步瞭解如何為個人授予角色,以及如何對整個機構資源的存取權設定限制,請前往「管理預設的機構角色」頁面。

如果未指定父項資源,系統會根據使用者帳戶的網域,在適用情況下自動選取父項資源。

您可以使用 Google Cloud 控制台、Google Cloud CLI 或 projects.create() 方法建立新專案。

主控台

如要建立新專案,請執行下列步驟:

  1. 前往控制台的「Manage resources」(管理資源) 頁面。 Google Cloud

    前往「Manage Resources」(管理資源) 頁面

    其餘步驟會顯示在 Google Cloud 控制台。

  2. 在頁面頂端的「Select organization」(選取機構) 下拉式清單中,選取要建立專案的機構資源。如果您是免費試用的使用者,請略過這個步驟,因為系統不會顯示這個清單。
  3. 按一下「Create Project」(建立專案)
  4. 在顯示的「New Project」(新增專案) 視窗中,輸入專案名稱並選取適當的帳單帳戶。專案名稱只能由英文字母、數字、單引號、連字號、空格或驚嘆號組成,而且長度必須介於 4 至 30 個字元之間。
  5. 在「Location」(位置) 方塊中輸入上層機構或資料夾,該資源將成為新專案的階層父項。如果系統顯示「No organization」(無機構) 這個選項,只要選取該選項即可建立新專案,做為其資源階層的頂層。
  6. 輸入新專案的詳細資料後,按一下「Create」(建立)

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 如要建立新專案,請使用 gcloud projects create 指令:

    gcloud projects create PROJECT_ID
    

    其中 PROJECT_ID 是您要建立的專案 ID。 專案 ID 的開頭必須是小寫英文字母且僅包含 ASCII 字母、數字或連字號,並且必須介於 6 至 30 個字元。

    如要建立以機構資源或資料夾作為父項的專案,請使用 --organization--folder 標記。每個資源只能有一個父項,所以只能使用其中一個標記。

    gcloud projects create PROJECT_ID --organization=ORGANIZATION_ID
    
    gcloud projects create PROJECT_ID --folder=FOLDER_ID
    

API

使用 projects.create() 方法建立新專案時,專案 ID 不能使用特定文字,例如 googlenullundefinedssl。 如果使用限用字,要求就會傳回 INVALID_ARGUMENT 錯誤。

下列要求只會建立專案,不會自動將其關聯至帳單帳戶。您可使用 projects.updateBillingInfo 方法來設定或更新與專案相關聯的帳單帳戶。

建立專案要求:

POST https://cloudresourcemanager.googleapis.com/v3/projects/
Authorization: *************
Content-Type: application/json

{
    "projectId": "our-project-123",
    "name": "my project",
    "labels": {
      "mylabel": "prod"
    }
}

建立專案回應:

{
    "name": "operations/pc.123456789",
}

取得作業要求:

GET https://cloudresourcemanager.googleapis.com/v3/operations/pc.123456789
Authorization: *************
Content-Type: application/json

取得作業回應:

{
    "name": "operations/pc.123456789",
    "done": true,
    "response": {
        "@type": "type.googleapis.com/google.cloudresourcemanager.v3.Project",
        "projectNumber": "464036093014",
        "projectId": "our-project-123",
        "lifecycleState": "ACTIVE",
        "name": "my project",
        "labels": {
        "mylabel": "prod"
        },
    "createTime": "2016-01-07T21:59:43.314Z"
    }
}

在建立專案時新增標籤

標記可為資源建立註解。您可以在建立專案時新增標記。新增標記時,您必須指派「標記使用者」角色。如要進一步瞭解指派給這個角色的權限,請參閱「管理資源上的標記」。您只能透過下列其中一種方式,為代碼鍵/值組合新增命名空間:

gcloud

如要在建立專案時新增標記,請執行下列指令:

gcloud projects create PROJECT_ID --organization=ORGANIZATION_ID --tags=KEY_VALUE_PAIRS

更改下列內容:

  • PROJECT_ID 是專案的專屬 ID。
  • ORGANIZATION_ID 是機構的專屬 ID。
  • KEY_VALUE_PAIRS 是以逗號分隔的鍵/值組合清單,可指派給資源。以半形逗號分隔的鍵/值組合範例如下:123/environment=production, 456/create=testresource

API

下列程式碼片段是 JSON 要求,用於建立專案並在其中新增標記。

  POST https://cloudresourcemanager.googleapis.com/v3/projects/
  Authorization: *************
  Content-Type: application/json

  {
    "projectId": "our-project-456",
    "name": "my project",
    "parent": "organizations/123",
    "tags": {
      "key": "123/environment"
      "value": "production"
    },
"tags": {
      "key": "123/costCenter"
      "value": "marketing"
  }
}

使用服務帳戶建立專案

您可以使用服務帳戶自動建立專案。與使用者帳戶一樣,服務帳戶也可以獲得在機構資源中建立專案的權限。服務帳戶不得在機構資源外建立專案,且建立專案時必須指定父項資源。服務帳戶可以使用 gcloud CLI 或 projects.create() 方法建立新專案。

管理專案配額

如果配額中剩餘的專案數量不到 30 個,「New Project」(新增專案) 頁面就會顯示通知,說明配額中所剩的專案數量。達到專案數量上限後,如要建立更多專案,請要求提高專案數量上限。您也可以前往「管理資源」頁面,排定在 30 天後刪除部分專案。使用者虛刪除的專案會計入配額。30 天後,系統就會徹底刪除這些專案。

如要要求機構配額的額外專案容量,請按照下列步驟操作:

  1. 前往「配額與系統限制」頁面。

    前往「配額與系統限制」

  2. 在資源選取器中,選取要提高專案配額的機構。

  3. 在「篩選器」選項中,選取「指標」並輸入 cloudresourcemanager.googleapis.com/projects_count

  4. 選取「Cloud Resource Manager API」,按一下「更多動作」圖示 ,然後選取「編輯配額」圖示

  5. 在「Quota changes」(配額變更) 對話方塊中,輸入新的配額值和說明,然後按一下「Next」(下一步)

  6. 輸入聯絡資料,然後按一下「提交要求」

我們會發送電子郵件通知,確認已收到您的要求。如需進一步協助,請回覆該電子郵件。審查完畢後,我們會傳送電子郵件,通知您要求是否獲准。

如果您沒有機構,但想要求增加專案配額,請填寫要求增加專案配額表單。

如要進一步瞭解配額及使用配額的原因,請參閱「免費試用專案配額要求」支援頁面。如要進一步瞭解帳單報表,請參閱帳單報表支援頁面。

找出專案名稱、編號和 ID

如要與 Google Cloud 資源互動,您必須為每個要求提供專案的識別資訊。專案 ID 和專案編號可用來識別專案。

  1. 前往 Google Cloud 控制台的「Welcome」(歡迎) 頁面。

    前往「歡迎」

  2. 在頁面頂端的專案選擇工具中選取專案。

    專案名稱、專案編號和專案 ID 會顯示在「歡迎」標題下方。

取得現有專案

您可以使用 Google Cloud CLI 或 projects.get() 方法取得現有專案。

如果您不是專案擁有者,則必須具備「瀏覽器」角色 (roles/browser) 包含的權限。

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 如要取得專案的中繼資料,請使用 gcloud projects describe 指令:

    gcloud projects describe PROJECT_ID
    

    PROJECT_ID 替換為專案 ID。

API

要求:

GET https://cloudresourcemanager.googleapis.com/v3/projects/<var>PROJECT_ID</var>

PROJECT_ID 替換為專案 ID。

回應:

{
    "projectNumber": "464036093014",
    "projectId": "our-project-123",
    "lifecycleState": "ACTIVE",
    "name": "my project",
    "labels": {
        "mylabel": "prod"
    },
    "createTime": "2016-01-07T21:59:43.314Z"
}

可列出資源下的所有專案

如要列出資源的所有直接子項專案,請使用 v3 projects.list 方法,並在查詢中指定父項資源:

要求:

GET https://cloudresourcemanager.googleapis.com/v3/projects

{
    "parent": "folders/662951040570"
}

回應:

{
    "projects": [
    {
        "name": "projects/951040570662",
        "parent": "folders/662951040570",
        "projectId": "tokyo-rain-123",
        "state": "ACTIVE",
        "displayName": "Tokyo Rain"
        "createTime": "2013-11-13T20:31:53.308Z"
        "updateTime": "2013-11-13T20:31:53.308Z"
        "etag": "BwWUlZ6XEfY="
    }
    ]
}

搜尋專案

如要搜尋符合指定查詢的專案,請使用 gcloud alpha resource-manager projects search,並在 --query 標記中傳遞查詢。搜尋範圍是使用者具有 projects.get 權限的所有專案。

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 如要取得所有專案的清單,請使用 gcloud alpha projects search 指令:

    gcloud alpha projects search --query="displayName=rek*"
    <table output showing the projects with display names starting from rek eg. rekey-project-2, rekha-project>
    
    gcloud alpha projects search --query="state:DELETE_REQUESTED"
    <table output showing the projects for which delete has been requested>
    

API

您可以使用 projects.search 方法和查詢字串,傳回符合篩選條件的特定專案資源。結果只會包含您已獲授 resourcemanager.projects.get 權限的專案。

以下程式碼片段會傳回顯示名稱為「Tokyo Rain」的專案資源:

要求:

GET https://cloudresourcemanager.googleapis.com/v3/projects:search?query=displayName%3ATokyo%2BRain

回應:

{
  "projects": [
    {
      "name": "projects/951040570662",
      "parent": "folders/662951040570",
      "projectId": "tokyo-rain-123",
      "state": "ACTIVE",
      "displayName": "Tokyo Rain",
      "createTime": "2013-11-13T20:31:53.308Z",
      "updateTime": "2013-11-13T20:31:53.308Z",
      "etag": "BwWUlZ6XEfY="
    }
  ]
}

以下程式碼片段會傳回具有紅色標籤的所有專案資源:

要求:

GET https://cloudresourcemanager.googleapis.com/v3/projects:search?query=labels.color%3Ared

回應:

{
  "projects": [
    {
      "name": "projects/951054970012",
      "parent": "folders/662951040570",
      "projectId": "Osaka-rain-234",
      "state": "ACTIVE",
      "displayName": "Osaka Rain",
      "createTime": "2013-11-13T20:31:53.308Z",
      "updateTime": "2013-11-13T20:31:53.308Z",
      "etag": "BwWUlZ6XEfY=",
      "labels": {
        "color": "red"
      }
    }
  ]
}

如果您在要求主體中指定了 parent.typeparent.id 欄位,則會在父項執行 resourcemanager.projects.list 權限檢查。如果使用者擁有此權限,則在套用其餘的篩選條件後,會傳回父項下的所有專案。

如果使用者缺少此權限,則在套用其餘的篩選條件後,會傳回使用者具有 resourcemanager.projects.get 權限的所有專案。

如未指定篩選條件,呼叫會傳回使用者具有 resourcemanager.projects.get 權限的專案。

更新專案

您可以使用 Google Cloud 控制台或 projects.patch() 方法更新專案。

可更新的欄位只有專案名稱和標籤。 如要進一步瞭解如何更新專案,請參閱專案 API 參考頁面

如要在資源階層結構中移動專案,請按這裡瞭解如何移動專案。如要將專案從一個機構資源遷移至另一個機構資源,請參閱「遷移專案」。

主控台

如要 Google Cloud 透過控制台更新專案的名稱或標籤,請執行下列操作:

  1. 前往 Google Cloud 控制台的「IAM & Admin Settings」(IAM 與管理設定) 頁面。

    前往「IAM & Admin Settings」(IAM 與管理員設定)

    其餘步驟會顯示在 Google Cloud 控制台。

  2. 按一下畫面頂端的專案選取下拉式清單。
  3. 在顯示的「Select from」(可用的選項) 視窗中,點選機構下拉式清單,然後選取您的機構。如果您是免費試用的使用者,請跳過此步驟,因為畫面不會顯示機構清單。
  4. 從顯示的清單中選取您的專案。
  5. 如要變更專案名稱,編輯「Project name」(專案名稱),然後按一下「Save」(儲存)。
  6. 如要變更標籤,請按一下左側導覽面板中的「Labels」(標籤)

    進一步瞭解如何使用標籤

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 如要更新專案的名稱或標籤,請使用 gcloud alpha projects update 指令:

    gcloud alpha projects update PROJECT_ID \
        --name=NAME \
        --update-labels=KEY=VALUE, ...
    

    其中:

    • PROJECT_ID 是要更新的專案 ID。

    • NAME 是您要指派給專案的新名稱。

    • KEY=VALUE, ... 是您要更新的標籤鍵/值組合清單。如果標籤已存在,系統會修改其值。如果不存在,系統會建立新標籤。

    如要進一步瞭解這個指令,以及可搭配使用的其他標記,請參閱 Google Cloud CLI SDK

API

如要更新專案,請按照下列步驟操作:

以下範例會將專案的顯示名稱更新為 myproject,並將 color 標籤設為 red

要求:

PATCH https://cloudresourcemanager.googleapis.com/v3/projects/PROJECT_NUMBER?updateMask=displayName,labels

其中 PROJECT_NUMBER 是要更新的專案數字 ID。

JSON 要求內文:

{
  "displayName": "myproject",
  "labels": {
    "color": "red"
  }
}

回應:

{
  "projects": [
    {
      "name": "projects/951054970012",
      "parent": "folders/662951040570",
      "projectId": "Osaka-rain-234",
      "state": "ACTIVE",
      "displayName": "myproject",
      "createTime": "2013-11-13T20:31:53.308Z",
      "updateTime": "2013-11-13T20:35:42.308Z",
      "etag": "BwWUlZ6XEfY=",
      "labels": {
        "color": "red"
      }
    }
  ]
}

關閉 (刪除) 專案

您可以使用 Google Cloud 控制台或 API 中的 projects.delete 方法關閉專案。專案的生命週期狀態必須為 ACTIVE,才能透過這種方式關閉。

這個方法會立即將專案標示為要刪除。系統會盡力將通知電子郵件傳送給發起刪除作業的使用者,以及重要聯絡人中列出的技術類別聯絡人;如果無法傳送通知,系統仍會將專案標示為要刪除。如果技術類別中沒有聯絡人,系統就不會通知備用聯絡人。

標示為要刪除的專案無法再使用。如果專案有相關聯的帳單帳戶,則該關聯會中斷,且不會在取消專案刪除作業後恢復。30 天後,系統就會徹底刪除專案。在完全刪除前,專案可能仍會顯示,但無法使用。

如要在 30 天內停止專案刪除程序,請參閱還原專案的步驟

30 天之後就會刪除專案及其所有資源且無法還原。在徹底刪除前,該專案會計入您的專案配額。

為確保不會刪除任何重要專案,您可以啟用變更風險建議。當您嘗試刪除系統判定為重要的專案時,變更風險建議會產生警告。 Google Cloud

如果您設定了專案的帳單資訊,可能會等到目前的帳單週期結束且成功收取費用後,才能徹底刪除專案。您使用的服務數目和類型也會影響系統永久刪除專案的時間。如需資料保留和安全刪除的詳細資訊,請參閱 Google 如何保留所收集到的資料一文。

關閉專案

主控台

  1. 前往 Google Cloud 控制台的「IAM & Admin Settings」(IAM 與管理設定) 頁面。

    前往「IAM & Admin Settings」(IAM 與管理員設定)

    其餘步驟會顯示在 Google Cloud 控制台。

  2. 在「IAM & Admin Settings」(IAM 與管理設定) 頁面,選取要刪除的專案,然後按一下「Shut down」(關閉)

    只有在目前專案中具備 resourcemanager.projects.delete 權限的使用者,才會看到「Shut down」(關閉) 選項。

  3. 按一下「Shut down」(關閉)
  4. 輸入專案 ID,然後點選「Shut down anyway」(仍要關閉)

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 如要刪除專案,請使用 gcloud projects delete 指令:

    gcloud projects delete PROJECT_ID
    

    其中 PROJECT_ID 是要刪除的專案 ID。

API

以下程式碼片段可刪除指定的專案:

要求:

DELETE https://cloudresourcemanager.googleapis.com/v3/projects/my-project-123

解決專案刪除作業的相關問題

如果專案關閉程序失敗,請參閱「解決專案刪除問題」一文瞭解詳情。

還原專案

專案擁有者可在專案關閉後的 30 天內還原已刪除的專案。

注意事項

還原專案可將專案恢復至關閉前的狀態,但有以下例外情況:

  • 專案關閉時,專案的計費功能會停用,且還原專案時不會自動啟用計費功能。專案還原後,您必須手動重新連結 Cloud Billing 帳戶。您可能需要等待幾小時,才能將最近還原的專案連結至帳單帳戶。

  • 如果在 30 天內還原專案,即可還原多數資源。

  • 部分服務的還原作業會延遲,你最多可能需要等待 36 小時,服務才會還原。

  • 部分資源的刪除期限較短,如 Cloud Storage 或 Pub/Sub 資源。即使您在 30 天內還原專案,也未必能完全還原這些資源。

  • 有些服務可能需要手動重新啟動。詳情請參閱「重新啟動 Google Cloud 服務」。

您必須具備要還原專案的 resourcemanager.projects.undelete 權限。如要還原專案:

主控台

如要在 Google Cloud 控制台中查看專案,您必須具備下列權限:

  • resourcemanager.projects.list
  • resourcemanager.folders.list
  • resourcemanager.projects.get
  1. 前往 Google Cloud 控制台的「Manage resources」(管理資源) 頁面。

    前往「管理資源」頁面

  2. 在頁面頂端的專案選擇工具中,選取您的機構資源。

  3. 在機構資源、資料夾和專案清單下方,點選「待刪除的資源」

  4. 勾選要還原的專案,然後點選「還原」。在隨即顯示的對話方塊中,確認要還原的專案。

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 如要還原專案,請使用 gcloud projects undelete 指令:

    gcloud projects undelete PROJECT_ID
    

    PROJECT_ID 是要還原的專案 ID 或專案編號。

API

以下程式碼片段可還原指定的專案:

要求:

POST https://cloudresourcemanager.googleapis.com/v3/projects/my-project-123:undelete