This topic shows how to delete a secret and all of its versions.
To destroy only a secret version, see Destroy a secret version.
Required roles
Deleting a secret requires the Secret Manager Admin role
(roles/secretmanager.admin
) on the secret, project, folder, or organization.
Delete a secret
Console
-
Go to the Secret Manager page in the Google Cloud console.
-
On the Secret Manager page, in the Actions column for the secret, click View more
. -
In the menu, select Delete.
-
In the Delete secret dialog, enter the name of the secret.
-
Click the Delete secret button.
gcloud
To use Secret Manager on the command line, first Install or upgrade to version 378.0.0 or higher of the Google Cloud CLI. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
$ gcloud secrets delete secret-id
C#
To run this code, first set up a C# development environment and install the Secret Manager C# SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
Go
To run this code, first set up a Go development environment and install the Secret Manager Go SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
Java
To run this code, first set up a Java development environment and install the Secret Manager Java SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
Node.js
To run this code, first set up a Node.js development environment and install the Secret Manager Node.js SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
PHP
To run this code, first learn about using PHP on Google Cloud and install the Secret Manager PHP SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
Python
To run this code, first set up a Python development environment and install the Secret Manager Python SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
Ruby
To run this code, first set up a Ruby development environment and install the Secret Manager Ruby SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
API
These examples use curl to demonstrate using the API. You can generate access tokens with gcloud auth print-access-token. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
$ curl "https://secretmanager.googleapis.com/v1/projects/project-id/secrets/secret-id" \
--request "DELETE" \
--header "authorization: Bearer $(gcloud auth print-access-token)" \
--header "content-type: application/json"
What's next
- Learn how to set an expiration date for a secret.
- Learn how to manage access to secrets.