190 lines
8.6 KiB
Markdown
190 lines
8.6 KiB
Markdown
# Spanner instance
|
|
|
|
This module allows to create a spanner instance with associated spanner instance config and databases in the instance. Additionally it allows creating instance IAM bindings and database IAM bindings.
|
|
|
|
## Examples
|
|
|
|
### Basic instance with a database
|
|
|
|
```hcl
|
|
module "spanner_instace" {
|
|
source = "./fabric/modules/spanner-instance"
|
|
project_id = var.project_id
|
|
instance = {
|
|
name = "my-instance"
|
|
display_name = "Regional instance in us-central1"
|
|
config = {
|
|
name = "regional-us-central1"
|
|
}
|
|
num_nodes = 1
|
|
}
|
|
databases = {
|
|
my-database = {
|
|
|
|
}
|
|
}
|
|
}
|
|
# tftest modules=1 resources=2 inventory=simple-instance-with-database.yaml
|
|
```
|
|
|
|
### Instance with autoscaling
|
|
|
|
```hcl
|
|
module "spanner_instance" {
|
|
source = "./fabric/modules/spanner-instance"
|
|
project_id = var.project_id
|
|
instance = {
|
|
name = "my-instance"
|
|
display_name = "Regional instance"
|
|
config = {
|
|
name = "regional-us-central1"
|
|
}
|
|
autoscaling = {
|
|
limits = {
|
|
min_processing_units = 2000
|
|
max_processing_units = 3000
|
|
}
|
|
targets = {
|
|
high_priority_cpu_utilization_percent = 75
|
|
storage_utilization_percent = 90
|
|
}
|
|
}
|
|
labels = {
|
|
foo = "bar"
|
|
}
|
|
}
|
|
}
|
|
# tftest modules=1 resources=1 inventory=instance-with-autoscaling.yaml
|
|
```
|
|
|
|
### Instance with custom config
|
|
|
|
```hcl
|
|
module "spanner_instance" {
|
|
source = "./fabric/modules/spanner-instance"
|
|
project_id = var.project_id
|
|
instance = {
|
|
name = "my-instance"
|
|
display_name = "Regional instance"
|
|
config = {
|
|
name = "custom-nam11-config"
|
|
auto_create = {
|
|
display_name = "Test Spanner Instance Config"
|
|
base_config = "name11"
|
|
replicas = [
|
|
{
|
|
location = "us-west1"
|
|
type = "READ_ONLY"
|
|
default_leader_location = false
|
|
}
|
|
]
|
|
}
|
|
}
|
|
num_nodes = 1
|
|
}
|
|
}
|
|
# tftest modules=1 resources=2 inventory=instance-with-custom-config.yaml
|
|
```
|
|
|
|
### New database in existing instance
|
|
|
|
```hcl
|
|
module "spanner_instance" {
|
|
source = "./fabric/modules/spanner-instance"
|
|
project_id = var.project_id
|
|
instance = {
|
|
name = "my-instance"
|
|
}
|
|
instance_create = false
|
|
databases = {
|
|
my-database = {
|
|
|
|
}
|
|
}
|
|
}
|
|
# tftest skip
|
|
```
|
|
|
|
### IAM
|
|
|
|
```hcl
|
|
module "spanner_instance" {
|
|
source = "./fabric/modules/spanner-instance"
|
|
project_id = var.project_id
|
|
instance = {
|
|
name = "my-instance"
|
|
display_name = "Regional instance"
|
|
config = {
|
|
name = "regional-us-central1"
|
|
}
|
|
num_nodes = 1
|
|
}
|
|
databases = {
|
|
my-database = {
|
|
version_retention_period = "1d"
|
|
iam = {
|
|
"roles/spanner.databaseReader" = [
|
|
"group:group1@myorg.com"
|
|
]
|
|
}
|
|
iam_bindings = {
|
|
"spanner-database-role-user" = {
|
|
role = "roles/spanner.databaseRoleUser"
|
|
members = [
|
|
"group:group2@myorg.com"
|
|
]
|
|
condition = {
|
|
title = "role-my_role"
|
|
description = "Grant permissions on my_role"
|
|
expression = "(resource.type == \"spanner.googleapis.com/DatabaseRole\" && (resource.name.endsWith(\"/my_role\")))"
|
|
}
|
|
}
|
|
}
|
|
iam_bindings_additive = {
|
|
"spanner-database-admin" = {
|
|
role = "roles/spanner.databaseAdmin"
|
|
member = "group:group3@myorg.com"
|
|
condition = {
|
|
title = "delegated-role-grants"
|
|
description = "Delegated role grants."
|
|
expression = format(
|
|
"api.getAttribute('iam.googleapis.com/modifiedGrantsByRole', []).hasOnly([%s])",
|
|
join(",", formatlist("'%s'",
|
|
[
|
|
"roles/storage.databaseReader",
|
|
]
|
|
))
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# tftest modules=1 resources=5 inventory=iam.yaml
|
|
```
|
|
<!-- BEGIN TFDOC -->
|
|
## Variables
|
|
|
|
| name | description | type | required | default |
|
|
|---|---|:---:|:---:|:---:|
|
|
| [instance](variables.tf#L89) | Instance attributes. | <code title="object({ autoscaling = optional(object({ limits = optional(object({ max_nodes = optional(number) max_processing_units = optional(number) min_nodes = optional(number) min_processing_units = optional(number) })) targets = optional(object({ high_priority_cpu_utilization_percent = optional(number) storage_utilization_percent = optional(number) })) })) config = optional(object({ name = string auto_create = optional(object({ base_config = optional(string) display_name = optional(string) labels = optional(map(string), {}) replicas = list(object({ location = string type = string default_leader_location = bool } )) })) })) display_name = optional(string) labels = optional(map(string), {}) name = string num_nodes = optional(number) processing_units = optional(number) force_destroy = optional(bool) })">object({…})</code> | ✓ | |
|
|
| [project_id](variables.tf#L134) | Project id. | <code>string</code> | ✓ | |
|
|
| [databases](variables.tf#L17) | Databases. | <code title="map(object({ database_dialect = optional(string) ddl = optional(list(string), []) deletion_protection = optional(bool) enable_drop_protection = optional(bool) iam = optional(map(list(string)), {}) iam_bindings = optional(map(object({ members = list(string) role = string condition = optional(object({ expression = string title = string description = optional(string) })) })), {}) iam_bindings_additive = optional(map(object({ member = string role = string condition = optional(object({ expression = string title = string description = optional(string) })) })), {}) kms_key_name = optional(string) version_retention_period = optional(string) }))">map(object({…}))</code> | | <code>{}</code> |
|
|
| [iam](variables.tf#L63) | IAM bindings in {ROLE => [MEMBERS]} format. | <code>map(list(string))</code> | | <code>{}</code> |
|
|
| [iam_bindings](variables.tf#L69) | Authoritative IAM bindings in {KEY => {role = ROLE, members = [], condition = {}}}. Keys are arbitrary. | <code title="map(object({ members = list(string) role = string }))">map(object({…}))</code> | | <code>{}</code> |
|
|
| [iam_bindings_additive](variables.tf#L79) | Individual additive IAM bindings. Keys are arbitrary. | <code title="map(object({ member = string role = string }))">map(object({…}))</code> | | <code>{}</code> |
|
|
| [instance_create](variables.tf#L127) | Set to false to manage databases and IAM bindings in an existing instance. | <code>bool</code> | | <code>true</code> |
|
|
|
|
## Outputs
|
|
|
|
| name | description | sensitive |
|
|
|---|---|:---:|
|
|
| [spanner_database_ids](outputs.tf#L17) | Spanner database ids. | |
|
|
| [spanner_databases](outputs.tf#L22) | Spanner databases. | |
|
|
| [spanner_instance](outputs.tf#L27) | Spanner instance. | |
|
|
| [spanner_instance_config](outputs.tf#L32) | Spanner instance config. | |
|
|
| [spanner_instance_config_id](outputs.tf#L37) | Spanner instance config id. | |
|
|
| [spanner_instance_id](outputs.tf#L42) | Spanner instance id. | |
|
|
<!-- END TFDOC -->
|