# BigQuery Connection

This module allows creating a BigQuery connection.

<!-- BEGIN TOC -->
- [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)
<!-- END TOC -->

## 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
```
<!-- BEGIN TFDOC -->
## Variables

| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [connection_id](variables.tf#L59) | The ID of the connection. | <code>string</code> | ✓ |  |
| [location](variables.tf#L132) | The geographic location where the connection should reside. | <code>string</code> | ✓ |  |
| [project_id](variables.tf#L137) | The ID of the project in which the resource belongs. | <code>string</code> | ✓ |  |
| [connection_config](variables.tf#L17) | Connection properties. | <code>object&#40;&#123;&#8230;&#125;&#41;</code> |  | <code>&#123;&#125;</code> |
| [context](variables.tf#L64) | Context-specific interpolations. | <code>object&#40;&#123;&#8230;&#125;&#41;</code> |  | <code>&#123;&#125;</code> |
| [description](variables.tf#L73) | A description of the connection. | <code>string</code> |  | <code>null</code> |
| [encryption_key](variables.tf#L79) | The name of the KMS key used for encryption. | <code>string</code> |  | <code>null</code> |
| [friendly_name](variables.tf#L85) | A descriptive name for the connection. | <code>string</code> |  | <code>null</code> |
| [iam](variables.tf#L91) | IAM bindings for the connection in {ROLE => [MEMBERS]} format. | <code>map&#40;list&#40;string&#41;&#41;</code> |  | <code>&#123;&#125;</code> |
| [iam_bindings](variables.tf#L97) | Authoritative IAM bindings in {KEY => {role = ROLE, members = [], condition = {}}}. Keys are arbitrary. | <code>map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> |  | <code>&#123;&#125;</code> |
| [iam_bindings_additive](variables.tf#L111) | Individual additive IAM bindings. Keys are arbitrary. | <code>map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> |  | <code>&#123;&#125;</code> |
| [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. | <code>map&#40;list&#40;string&#41;&#41;</code> |  | <code>&#123;&#125;</code> |

## 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. |  |
<!-- END TFDOC -->
