Skip to content

Commit e2a5c82

Browse files
authored
feature: Added recommended defaults for blueprint variables (#20)
1 parent 8b68e31 commit e2a5c82

File tree

5 files changed

+105
-15
lines changed

5 files changed

+105
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Functional examples are included in the
3636
| name | The unique name of the Bigtable instance. | `string` | n/a | yes |
3737
| project\_id | The ID of the project in which the resource belongs | `string` | n/a | yes |
3838
| storage\_type | The storage type to use. One of SSD or HDD. Defaults to SSD | `string` | `"SSD"` | no |
39-
| tables | Tables to created in the Bigtable instance. | <pre>map(object({<br> table_name = string<br> split_keys = optional(list(string))<br> deletion_protection = optional(string)<br> change_stream_retention = optional(number)<br> column_family = optional(map(object({<br> family = string<br> }))<br> )<br> }))</pre> | `{}` | no |
40-
| zones | Zones of the Bigtable cluster. | <pre>map(object({<br> zone = string<br> cluster_id = string<br> num_nodes = optional(number)<br> kms_key_name = optional(string)<br> autoscaling_config = optional(object({<br> min_nodes = number<br> max_nodes = number<br> cpu_target = number<br> storage_target = optional(number)<br> }))<br> }))</pre> | n/a | yes |
39+
| tables | Tables to created in the Bigtable instance. | <pre>map(object({<br> table_name = string<br> split_keys = optional(list(string))<br> deletion_protection = optional(string, "PROTECTED")<br> change_stream_retention = optional(string, "0s")<br> automated_backup_policy = optional(object({<br> retention_period = string<br> frequency = string<br> }))<br><br> column_family = optional(map(object({<br> family = string<br> }))<br> )<br> }))</pre> | `{}` | no |
40+
| zones | Zones of the Bigtable cluster. | <pre>map(object({<br> zone = string<br> cluster_id = string<br> num_nodes = optional(number)<br> kms_key_name = optional(string)<br> autoscaling_config = optional(object({<br> min_nodes = number<br> max_nodes = number<br> cpu_target = number<br> storage_target = optional(number)<br> }))<br> }))</pre> | <pre>{<br> "zone1": {<br> "autoscaling_config": {<br> "cpu_target": 60,<br> "max_nodes": 2,<br> "min_nodes": 1<br> },<br> "cluster_id": "cluster1",<br> "zone": "us-central1-a"<br> },<br> "zone2": {<br> "autoscaling_config": {<br> "cpu_target": 60,<br> "max_nodes": 2,<br> "min_nodes": 1<br> },<br> "cluster_id": "cluster2",<br> "zone": "us-west1-a"<br> },<br> "zone3": {<br> "autoscaling_config": {<br> "cpu_target": 60,<br> "max_nodes": 2,<br> "min_nodes": 1<br> },<br> "cluster_id": "cluster3",<br> "zone": "us-central1-c"<br> }<br>}</pre> | no |
4141

4242
## Outputs
4343

examples/basic/main.tf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,27 @@ module "bigtable" {
4242
}
4343
tables = {
4444
table1 = {
45-
"table_name" = "test-table1"
45+
table_name = "test-table1"
4646
split_keys = ["a", "b", "c"]
47-
"column_family" = {
47+
column_family = {
4848
family1 = {
49-
"family" = "first-family"
49+
family = "first-family"
5050
}
5151
family2 = {
52-
"family" = "second-family"
52+
family = "second-family"
5353
}
5454
}
55+
deletion_protection = "UNPROTECTED"
5556
}
57+
5658
table2 = {
57-
"table_name" = "test-table2"
58-
table3 = {
59-
"table_name" = "test-table3"
60-
}
59+
table_name = "test-table2"
60+
deletion_protection = "UNPROTECTED"
61+
}
62+
63+
table3 = {
64+
table_name = "test-table3"
65+
deletion_protection = "UNPROTECTED"
6166
}
6267
}
6368
deletion_protection = false

main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ resource "google_bigtable_table" "table" {
6565
family = column_family.value["family"]
6666
}
6767
}
68+
69+
dynamic "automated_backup_policy" {
70+
for_each = each.value.automated_backup_policy != null ? [each.value.automated_backup_policy] : []
71+
content {
72+
retention_period = automated_backup_policy.value.retention_period
73+
frequency = automated_backup_policy.value.frequency
74+
}
75+
}
6876
}
6977

