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.
Basic instance with a database
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
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
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
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
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:[email protected] "
]
}
iam_bindings = {
" spanner-database-role-user" = {
role = " roles/spanner.databaseRoleUser"
members = [
" group:[email protected] "
]
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:[email protected] "
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
name
description
type
required
default
instance
Instance attributes.
object({…})
✓
project_id
Project id.
string
✓
databases
Databases.
map(object({…}))
{}
iam
IAM bindings in {ROLE => [MEMBERS]} format.
map(list(string))
{}
iam_bindings
Authoritative IAM bindings in {KEY => {role = ROLE, members = [], condition = {}}}. Keys are arbitrary.
map(object({…}))
{}
iam_bindings_additive
Individual additive IAM bindings. Keys are arbitrary.
map(object({…}))
{}
instance_create
Set to false to manage databases and IAM bindings in an existing instance.
bool
true