> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Bigtable cluster backup encrypted remediation

### Triage and Remediation

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the issue of unencrypted Bigtable Cluster backups in GCP, you can follow these steps:

        1. Open the Google Cloud Console and navigate to the Bigtable Cluster backups page.

        2. Select the Bigtable cluster for which you want to enable backup encryption.

        3. Click on the "Edit" button located at the top of the page.

        4. Scroll down to the "Backup Encryption" section and select "Enabled".

        5. Choose the key version you want to use for encryption and click on "Save".

        6. Once the backup encryption is enabled, all new backups for the selected Bigtable cluster will be encrypted using the specified key version.

        7. You can also verify the encryption status of existing backups by checking the "Encryption" column in the backups table.

        It is important to note that enabling backup encryption may increase the cost of backups due to the additional resources required for encryption. However, it is a necessary step to ensure the security of your data.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration of unencrypted backups for a Bigtable cluster in GCP, you can follow the below steps:

        1. Open the Cloud Shell in the GCP Console.

        2. Run the following command to list all the Bigtable instances in the current project:

           ```
           gcloud bigtable instances list
           ```

        3. Identify the instance for which you want to enable encrypted backups.

        4. Run the following command to enable encryption for backups for the identified instance:

           ```
           gcloud beta bigtable instances update [INSTANCE_ID] --backup-encryption google-default-kms-key
           ```

           Replace \[INSTANCE\_ID] with the actual ID of the Bigtable instance.

        5. The above command enables encryption for backups using the default Google Cloud KMS key. If you want to use a different KMS key, replace `google-default-kms-key` with the resource ID of the desired KMS key.

        6. Once the command executes successfully, encrypted backups will be enabled for the specified Bigtable instance.

        Note: The above command enables encryption for future backups only. To encrypt existing backups, you need to create a new backup and delete the old unencrypted backup.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the Bigtable Cluster Backups Should Be Encrypted misconfiguration in GCP using python, follow these steps:

        1. Open the Cloud Shell in your GCP console.

        2. Install the `google-cloud-bigtable` library using the following command:

        ```
        pip install google-cloud-bigtable
        ```

        3. Create a Python script to enable encryption for Bigtable cluster backups. Here is an example script:

        ```python theme={null}
        from google.cloud import bigtable
        from google.cloud.bigtable import enums
        from google.cloud.bigtable.admin_v2 import enums as admin_enums
        from google.cloud.bigtable.admin_v2 import BigtableTableAdminClient
        from google.cloud.bigtable.admin_v2.types import CreateBackupRequest, Backup, EncryptionInfo

        # Set the project ID, instance ID, and cluster ID for your Bigtable cluster
        project_id = 'your-project-id'
        instance_id = 'your-instance-id'
        cluster_id = 'your-cluster-id'

        # Set the ID and encryption type for your backup
        backup_id = 'your-backup-id'
        encryption_type = enums.EncryptionInfo.EncryptionType.GOOGLE_DEFAULT_ENCRYPTION

        # Create a client to interact with the Bigtable table admin API
        client = BigtableTableAdminClient()

        # Get the cluster object for your Bigtable cluster
        cluster = client.get_cluster(request={"name": f"projects/{project_id}/instances/{instance_id}/clusters/{cluster_id}"})

        # Create the encryption info object for your backup
        encryption_info = EncryptionInfo(encryption_type=encryption_type)

        # Create the backup object with encryption info
        backup = Backup(
            encryption_info=encryption_info
        )

        # Create the backup request with backup ID and cluster name
        backup_request = CreateBackupRequest(
            parent=cluster.name,
            backup_id=backup_id,
            backup=backup
        )

        # Create the backup
        client.create_backup(request=backup_request)

        # Print confirmation message
        print(f"Backup {backup_id} created with encryption enabled.")
        ```

        4. Replace the placeholders in the script with your own project ID, instance ID, cluster ID, backup ID, and encryption type.

        5. Run the script in the Cloud Shell using the following command:

        ```
        python script_name.py
        ```

        6. Verify that the backup was created with encryption enabled by checking the backup details in the GCP console.

        By following these steps, you have successfully remediated the Bigtable Cluster Backups Should Be Encrypted misconfiguration in GCP using python.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "google_bigtable_backup" "BIGTABLE_BACKUP" {
          name          = "BACKUP_NAME"                 # e.g. "daily-backup-01"
          instance_name = "BIGTABLE_INSTANCE_NAME"      # e.g. "my-bt-instance"
          cluster       = "BIGTABLE_CLUSTER_NAME"       # e.g. "my-bt-cluster"
          table         = "BIGTABLE_TABLE_NAME"         # e.g. "my-table"

          # Set a customer-managed encryption key (CMEK) so the backup is encrypted.
          kms_key_name  = "KMS_KEY_RESOURCE_ID"         # e.g. "projects/PROJECT_ID/locations/LOCATION/keyRings/RING/cryptoKeys/KEY"

          expire_time   = "BACKUP_EXPIRE_TIMESTAMP"     # RFC3339, e.g. "2026-01-01T00:00:00Z"
        }
        ```

        `kms_key_name` is immutable for an existing backup; adding or changing it will force replacement of the `google_bigtable_backup` resource (destroy and recreate the backup), which is irreversible for the data in that backup.

        To verify, `terraform plan` should show the `google_bigtable_backup` resource either being created with `kms_key_name = "KMS_KEY_RESOURCE_ID"` or updated with a replacement where the only functional change is the addition (or change) of `kms_key_name`.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
