# BigQuery Connection
This module allows creating a BigQuery connection.
- [Cloud SQL Connection](#cloud-sql-connection)
- [Cloud SQL Connection with Cloud KMS](#cloud-sql-connection-with-cloud-kms)
- [Spanner Connection](#spanner-connection)
- [Spanner Connection with Context interpolations](#spanner-connection-with-context-interpolations)
- [Variables](#variables)
- [Outputs](#outputs)
## Cloud SQL Connection
```hcl
module "bigquery-connection" {
source = "./fabric/modules/bigquery-connection"
project_id = var.project_id
location = "EU"
connection_id = "my-connection"
friendly_name = "My Cloud SQL Connection"
description = "A connection to a Cloud SQL instance."
connection_config = {
cloud_sql = {
instance_id = "my-instance-id"
database = "my-database"
type = "POSTGRES"
credential = {
username = "my-username"
password = "my-password"
}
}
}
iam = {
"roles/bigquery.connectionUser" = ["user:my-user@example.com"]
}
}
# tftest modules=1 resources=2 inventory=cloudsql.yaml
```
## Cloud SQL Connection with Cloud KMS
```hcl
module "bigquery-connection" {
source = "./fabric/modules/bigquery-connection"
project_id = var.project_id
location = "EU"
connection_id = "my-connection"
friendly_name = "My BigQuery Connection"
description = "A connection to a Cloud SQL instance."
encryption_key = "my-key"
connection_config = {
cloud_sql = {
instance_id = "my-instance-id"
database = "my-database"
type = "POSTGRES"
credential = {
username = "my-username"
password = "my-password"
}
}
}
}
# tftest modules=1 resources=1 inventory=cloudsql_kms.yaml
```
## Spanner Connection
```hcl
module "bigquery-connection" {
source = "./fabric/modules/bigquery-connection"
project_id = var.project_id
location = "EU"
connection_id = "my-connection"
friendly_name = "My BigQuery Connection"
description = "A connection to a Spanner instance."
connection_config = {
cloud_spanner = {
database = "projects/my-project/instances/my-instance/databases/my-database"
use_parallelism = true
use_data_boost = true
max_parallelism = 2
}
}
iam = {
"roles/bigquery.connectionUser" = ["user:my-user@example.com"]
}
}
# tftest modules=1 resources=2 inventory=spanner.yaml
```
## Spanner Connection with Context interpolations
```hcl
module "bigquery-connection" {
source = "./fabric/modules/bigquery-connection"
project_id = var.project_id
location = "EU"
connection_id = "my-connection"
friendly_name = "My BigQuery Connection"
description = "A connection to a Spanner instance."
connection_config = {
cloud_spanner = {
database = "projects/my-project/instances/my-instance/databases/my-database"
use_parallelism = true
use_data_boost = true
max_parallelism = 2
}
}
context = {
iam_principals = {
myuser = "user:my-user@example.com"
}
}
iam = {
"roles/bigquery.connectionUser" = ["$iam_principals:myuser"]
}
}
# tftest modules=1 resources=2 inventory=spanner_context.yaml
```
## Variables
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [connection_id](variables.tf#L59) | The ID of the connection. | string | ✓ | |
| [location](variables.tf#L132) | The geographic location where the connection should reside. | string | ✓ | |
| [project_id](variables.tf#L137) | The ID of the project in which the resource belongs. | string | ✓ | |
| [connection_config](variables.tf#L17) | Connection properties. | object({…}) | | {} |
| [context](variables.tf#L64) | Context-specific interpolations. | object({…}) | | {} |
| [description](variables.tf#L73) | A description of the connection. | string | | null |
| [encryption_key](variables.tf#L79) | The name of the KMS key used for encryption. | string | | null |
| [friendly_name](variables.tf#L85) | A descriptive name for the connection. | string | | null |
| [iam](variables.tf#L91) | IAM bindings for the connection in {ROLE => [MEMBERS]} format. | map(list(string)) | | {} |
| [iam_bindings](variables.tf#L97) | Authoritative IAM bindings in {KEY => {role = ROLE, members = [], condition = {}}}. Keys are arbitrary. | map(object({…})) | | {} |
| [iam_bindings_additive](variables.tf#L111) | Individual additive IAM bindings. Keys are arbitrary. | map(object({…})) | | {} |
| [iam_by_principals](variables.tf#L125) | Authoritative IAM binding in {PRINCIPAL => [ROLES]} format. Principals need to be statically defined to avoid cycle errors. Merged internally with the `iam` variable. | map(list(string)) | | {} |
## Outputs
| name | description | sensitive |
|---|---|:---:|
| [connection_config](outputs.tf#L17) | The connection configuration. | |
| [connection_id](outputs.tf#L29) | The ID of the BigQuery connection. | |
| [description](outputs.tf#L34) | The description of the connection. | |
| [location](outputs.tf#L39) | The location of the connection. | |