> ## 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 firestore index state valid remediation

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the "Cloud Firestore Index State Should Be READY or CREATING" misconfiguration for GCP using the GCP console, please follow these steps:

        1. Open the GCP console and select the project that contains the Firestore instance with the misconfigured index.

        2. Navigate to the Firestore instance that has the misconfigured index.

        3. Click on the "Indexes" tab in the Firestore console.

        4. Look for the index that has the status "ERROR". This index needs to be remediated.

        5. Click on the index that has the status "ERROR" to open the details page.

        6. On the details page, click on the "Edit" button.

        7. Review the index definition and make any necessary changes to ensure it is valid.

        8. Click on the "Save" button to save the changes.

        9. Wait for the index to be reprocessed. This may take some time depending on the size of your Firestore instance and the number of documents in it.

        10. Once the index is in the "READY" or "CREATING" state, the misconfiguration is remediated.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the "Cloud Firestore Index State Should Be READY or CREATING" misconfiguration for GCP using GCP CLI, you can follow the below steps:

        1. Open the Cloud Firestore console in GCP and navigate to the Indexes tab.

        2. Check the status of the index that is causing the misconfiguration. If the status is anything other than "READY" or "CREATING", it means the index is not in a valid state.

        3. To remediate this, you can use the GCP CLI command "gcloud firestore indexes delete" to delete the problematic index.

        4. After deleting the index, you can recreate it using the "gcloud firestore indexes create" command. This will create a new index with a valid state.

        5. Once the new index is created, you can verify its status in the Cloud Firestore console to ensure that it is in a "READY" or "CREATING" state.

        6. Repeat these steps for any other indexes that are in an invalid state.

        By following these steps, you can remediate the "Cloud Firestore Index State Should Be READY or CREATING" misconfiguration for GCP using GCP CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the Cloud Firestore Index State Should Be READY or CREATING issue for GCP using python, you can follow the below steps:

        1. First, you need to check the current state of the index by running the following command in the Cloud Shell:

        ```
        gcloud firestore indexes list
        ```

        2. If the state of the index is "CREATING", it means the index is still being created. You can wait for a few minutes and check again.

        3. If the state of the index is "ERROR", it means there was an error while creating the index. You can delete the index and recreate it using the following commands:

        ```
        gcloud firestore indexes delete [INDEX_NAME]
        gcloud firestore indexes create [INDEX_NAME] [FIELD_NAME] [ASCENDING/DESCENDING]
        ```

        Replace \[INDEX\_NAME] with the name of the index, \[FIELD\_NAME] with the name of the field on which the index is created, and \[ASCENDING/DESCENDING] with the order of the index.

        4. If the state of the index is "READY", it means the index is created successfully and there is no issue.

        5. You can also use the following python code to check the state of the index and delete and recreate the index if needed:

        ```
        from google.cloud import firestore

        db = firestore.Client()

        index_ref = db.collection('__collection_group__').document('__name__').collectionGroup('__subcollection__').document('__doc__').collectionGroup('__collection__').document('__doc__').collectionGroup('__subcollection__').document('__doc__').collection('__collection__').document('__doc__').collection('indexes').document('[INDEX_NAME]')

        index = index_ref.get()

        if index.to_dict()['state'] == 'ERROR':
            index_ref.delete()
            db.create_index([(u'[FIELD_NAME]', u'[ASCENDING/DESCENDING]')], collection_group=u'[COLLECTION_GROUP]')
        elif index.to_dict()['state'] == 'CREATING':
            # Wait for a few minutes and check again
            pass
        else:
            # Index is in READY state
            pass
        ```

        Replace \[INDEX\_NAME] with the name of the index, \[FIELD\_NAME] with the name of the field on which the index is created, \[ASCENDING/DESCENDING] with the order of the index, and \[COLLECTION\_GROUP] with the name of the collection group.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        # There is no Terraform or Google API argument to change a Firestore index state
        # from NEEDS_REPAIR to READY/CREATING; this must be fixed by deleting and
        # recreating the index via the Firestore Console or gcloud as per the docs.
        #
        # Example of how a healthy index would be managed in Terraform (for reference only):

        resource "google_firestore_index" "COLLECTION_GROUP_INDEX_NAME" {
          project    = "YOUR_PROJECT_ID"
          collection = "YOUR_COLLECTION_ID"

          fields {
            field_path = "FIELD_NAME_1"
            order      = "ASCENDING"
          }

          fields {
            field_path = "FIELD_NAME_2"
            order      = "DESCENDING"
          }

          # Add additional fields / array_config as needed
        }
        ```

        This finding cannot be remediated directly in Terraform because the provider does not expose index state or a “repair” operation; use the Firestore Console or `gcloud firestore indexes composite delete/create` to replace the NEEDS\_REPAIR index, then ensure your Firestore indexes are fully managed by `google_firestore_index` resources going forward. `terraform plan` will not show any state repair for existing NEEDS\_REPAIR indexes, only create/modify/destroy operations for indexes you define in code.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
