> ## 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 table granularity 1ms remediation

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the misconfiguration of Bigtable Cluster Tables should have timestamp granularity set to 1ms in GCP using GCP console, follow these steps:

        1. Open the GCP console and navigate to the Cloud Bigtable section.

        2. Select the Bigtable instance that you want to remediate.

        3. In the left navigation pane, click on the "Tables" option.

        4. Select the table that you want to remediate and click on the "Edit" button.

        5. Scroll down to the "Column families" section and click on the column family that contains the timestamp column.

        6. In the "Column family" settings, set the "Timestamp granularity" to "Milliseconds".

        7. Click on the "Save" button to apply the changes.

        8. Repeat steps 4-7 for all the tables in the Bigtable instance that have timestamp columns.

        By following these steps, you will remediate the misconfiguration of Bigtable Cluster Tables should have timestamp granularity set to 1ms in GCP using GCP console.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration of Bigtable Cluster Tables having timestamp granularity set to 1ms in GCP using GCP CLI, follow these steps:

        1. Open the terminal and ensure that you have the latest version of the Google Cloud SDK installed.

        2. Authenticate yourself with the GCP CLI by running the following command:

        ```
        gcloud auth login
        ```

        3. Set the default project for the CLI by running the following command:

        ```
        gcloud config set project PROJECT_ID
        ```

        Replace `PROJECT_ID` with the ID of the project where your Bigtable Cluster is located.

        4. Run the following command to update the timestamp granularity of your Bigtable Cluster:

        ```
        gcloud bigtable clusters update CLUSTER_NAME --cluster-id=CLUSTER_ID --instance=INSTANCE_NAME --timestamp-granularity=ms
        ```

        Replace `CLUSTER_NAME`, `CLUSTER_ID`, and `INSTANCE_NAME` with the respective names of your Bigtable Cluster, Cluster ID, and Instance.

        5. Verify that the timestamp granularity has been set to 1ms by running the following command:

        ```
        gcloud bigtable clusters describe CLUSTER_NAME --cluster-id=CLUSTER_ID --instance=INSTANCE_NAME
        ```

        This command will display the details of your Bigtable Cluster, including the timestamp granularity.

        By following these steps, you can remediate the misconfiguration of Bigtable Cluster Tables having timestamp granularity set to 1ms in GCP using GCP CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the Bigtable Cluster Tables Timestamp Granularity issue in GCP using Python, you can follow these steps:

        1. Install the `google-cloud-bigtable` library using pip:

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

        2. Import the required libraries:

        ```python theme={null}
        from google.cloud import bigtable
        from google.cloud.bigtable import column_family
        ```

        3. Create a `bigtable.Client` object and a `bigtable.Table` object:

        ```python theme={null}
        client = bigtable.Client(project=<project_id>, admin=True)
        table = client.table('<instance_id>', '<table_id>')
        ```

        4. Get the column family and update the timestamp granularity:

        ```python theme={null}
        column_family_id = '<column_family_id>'
        column_family = column_family.ColumnFamily(column_granularity_millis=1)
        table.column_family(column_family_id).modify_column_family(column_family)
        ```

        5. Confirm that the column family has been updated:

        ```python theme={null}
        column_families = table.list_column_families()
        for column_family_id, column_family in column_families.items():
            print('Column Family:', column_family_id)
            print('Timestamp Granularity:', column_family.column_granularity_millis)
        ```

        This should remediate the Bigtable Cluster Tables Timestamp Granularity issue in GCP using Python.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "google_bigtable_instance" "THIS_INSTANCE" {
          name         = "BT_INSTANCE_NAME"          # replace with your instance ID
          display_name = "BT_INSTANCE_DISPLAY_NAME"  # replace with your display name
          cluster {
            cluster_id   = "BT_CLUSTER_ID"           # replace with your cluster ID
            zone         = "BT_CLUSTER_ZONE"         # replace with your zone, e.g. us-central1-b
            num_nodes    = 1
            storage_type = "SSD"
          }
        }

        resource "google_bigtable_table" "THIS_TABLE" {
          name          = "BT_TABLE_NAME"            # replace with your table ID
          instance_name = google_bigtable_instance.THIS_INSTANCE.name

          # This is the setting the check requires: 1ms timestamp granularity
          granularity = "MILLIS"
        }
        ```

        Changing `granularity` on an existing `google_bigtable_table` forces replacement of the table (the underlying API treats this as immutable), which will delete and recreate the table and its data; plan and migrate data accordingly before applying.

        To verify, `terraform plan` should show a `~` or `+/-` change on the `google_bigtable_table` resource where `granularity` is set to `"MILLIS"` (or a new table created with that value if it was previously unmanaged).
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
