Delete parameter versions

This page describes how to delete a parameter version.

Consider deleting a parameter version in the following scenarios:

  • The version is obsolete and is no longer needed.
  • The version contains sensitive information that needs to be permanently removed.
  • You want to simplify the management of parameter versions by deleting old and unused versions.

Required roles

To get the permissions that you need to delete a parameter version, ask your administrator to grant you the Parameter Manager Parameter Version Manager (roles/parametermanager.parameterVersionManager) IAM role on the project, folder, or organization. For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

Delete a parameter version

To delete a parameter version, use one of the following methods:

Global parameters

Console

  1. In the Google Cloud console, go to the Secret Manager page.

    Go to Secret Manager

  2. Click Parameter Manager to go to the Parameter Manager page. You'll see the list of parameters for that project.

  3. Click the parameter name to access its versions. The parameter details page opens. You can see all the versions belonging to the selected parameter in the Versions tab.

  4. Select the parameter version that you want to delete.

  5. Click the Actions menu associated with that version, and then click Delete.

  6. In the confirmation dialog that appears, enter the parameter ID to confirm, and then click click Delete.

gcloud

Before using any of the command data below, make the following replacements:

  • PARAMETER_VERSION_ID: the ID of the parameter version
  • PARAMETER_ID: the name of the parameter

Execute the following command:

Linux, macOS, or Cloud Shell

gcloud parametermanager parameters versions delete PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=global

Windows (PowerShell)

gcloud parametermanager parameters versions delete PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=global

Windows (cmd.exe)

gcloud parametermanager parameters versions delete PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=global

You should receive a response similar to the following:

You are about to delete parameterVersion [appconfigv1]

Do you want to continue (Y/n)?  y

Deleted parameterVersion [appconfigv1].

REST

Before using any of the request data, make the following replacements:

  • PROJECT_ID: the Google Cloud project ID
  • PARAMETER_ID: the name of the parameter
  • PARAMETER_VERSION_ID: the ID of the parameter version

HTTP method and URL:

DELETE https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID

Request JSON body:

{}

To send your request, choose one of these options:

curl

Save the request body in a file named request.json, and execute the following command:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID"

PowerShell

Save the request body in a file named request.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{}

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.

def delete_param_version(project_id: str, parameter_id: str, version_id: str) -> None:
    """
    Deletes a specific version of an existing parameter in the global location
    of the specified project using the Google Cloud Parameter Manager SDK.

    Args:
        project_id (str): The ID of the project where the parameter is located.
        parameter_id (str): The ID of the parameter for
        which the version is to be deleted.
        version_id (str): The ID of the version to be deleted.

    Returns:
        None

    Example:
        delete_param_version(
            "my-project",
            "my-global-parameter",
            "v1"
        )
    """
    # Import the necessary library for Google Cloud Parameter Manager.
    from google.cloud import parametermanager_v1

    # Create the Parameter Manager client.
    client = parametermanager_v1.ParameterManagerClient()

    # Build the resource name of the parameter version.
    name = client.parameter_version_path(project_id, "global", parameter_id, version_id)

    # Define the request to delete the parameter version.
    request = parametermanager_v1.DeleteParameterVersionRequest(name=name)

    # Delete the parameter version.
    client.delete_parameter_version(request=request)

    # Print a confirmation message.
    print(f"Deleted parameter version: {name}")

Regional parameters

Console

  1. In the Google Cloud console, go to the Secret Manager page.

    Go to Secret Manager

  2. Click Parameter Manager to go to the Parameter Manager page. You'll see the list of parameters for that project.

  3. Click the parameter name to access its versions. The parameter details page opens. You can see all the versions belonging to the selected parameter in the Versions tab.

  4. Select the parameter version that you want to delete.

  5. Click the Actions menu associated with that version, and then click Delete.

  6. In the confirmation dialog that appears, enter the parameter ID to confirm, and then click click Delete.

gcloud

Before using any of the command data below, make the following replacements:

  • PARAMETER_VERSION_ID: the ID of the parameter version
  • PARAMETER_ID: the name of the parameter
  • LOCATION: the Google Cloud location of the parameter

Execute the following command:

Linux, macOS, or Cloud Shell

gcloud parametermanager parameters versions delete PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=LOCATION

Windows (PowerShell)

gcloud parametermanager parameters versions delete PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=LOCATION

Windows (cmd.exe)

gcloud parametermanager parameters versions delete PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=LOCATION

You should receive a response similar to the following:

You are about to delete parameterVersion [appconfigv1]

Do you want to continue (Y/n)?  y

Deleted parameterVersion [appconfigv1].

REST

Before using any of the request data, make the following replacements:

  • LOCATION: the Google Cloud location of the parameter
  • PROJECT_ID: the Google Cloud project ID
  • PARAMETER_ID: the name of the parameter
  • PARAMETER_VERSION_ID: the ID of the parameter version

HTTP method and URL:

DELETE https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID

Request JSON body:

{}

To send your request, choose one of these options:

curl

Save the request body in a file named request.json, and execute the following command:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID"

PowerShell

Save the request body in a file named request.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{}

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.

def delete_regional_param_version(
    project_id: str, location_id: str, parameter_id: str, version_id: str
) -> None:
    """
    Deletes a specific version of an existing parameter in the specified region
    of the specified project using the Google Cloud Parameter Manager SDK.

    Args:
        project_id (str): The ID of the project where the parameter is located.
        location_id (str): The ID of the region where the parameter is located.
        parameter_id (str): The ID of the parameter for
        which the version is to be deleted.
        version_id (str): The ID of the version to be deleted.

    Returns:
        None

    Example:
        delete_regional_param_version(
            "my-project",
            "us-central1",
            "my-regional-parameter",
            "v1"
        )
    """
    # Import the necessary library for Google Cloud Parameter Manager.
    from google.cloud import parametermanager_v1

    # Create the Parameter Manager client with the regional endpoint.
    api_endpoint = f"parametermanager.{location_id}.rep.googleapis.com"
    client = parametermanager_v1.ParameterManagerClient(
        client_options={"api_endpoint": api_endpoint}
    )

    # Build the resource name of the parameter version.
    name = client.parameter_version_path(
        project_id, location_id, parameter_id, version_id
    )

    # Define the request to delete the parameter version.
    request = parametermanager_v1.DeleteParameterVersionRequest(name=name)

    # Delete the parameter version.
    client.delete_parameter_version(request=request)

    # Print a confirmation message.
    print(f"Deleted regional parameter version: {name}")

What's next