7078

metadata.yaml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,28 @@ spec:
7171
storage_target = optional(number)
7272
}))
7373
}))
74-
required: true
74+
defaultValue:
75+
zone1:
76+
autoscaling_config:
77+
cpu_target: 60
78+
max_nodes: 2
79+
min_nodes: 1
80+
cluster_id: cluster1
81+
zone: us-central1-a
82+
zone2:
83+
autoscaling_config:
84+
cpu_target: 60
85+
max_nodes: 2
86+
min_nodes: 1
87+
cluster_id: cluster2
88+
zone: us-west1-a
89+
zone3:
90+
autoscaling_config:
91+
cpu_target: 60
92+
max_nodes: 2
93+
min_nodes: 1
94+
cluster_id: cluster3
95+
zone: us-central1-c
7596
- name: labels
7697
description: labels associated to the Bigtable instance.
7798
varType: map(string)
@@ -82,8 +103,13 @@ spec:
82103
map(object({
83104
table_name = string
84105
split_keys = optional(list(string))
85-
deletion_protection = optional(string)
86-
change_stream_retention = optional(number)
106+
deletion_protection = optional(string, "PROTECTED")
107+
change_stream_retention = optional(string, "0s")
108+
automated_backup_policy = optional(object({
109+
retention_period = string
110+
frequency = string
111+
}))
112+
87113
column_family = optional(map(object({
88114
family = string
89115
}))

variables.tf

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,45 @@ variable "zones" {
6464
storage_target = optional(number)
6565
}))
6666
}))
67+
68+
default = {
69+
"zone1" = {
70+
cluster_id = "cluster1"
71+
zone = "us-central1-a"
72+
autoscaling_config = {
73+
min_nodes = 1
74+
max_nodes = 2
75+
cpu_target = 60
76+
}
77+
}
78+
79+
"zone2" = {
80+
cluster_id = "cluster2"
81+
zone = "us-west1-a"
82+
autoscaling_config = {
83+
min_nodes = 1
84+
max_nodes = 2
85+
cpu_target = 60
86+
}
87+
}
88+
89+
"zone3" = {
90+
cluster_id = "cluster3"
91+
zone = "us-central1-c"
92+
autoscaling_config = {
93+
min_nodes = 1
94+
max_nodes = 2
95+
cpu_target = 60
96+
}
97+
}
98+
}
99+
100+
validation {
101+
condition = alltrue(flatten([
102+
for k, v in var.zones : !((v.num_nodes == null && v.autoscaling_config == null) || (v.num_nodes != null && v.autoscaling_config != null))
103+
]))
104+
error_message = "Set either num_nodes (or) autoscaling_config."
105+
}
67106
}
68107

69108

@@ -79,8 +118,13 @@ variable "tables" {
79118
type = map(object({
80119
table_name = string
81120
split_keys = optional(list(string))
82-
deletion_protection = optional(string)
83-
change_stream_retention = optional(number)
121+
deletion_protection = optional(string, "PROTECTED")
122+
change_stream_retention = optional(string, "0s")
123+
automated_backup_policy = optional(object({
124+
retention_period = string
125+
frequency = string
126+
}))
127+
84128
column_family = optional(map(object({
85129
family = string
86130
}))
@@ -93,6 +137,13 @@ variable "tables" {
93137
]))
94138
error_message = "table_name must be between 1 and 50."
95139
}
140+
141+
validation {
142+
condition = alltrue(flatten([
143+
for k, v in var.tables : (v.deletion_protection == "PROTECTED" || v.deletion_protection == "UNPROTECTED")
144+
]))
145+
error_message = "deletion_protection must be set to either PROTECTED or UNPROTECTED"
146+
}
96147
default = {}
97148
}
98149

0 commit comments

Comments
 (0)