Google BigQuery Routine

This page shows how to write Terraform for BigQuery Routine and write them securely.

google_bigquery_routine (Terraform)

The Routine in BigQuery can be configured in Terraform with the resource name google_bigquery_routine. The following sections describe 2 examples of how to use the resource and its parameters.

Example Usage from GitHub

routines.tf#L24
resource "google_bigquery_routine" "IP_FROM_CIDR_STRING" {
  project      = var.logs_project_id
  dataset_id   = var.dataset_name
  routine_id   = "IP_FROM_CIDR_STRING"
  language     = "SQL"
  routine_type = "SCALAR_FUNCTION"
udf.tf#L1
resource "google_bigquery_routine" "my_sum_udf" {
  project         = var.project
  dataset_id      = google_bigquery_dataset.dataset.dataset_id
  routine_id      = "my_sum"
  routine_type    = "SCALAR_FUNCTION"
  //  language        = "SQL"

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The time when this routine was created, in milliseconds since the epoch.

The ID of the dataset containing this routine

The body of the routine. For functions, this is the expression in the AS clause. If language=SQL, it is the substring inside (but excluding) the parentheses.

The description of the routine if defined.

The determinism level of the JavaScript UDF if defined. Possible values: ["DETERMINISM_LEVEL_UNSPECIFIED", "DETERMINISTIC", "NOT_DETERMINISTIC"]

Optional. If language = "JAVASCRIPT", this field stores the path of the imported JAVASCRIPT libraries.

The language of the routine. Possible values: ["SQL", "JAVASCRIPT"]

The time when this routine was modified, in milliseconds since the epoch.

A JSON schema for the return type. Optional if language = "SQL"; required otherwise. If absent, the return type is inferred from definitionBody at query time in each query that references this routine. If present, then the evaluated result will be cast to the specified returned type at query time. ~>NOTE: Because this field expects a JSON string, any changes to the string will create a diff, even if the JSON itself hasn't changed. If the API returns a different value for the same schema, e.g. it switche d the order of values or replaced STRUCT field type with RECORD field type, we currently cannot suppress the recurring diff this causes. As a workaround, we recommend using the schema as returned by the API.

The ID of the the routine. The ID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_). The maximum length is 256 characters.

The type of routine. Possible values: ["SCALAR_FUNCTION", "PROCEDURE"]

  • arguments list block

    Defaults to FIXED_TYPE. Default value: "FIXED_TYPE" Possible values: ["FIXED_TYPE", "ANY_TYPE"]

    A JSON schema for the data type. Required unless argumentKind = ANY_TYPE. ~>NOTE: Because this field expects a JSON string, any changes to the string will create a diff, even if the JSON itself hasn't changed. If the API returns a different value for the same schema, e.g. it switched the order of values or replaced STRUCT field type with RECORD field type, we currently cannot suppress the recurring diff this causes. As a workaround, we recommend using the schema as returned by the API.

    Specifies whether the argument is input or output. Can be set for procedures only. Possible values: ["IN", "OUT", "INOUT"]

    The name of this argument. Can be absent for function return argument.

  • timeouts single block

Explanation in Terraform Registry

A user-defined function or a stored procedure that belongs to a Dataset To get more information about Routine, see:

Tips: Best Practices for The Other Google BigQuery Resources

In addition to the google_bigquery_dataset, Google BigQuery has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

google_bigquery_dataset

Ensure your BigQuery dataset blocks unwanted access

It is better to block unwanted access from users outside the organization.

Review your Google BigQuery settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Frequently asked questions

What is Google BigQuery Routine?

Google BigQuery Routine is a resource for BigQuery of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google BigQuery Routine?

For Terraform, the GoogleCloudPlatform/professional-services and bmwieczorek/my-apache-beam-dataflow source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.