Cloud KMS API または Google Cloud CLI を使用して Cloud Key Management Service リソースを参照する場合は、リソース ID を使用します。たとえば、鍵リングのリソース ID を使用して、その鍵リングに Identity and Access Management(IAM)ロールを付与できます。このトピックでは、鍵リング、鍵、鍵バージョンの ID を取得する方法を示します。
鍵には、0 個以上の鍵バージョンが含まれています。鍵バージョンのリソース ID は、鍵 ID とスラッシュ(/)、およびバージョン ID です。鍵のすべてのバージョンを一覧表示するには、鍵の名前をクリックします。バージョンの [その他] アイコンをクリックし、[リソース名をコピー] をクリックします。
gcloud
指定した鍵リングのすべての鍵を一覧表示します。
gcloud kms keys list --keyring KEY_RING --location LOCATION
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-04-21 UTC。"],[],[],null,["# Getting a Cloud KMS resource ID\n\nWhen you refer to a Cloud Key Management Service resource using the Cloud KMS API or Google Cloud CLI, you use the resource ID. For example, you can use the resource\nID of a key ring to grant an\n[Identity and Access Management (IAM) role](/kms/docs/reference/permissions-and-roles) on\nthat key ring. This topic shows how to get the ID for a key ring, a key, and a\nkey version.\n\nGetting the resource ID for a key ring\n--------------------------------------\n\n### Console\n\n1. Go to the **Key Management** page in the Google Cloud console.\n\n [Go to\n the Key Management page](https://console.cloud.google.com/security/kms)\n2. Click **More** *more_vert*\n for the key ring.\n\n3. Click **Copy resource name**. The resource ID for the key ring is copied to your\n clipboard.\n\n### gcloud\n\nList all key rings in a location: \n\n```\ngcloud kms keyrings list --location LOCATION\n```\n\nThe **Name** column of the output includes the resource ID for each key ring.\nFor example: \n\n```\nprojects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING\n```\n\nGetting the ID for a key and version\n------------------------------------\n\n### Console\n\n1. Go to the **Key Management** page in the Google Cloud console.\n\n [Go to\n the Key Management page](https://console.cloud.google.com/security/kms)\n2. Select the key ring that contains the key.\n\n3. For the key whose resource ID you are retrieving, click\n **More** *more_vert*.\n\n4. Click **Copy resource name**. The resource ID for the key is copied to your\n clipboard. Its format is similar to the following:\n\n ```\n projects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME\n ```\n5. A key contains zero or more key versions. The resource ID for a key\n version is the key ID, plus a slash (`/`), plus the version ID. To list\n all versions for a key, click the key's name. Click the **More** icon for\n the version, and click **Copy resource name**.\n\n### gcloud\n\nList all keys on a given key ring: \n\n```\ngcloud kms keys list --keyring KEY_RING --location LOCATION\n```\n\nThe **Name** column of the output includes the resource ID for each key. For\nexample: \n\n```\nprojects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME\n```\n\nA key has zero or more key versions. The resource ID for a key version is\nthe key ID, plus a slash (`/`), plus the version ID. To list all versions\nfor a key: \n\n```\ngcloud kms keys versions list --location LOCATION --keyring KEY_RING --key KEY_NAME\n```\n\nThe **Name** column of the output includes the resource ID for each key\nversion. For example: \n\n```\nprojects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME/2\n```\n\nWhat's next\n-----------\n\n- Learn more about [permissions and roles](/kms/docs/reference/permissions-and-roles) in Cloud KMS.\n- [Manage access to Cloud KMS resources](/kms/docs/iam).\n- [Rotate a key](/kms/docs/rotate-key)."]]