> [!CAUTION]
> You are currently viewing version 1.16 of the Apigee hybrid documentation. For more information, see [Supported versions](https://docs.cloud.google.com/apigee/docs/hybrid/supported-platforms.md.txt#supported-versions).

<button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">Version 1.16 </button>

- Supported versions:
- [v1.17 (latest)](https://docs.cloud.google.com/apigee/docs/hybrid/v1.17/environment-delete.md.txt)
- [v1.16](https://docs.cloud.google.com/apigee/docs/hybrid/v1.16/environment-delete.md.txt)
- [v1.15](https://docs.cloud.google.com/apigee/docs/hybrid/v1.15/environment-delete.md.txt)
- [v1.14](https://docs.cloud.google.com/apigee/docs/hybrid/v1.14/environment-delete.md.txt)
- [List of supported versions](https://docs.cloud.google.com/apigee/docs/hybrid/supported-platforms.md.txt#supported-versions)
- Unsupported versions:
- [v1.13](https://docs.cloud.google.com/apigee/docs/hybrid/v1.13/environment-delete.md.txt)
- [v1.12](https://docs.cloud.google.com/apigee/docs/hybrid/v1.12/environment-delete.md.txt)
- [v1.11](https://docs.cloud.google.com/apigee/docs/hybrid/v1.11/environment-delete.md.txt)
- [v1.10](https://docs.cloud.google.com/apigee/docs/hybrid/v1.10/environment-delete.md.txt)
- [v1.9](https://docs.cloud.google.com/apigee/docs/hybrid/v1.9/environment-delete.md.txt)
- [v1.8](https://docs.cloud.google.com/apigee/docs/hybrid/v1.8/environment-delete.md.txt)
- [v1.7](https://docs.cloud.google.com/apigee/docs/hybrid/v1.7/environment-delete.md.txt)
- [v1.6](https://docs.cloud.google.com/apigee/docs/hybrid/v1.6/environment-delete.md.txt)
- [v1.5](https://docs.cloud.google.com/apigee/docs/hybrid/v1.5/environment-delete.md.txt)
- [v1.4](https://docs.cloud.google.com/apigee/docs/hybrid/v1.4/environment-delete.md.txt)
- [v1.3](https://docs.cloud.google.com/apigee/docs/hybrid/v1.3/environment-delete.md.txt)
- [v1.2](https://docs.cloud.google.com/apigee/docs/hybrid/v1.2/environment-delete.md.txt)
- [v1.1](https://docs.cloud.google.com/apigee/docs/hybrid/v1.1/environment-delete.md.txt)


This topic explains how to delete environments in Apigee hybrid. See also
[About environments and environment groups](https://docs.cloud.google.com/apigee/docs/api-platform/fundamentals/environments-overview.md.txt).

## About environment deletion


Environment deletion is the reverse of
[environment creation](https://docs.cloud.google.com/apigee/docs/hybrid/v1.16/environment-create.md.txt) and includes the following tasks:

- Remove the environment's runtime components from your cluster and remove the environment from your overrides file.
- Delete the environment from the management plane using either the [Apigee UI](https://apigee.google.com) or the [Delete environments API](https://docs.cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/delete.md.txt).

> [!CAUTION]
> **Caution:** If you delete only the runtime components and don't delete the environment in the management plane, the environment still appears in the [Apigee UI](https://apigee.google.com) and in API responses. If you delete the environment in the management plane but don't remove its runtime components, those components stay in your cluster but are no longer usable.

## How to delete an environment

Assume that you have two environments, **test** and **prod**. In
your overrides file, the definitions might look something like this:

```
...
envs:
  - name: test
    serviceAccountPaths:
      synchronizer: "your_keypath/PROJECT_ID-apigee-synchronizer.json"
      runtime: "your_keypath/PROJECT_ID-apigee-runtime.json"
  - name: prod
    serviceAccountPaths:
      synchronizer: "your_keypath/PROJECT_ID-apigee-synchronizer.json"
      runtime: "your_keypath/PROJECT_ID-apigee-runtime.json"
...
```

> [!NOTE]
> **Note:** See:
>
> - [`envs[].name`](https://docs.cloud.google.com/apigee/docs/hybrid/v1.16/config-prop-ref.md.txt#envs-name)
> - [`envs[].serviceAccountPaths.synchronizer`](https://docs.cloud.google.com/apigee/docs/hybrid/v1.16/config-prop-ref.md.txt#envs-serviceaccountpaths-synchronizer)
> - [`envs[].serviceAccountPaths.runtime`](https://docs.cloud.google.com/apigee/docs/hybrid/v1.16/config-prop-ref.md.txt#envs-serviceaccountpaths-runtime)

To delete the **prod** environment, follow these steps:

1. Get your gcloud authentication credentials:

   ```
   TOKEN=$(gcloud auth print-access-token)
   ```
2. As a precaution, detach the environment from each environment group that it is attached to. This stops traffic from being routed to the environment before you remove its runtime components.
   1. List the attachments of the environment group and note the `name` (attachment ID) of the attachment whose `environment` is `prod`:

      ### No data residency

      ```
      curl -H "Authorization: Bearer $TOKEN" \
        "https://apigee.googleapis.com/v1/organizations/ORG_NAME/envgroups/ENV_GROUP/attachments"
      ```

      ### Data residency

      ```
      curl -H "Authorization: Bearer $TOKEN" \
        "https://CONTROL_PLANE_LOCATION-apigee.googleapis.com/v1/organizations/ORG_NAME/envgroups/ENV_GROUP/attachments"
      ```

      The output is similar to the following:

      ```
      {
        "environmentGroupAttachments": [
          {
            "name": "f6f2958f-a0a1-4260-b9e9-80eead82ff1d",
            "environment": "prod",
            "createdAt": "1789700385118",
            "environmentGroupId": "ENV_GROUP"
          }
        ]
      }
      ```
   2. Delete the attachment:

      ### No data residency

      ```
      curl -X DELETE -H "Authorization: Bearer $TOKEN" \
        "https://apigee.googleapis.com/v1/organizations/ORG_NAME/envgroups/ENV_GROUP/attachments/ATTACHMENT_ID"
      ```

      ### Data residency

      ```
      curl -X DELETE -H "Authorization: Bearer $TOKEN" \
        "https://CONTROL_PLANE_LOCATION-apigee.googleapis.com/v1/organizations/ORG_NAME/envgroups/ENV_GROUP/attachments/ATTACHMENT_ID"
      ```

   Where:
   - <var translate="no">ORG_NAME</var> is the name of your Apigee organization.
   - <var translate="no">ENV_GROUP</var> is the name of the environment group.
   - <var translate="no">ATTACHMENT_ID</var> is the attachment `name` returned in the previous step. This is a generated ID, not the environment name.
   - <var translate="no">CONTROL_PLANE_LOCATION</var> is the control plane location of your organization if you use [data residency](https://docs.cloud.google.com/apigee/docs/hybrid/v1.16/using-data-residency-with-apigee-hybrid.md.txt).

   Repeat these steps for each environment group that the environment is attached to.
3. Do a dry run to test removal of the runtime components:

   ```
   helm delete ENV_RELEASE_NAME -n APIGEE_NAMESPACE --dry-run
   ```
   - <var translate="no">ENV_RELEASE_NAME</var> is the name with which you previously installed the `apigee-env` chart for this environment. This is often the same as the environment name. To list the release names in your namespace, run `helm list -n APIGEE_NAMESPACE`.
   - <var translate="no">APIGEE_NAMESPACE</var> is the namespace where you installed Apigee hybrid, `apigee` by default.

   The `--dry-run` option simulates the uninstall without removing anything, and its output
   is the same as the output of the actual uninstall. Unlike `helm upgrade`,
   `helm delete` doesn't accept a value for `--dry-run` such as
   `--dry-run=server`. For example:

       helm delete prod -n apigee --dry-run
       release "prod" uninstalled

4. If the dry run is error-free, remove the runtime components:

   ```
   helm delete ENV_RELEASE_NAME -n APIGEE_NAMESPACE
   ```
5. Open your overrides file and remove the `prod` environment definition from `envs`, leaving only the **test** definition. For example:

   ```
   ...
   envs:
     - name: test
       serviceAccountPaths:
         synchronizer: "your_keypath/PROJECT_ID-apigee-synchronizer.json"
         runtime: "your_keypath/PROJECT_ID-apigee-runtime.json"
   ...
   ```

   > [!NOTE]
   > **Note:** Entries in `virtualhosts` are defined per environment group, not per environment, so you don't need to change them. Only remove a `virtualhosts` entry (and uninstall its `apigee-virtualhost` release) if you also delete the environment group.

6. Save the file.
7. Delete the environment from the management plane. You can use either the [Apigee UI](https://apigee.google.com) or the [Delete environments API](https://docs.cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/delete.md.txt).

   ### [Apigee UI](https://apigee.google.com)

   1. In the Google Cloud console, go to the
      **Apigee \> Management \> Environments** page.

      [Go to Environments](https://console.cloud.google.com/apigee/environments)
   2. Select the project of your Apigee organization.
   3. In the row of the `prod` environment, click **Actions \> Delete**.

   ### API

   No data residency:

   ```
   curl -X DELETE -H "Authorization: Bearer $TOKEN" \
     "https://apigee.googleapis.com/v1/organizations/ORG_NAME/environments/prod"
   ```

   Data residency:

   ```
   curl -X DELETE -H "Authorization: Bearer $TOKEN" \
     "https://CONTROL_PLANE_LOCATION-apigee.googleapis.com/v1/organizations/ORG_NAME/environments/prod"
   ```

   The call returns a long-running operation. Deletion can take a few minutes to
   complete.

   > [!NOTE]
   > **Note:** Deleting the environment in the management plane also removes any remaining environment group attachments for that environment.