

# Tear down a CA for AWS IAM for agents and workloads

Tear down a certificate authority (CA) for AWS IAM for agents and workloads in a fixed order. First, detach the CA from the workload identity provider in IAM, and confirm that the CA has no associations. Next, delete each replica in its own Region, and delete the primary CA last. The following procedure uses the AWS CLI and the example Regions from [Set up a CA for AWS IAM for agents and workloads (AWS CLI)](PcaWorkloadIdentity-get-started.md).

**To tear down a CA for AWS IAM for agents and workloads**

1. 
**Important**  
Don't delete the CA's signer while certificates that the CA issued are still in use. Deleting it removes the CA from the trust bundle at once, and those certificates stop verifying. After a rotation, don't disable the X.509 outbound signer to remove the old CA. Disabling it also stops the new CA.

   In IAM, detach the CA from the workload identity provider:
   + If the CA is the provider's only CA, disable the X.509 outbound signer.
   + If you rotated the provider to a new CA, leave the signer as it is. The old CA stops signing when the new CA starts.

   Wait until the status of the CA's signer is `INACTIVE`, and then delete the signer.

   For the signer statuses and the IAM commands, see [Agent and workload identity](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) in the *IAM User Guide*.

   When you delete the signer, IAM removes the association between the CA and the provider. Before you continue, confirm that the CA has no associations. In the console, the **Associations** tab of the CA details page is empty. With the API, [ListCertificateAuthorityAssociations](https://docs.aws.amazon.com/privateca/latest/APIReference/API_ListCertificateAuthorityAssociations.html) returns no associations. For the permission that the identity needs to detach the CA, see [Prerequisites](PcaWorkloadIdentity-get-started.md#workload-identity-prerequisites).

1. Delete each replica in its own Region. A CA with the status `ACTIVE` must be `DISABLED` before you can delete it. First, disable the replica with the [update-certificate-authority](https://docs.aws.amazon.com/cli/latest/reference/acm-pca/update-certificate-authority.html) command in the replica's Region.

   ```
   $ aws acm-pca update-certificate-authority \
       --region us-west-2 \
       --certificate-authority-arn arn:aws:acm-pca:us-west-2:{{123456789012}}:certificate-authority/{{a1b2c3d4-5678-90ab-cdef-EXAMPLE11111}} \
       --status DISABLED
   ```

   Then delete the replica with the [delete-certificate-authority](https://docs.aws.amazon.com/cli/latest/reference/acm-pca/delete-certificate-authority.html) command. Don't pass `--permanent-deletion-time-in-days` for a replica.

   ```
   $ aws acm-pca delete-certificate-authority \
       --region us-west-2 \
       --certificate-authority-arn arn:aws:acm-pca:us-west-2:{{123456789012}}:certificate-authority/{{a1b2c3d4-5678-90ab-cdef-EXAMPLE11111}}
   ```

   Issuance in that Region stops immediately, and the replica disappears from the output of [list-certificate-authority-replicas](https://docs.aws.amazon.com/cli/latest/reference/acm-pca/list-certificate-authority-replicas.html). Repeat this step for every replica, for example in `eu-west-1`.

1. Delete the primary CA last, in the primary Region, after every replica is `DELETED` or `FAILED`. If the status of the primary CA is still `ACTIVE`, disable it first.

   ```
   $ aws acm-pca update-certificate-authority \
       --region us-east-1 \
       --certificate-authority-arn arn:aws:acm-pca:us-east-1:{{123456789012}}:certificate-authority/{{a1b2c3d4-5678-90ab-cdef-EXAMPLE11111}} \
       --status DISABLED
   ```

   Then delete the primary CA.

   ```
   $ aws acm-pca delete-certificate-authority \
       --region us-east-1 \
       --certificate-authority-arn arn:aws:acm-pca:us-east-1:{{123456789012}}:certificate-authority/{{a1b2c3d4-5678-90ab-cdef-EXAMPLE11111}} \
       --permanent-deletion-time-in-days 7
   ```

   The primary CA keeps the normal restoration period of 7-30 days. During that period, the [restore-certificate-authority](https://docs.aws.amazon.com/cli/latest/reference/acm-pca/restore-certificate-authority.html) command restores the primary CA only. You can't restore a deleted replica. To get it back, create it again with [create-certificate-authority-replica](https://docs.aws.amazon.com/cli/latest/reference/acm-pca/create-certificate-authority-replica.html).

For a Java example, see [Delete a CA for AWS IAM for agents and workloads](JavaApiWI-DeleteCA.md). For more information about deleting and restoring a CA, see [Delete your private CA](PCADeleteCA.md).