2020-06-08 17:40:26 -07:00
|
|
|
/**
|
2022-01-01 06:52:31 -08:00
|
|
|
* Copyright 2022 Google LLC
|
2020-06-08 17:40:26 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
locals {
|
2022-12-22 12:04:42 -08:00
|
|
|
gc_pairs = flatten([
|
|
|
|
for table, table_obj in var.tables : [
|
|
|
|
for cf, cf_obj in table_obj.column_families : {
|
|
|
|
table = table
|
|
|
|
column_family = cf
|
|
|
|
gc_policy = cf_obj.gc_policy == null ? var.default_gc_policy : cf_obj.gc_policy
|
|
|
|
}
|
|
|
|
]
|
|
|
|
])
|
2022-12-28 10:53:17 -08:00
|
|
|
|
2022-12-30 02:27:37 -08:00
|
|
|
clusters_autoscaling = {
|
|
|
|
for cluster_id, cluster in var.clusters : cluster_id => {
|
|
|
|
zone = cluster.zone
|
|
|
|
storage_type = cluster.storage_type
|
|
|
|
num_nodes = cluster.autoscaling == null && var.default_autoscaling == null ? cluster.num_nodes : null
|
|
|
|
autoscaling = cluster.autoscaling == null ? var.default_autoscaling : cluster.autoscaling
|
|
|
|
}
|
|
|
|
}
|
2020-06-08 17:40:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_bigtable_instance" "default" {
|
|
|
|
project = var.project_id
|
|
|
|
name = var.name
|
|
|
|
|
2022-12-28 10:57:07 -08:00
|
|
|
instance_type = var.instance_type
|
2020-06-08 17:40:26 -07:00
|
|
|
display_name = var.display_name == null ? var.display_name : var.name
|
|
|
|
deletion_protection = var.deletion_protection
|
2022-12-28 10:53:17 -08:00
|
|
|
|
|
|
|
dynamic "cluster" {
|
2022-12-30 02:27:37 -08:00
|
|
|
for_each = local.clusters_autoscaling
|
2022-12-28 10:53:17 -08:00
|
|
|
content {
|
2022-12-30 02:27:37 -08:00
|
|
|
cluster_id = cluster.key
|
2022-12-28 10:53:17 -08:00
|
|
|
zone = cluster.value.zone
|
|
|
|
storage_type = cluster.value.storage_type
|
|
|
|
num_nodes = cluster.value.num_nodes
|
|
|
|
|
|
|
|
dynamic "autoscaling_config" {
|
|
|
|
for_each = cluster.value.autoscaling == null ? [] : [""]
|
|
|
|
content {
|
|
|
|
min_nodes = cluster.value.autoscaling.min_nodes
|
|
|
|
max_nodes = cluster.value.autoscaling.max_nodes
|
|
|
|
cpu_target = cluster.value.autoscaling.cpu_target
|
|
|
|
storage_target = cluster.value.autoscaling.storage_target
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-08 17:40:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_bigtable_instance_iam_binding" "default" {
|
2020-11-05 23:11:07 -08:00
|
|
|
for_each = var.iam
|
2020-06-08 17:40:26 -07:00
|
|
|
project = var.project_id
|
|
|
|
instance = google_bigtable_instance.default.name
|
2020-10-30 10:55:54 -07:00
|
|
|
role = each.key
|
2020-06-08 17:40:26 -07:00
|
|
|
members = each.value
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_bigtable_table" "default" {
|
2022-12-22 06:42:06 -08:00
|
|
|
for_each = var.tables
|
2020-06-08 17:40:26 -07:00
|
|
|
project = var.project_id
|
|
|
|
instance_name = google_bigtable_instance.default.name
|
|
|
|
name = each.key
|
|
|
|
split_keys = each.value.split_keys
|
|
|
|
|
2021-08-12 08:30:53 -07:00
|
|
|
dynamic "column_family" {
|
2022-12-22 06:42:06 -08:00
|
|
|
for_each = each.value.column_families
|
2020-06-08 17:40:26 -07:00
|
|
|
|
|
|
|
content {
|
2022-12-22 12:04:42 -08:00
|
|
|
family = column_family.key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_bigtable_gc_policy" "default" {
|
|
|
|
for_each = { for k, v in local.gc_pairs : k => v if v.gc_policy != null }
|
|
|
|
|
|
|
|
table = each.value.table
|
|
|
|
column_family = each.value.column_family
|
|
|
|
instance_name = google_bigtable_instance.default.name
|
|
|
|
project = var.project_id
|
|
|
|
|
|
|
|
gc_rules = try(each.value.gc_policy.gc_rules, null)
|
|
|
|
mode = try(each.value.gc_policy.mode, null)
|
|
|
|
deletion_policy = try(each.value.gc_policy.deletion_policy, null)
|
|
|
|
|
|
|
|
dynamic "max_age" {
|
|
|
|
for_each = try(each.value.gc_policy.max_age, null) != null ? [""] : []
|
|
|
|
content {
|
|
|
|
duration = each.value.gc_policy.max_age
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dynamic "max_version" {
|
|
|
|
for_each = try(each.value.gc_policy.max_version, null) != null ? [""] : []
|
|
|
|
content {
|
|
|
|
number = each.value.gc_policy.max_version
|
2020-06-08 17:40:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|