> ## 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.

# GCP BigQuery Tables Should Enable Ignore Unknown Values

### More Info:

Ensure that BigQuery Tables have enabled ignore unknown values

### Risk Level

Low

### Address

Operational Maturity, Security

### Compliance Standards

* Cloudanix Best Practice

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the misconfiguration of GCP BigQuery Tables not enabling Ignore Unknown Values, you can follow the below steps:

        1. Open the GCP Console and navigate to the BigQuery section.
        2. Select the dataset that contains the table for which you want to enable Ignore Unknown Values.
        3. Click on the table name to open the table details.
        4. Click on the Edit schema button to edit the schema of the table.
        5. In the Edit schema window, scroll down to the Advanced section.
        6. Toggle on the Ignore Unknown Values option.
        7. Click on the Save button to save the changes.

        By following these steps, you have successfully remediated the misconfiguration of GCP BigQuery Tables not enabling Ignore Unknown Values.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the GCP BigQuery Tables Should Enable Ignore Unknown Values misconfiguration, you can follow these steps using GCP CLI:

        1. Open the Cloud Shell in your GCP Console.

        2. Run the following command to enable the Ignore Unknown Values option for all tables in your BigQuery dataset:

        ```
        bq update --all --schema_update_option=ALLOW_FIELD_ADDITION <project_id>:<dataset_name>
        ```

        Replace `<project_id>` with your GCP project ID and `<dataset_name>` with the name of the BigQuery dataset that you want to update.

        3. Once the command is executed, it will update all the tables in the specified dataset to enable the Ignore Unknown Values option. This means that any new fields added to the data will be ignored instead of causing an error.

        4. Verify the changes by running the following command:

        ```
        bq show <project_id>:<dataset_name>.<table_name>
        ```

        Replace `<table_name>` with the name of the BigQuery table that you want to verify. The output should show that the Ignore Unknown Values option is enabled.

        By following these steps, you have successfully remediated the GCP BigQuery Tables Should Enable Ignore Unknown Values misconfiguration using GCP CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration in GCP BigQuery Tables by enabling Ignore Unknown Values, you can follow these steps using Python:

        1. Import the required libraries:

        ```python theme={null}
        from google.cloud import bigquery
        from google.api_core.exceptions import BadRequest
        ```

        2. Initialize the BigQuery client:

        ```python theme={null}
        client = bigquery.Client()
        ```

        3. Define the dataset and table name:

        ```python theme={null}
        dataset_id = 'your_dataset_id'
        table_id = 'your_table_id'
        ```

        4. Get the table metadata:

        ```python theme={null}
        table_ref = client.dataset(dataset_id).table(table_id)
        table = client.get_table(table_ref)
        ```

        5. Update the table schema to enable Ignore Unknown Values:

        ```python theme={null}
        try:
            table.schema.update(
                bigquery.SchemaField('your_field_name', 'STRING', mode='NULLABLE', allow_unknown=True)
            )
            table = client.update_table(table, ['schema'])
            print(f'Table {table_id} schema updated.')
        except BadRequest as e:
            print(f'Error updating table schema: {e}')
        ```

        6. Verify that the Ignore Unknown Values setting is enabled:

        ```python theme={null}
        if table.schema[0].allow_unknown:
            print('Ignore Unknown Values is enabled.')
        else:
            print('Ignore Unknown Values is not enabled.')
        ```

        Note: Make sure to replace 'your\_dataset\_id', 'your\_table\_id', and 'your\_field\_name' with your own values. Also, ensure that you have the necessary permissions to update the table schema.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        # This setting cannot be applied on the BigQuery *table* itself; it only exists on load jobs.
        # There is no argument on google_bigquery_table (or any table-level resource) for ignore_unknown_values.

        # Example of a BigQuery table managed by Terraform (shown only for context)
        resource "google_bigquery_table" "example" {
          project    = "PROJECT_ID"          # replace with your GCP project ID
          dataset_id = "DATASET_ID"          # replace with your dataset ID
          table_id   = "TABLE_ID"            # replace with your table ID

          schema = file("schema.json")
        }

        ```

        The BigQuery API exposes `ignoreUnknownValues` only on load jobs (JobConfigurationLoad), not on table metadata, and the `google_bigquery_table` resource does not have any `ignore_unknown_values` (or equivalent) argument. This finding therefore cannot be remediated on the `gcp-dataanalytics-bigquery-dataset-table` surface via Terraform; you must instead enable *Ignore unknown values* on whatever creates/loads the data (e.g., Dataflow, BigQuery load jobs, ingestion pipeline) by setting that flag there via its Terraform resource/module or in the Console.

        No `terraform plan` change is possible for this specific setting on the table resource, because the provider does not expose it.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
