管理及刪除資源
本頁說明 Config Connector 如何管理現有資源,以及如何處理刪除資源。
使用 Config Connector 定義資源時,會發生下列其中一個動作:
- 如果資源不存在,Config Connector 會建立資源。如需建立新資源的範例,請參閱「開始使用」一文。
- 如果已有名稱相同的資源,Config Connector 就會取得該資源並開始管理。Config Connector 會在機構、專案或資料夾中檢查名稱。 本頁面詳細說明 Config Connector 如何取得、管理及處理資源刪除作業。
您也可以使用 resourceID 欄位管理資源。部分資源只能使用 resourceID 欄位取得。部分資源只能建立為新資源,無法取得。詳情請參閱「使用 resourceID 欄位管理資源」。
取得現有資源
本節說明如何使用 Config Connector 取得現有資源,並以 BigQuery 資源為例。
事前準備
- 啟用 BigQuery API。
- 確認您有權存取 bq指令列工具。如果沒有bq,請使用 Cloud Shell 或透過 gcloud CLI 安裝。
取得 BigQuery 資料集
當資訊清單中的值與資源名稱相符時,Config Connector 會取得或控管資源。如果資源沒有名稱 (例如專案 ID),系統會使用資源的 ID。
建立空白的 BigQuery 資料集,然後使用 Config Connector 取得該資料集,即可瞭解 Config Connector 如何處理現有資源。
- 建立名為 - bigquerydatasetsample的 BigQuery 資料集,並使用- bq。- bq --location=US mk \--dataset \ --default_table_expiration 3600 \ --description description \ PROJECT_ID:bigquerydatasetsample
- 將下列內容複製到名為 - bq-sample.yaml的檔案。- apiVersion: bigquery.cnrm.cloud.google.com/v1beta1 kind: BigQueryDataset metadata: name: bigquerydatasetsample spec: defaultTableExpirationMs: 3600000 description: "BigQuery Dataset Sample" friendlyName: bigquerydataset-sample location: US
- 將 YAML 套用至叢集。 - kubectl apply --namespace CC_NAMESPACE -f bq-sample.yaml - 將 - CC_NAMESPACE替換為 Config Connector 管理資源的命名空間。
- 使用 - kubectl describe查看資料集詳細資料。- kubectl describe --namespace CC_NAMESPACE bigquerydataset bigquerydatasetsample - 將 - CC_NAMESPACE替換為 Config Connector 管理資源的命名空間。- kubectl describe的輸出內容包含資源狀態和擁有權的中繼資料。
刪除資料集
根據預設,Config Connector 取得並管理資源後,從叢集刪除物件就會刪除資源。如要保留資料集,請設定資源的 deletion-policy。
舉例來說,刪除取得 bigquerydataset-sample 的資訊清單會從 BigQuery 刪除資料集。
- 你可以使用 - kubectl delete刪除- bigquerydataset-sample資料集。- kubectl delete --namespace CC_NAMESPACE -f bq-sample.yaml - 將 - CC_NAMESPACE替換為 Config Connector 管理資源的命名空間。- kubectl的輸出內容會確認刪除:- bigquerydataset.bigquery.cnrm.cloud.google.com "bigquerydatasetsample" deleted
- 使用 - bq確認資料集已不存在。- bq show PROJECT_ID:bigquerydatasetsample - 指令輸出內容包含 - Not Found。
刪除後保留資源
...
metadata:
  annotations:
    cnrm.cloud.google.com/deletion-policy: abandon
...
舉例來說,先前所述 BigQuery 資料集的 YAML (包括 abandon 刪除政策) 如下:
apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
kind: BigQueryDataset
metadata:
  name: bigquerydatasetsample
  annotations:
    cnrm.cloud.google.com/deletion-policy: abandon
spec:
  defaultTableExpirationMs: 3600000
  description: "BigQuery Dataset Sample"
  friendlyName: bigquerydataset-sample
  location: US
有獲取限制的資源
部分資源無法按照前一節的操作說明取得。本節將詳細說明部分資源的獲取限制。
具有服務產生資源 ID 的資源
您只能使用 resourceID 欄位,取得具有服務產生的資源 ID 的資源。 Google Cloud 
下列 Config Connector 資源對應至具有服務產生資源 ID 的資源: Google Cloud
- AccessContextManagerAccessPolicy
- ApigeeOrganization
- BillingBudgetsBudget
- CloudIdentityGroup
- CloudIdentityMembership
- ComputeFirewallPolicy
- DLPDeidentifyTemplate
- DLPInspectTemplate
- DLPJobTrigger
- DLPStoredInfoType
- Folder
- IAPBrand
- IAPIdentityAwareProxyClient
- IdentityPlatformTenant
- MonitoringAlertPolicy
- MonitoringGroup
- MonitoringNotificationChannel
- MonitoringUptimeCheckConfig
- RecaptchaEnterpriseKey
- ResourceManagerLien
- SQLSSLCert
- SecretManagerSecretVersion
- StorageNotification
- StorageTransferJob
- VertexAIDataset
- VertexAIIndex
如要瞭解如何使用 resourceID 欄位,請參閱「使用 resourceID 欄位管理資源」。
無法取得的資源
下列 Config Connector 資源不支援取得現有 Google Cloud 資源:
- DataflowFlexTemplateJob
- FirestoreIndex
- IAMServiceAccountKey
後續步驟
- 瞭解 Config Connector 如何使用 Kubernetes 建構項目建立資源模型 Google Cloud 。
- 請參閱 Google Cloud 資源,瞭解 Config Connector 可管理的資源。
- 如需 Config Connector 的其他使用範例,請參閱 GitHub 存放區。
- 瞭解 Kubernetes 如何處理物件的宣告式設定。