Skip to content

Commit f56f444

Browse files
franviera92ext_cvieramorgante
authored
feat: add feature deletion_protection in bigquery table (#114)
* chore: add feature deletion_protection in bigquery table * chore: add delete_protection attribute for table,view and external table * chore: add delete_protection attribute for table,view and external table * chore: add delete_protection attribute for table,view and external table * chore: add delete_protection attribute for table,view and external table * chore: add delete_protection attribute for table,view and external table * chore: add delete_protection attribute for table,view and external table * chore: add delete_protection attribute for table,view and external table * chore: add delete_protection attribute for table,view and external table * configure attribute delete_protection * configure attribute delete_protection in false to views * configure attribute delete_protection in false to views * Update variables.tf * Update README.md Co-authored-by: ext_cviera <[email protected]> Co-authored-by: Morgante Pell <[email protected]>
1 parent b1f8423 commit f56f444

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ This module provisions a dataset and a list of tables with associated JSON schem
166166
| dataset\_name | Friendly name for the dataset being provisioned. | `string` | `null` | no |
167167
| default\_table\_expiration\_ms | TTL of tables using the dataset in MS | `number` | `null` | no |
168168
| delete\_contents\_on\_destroy | (Optional) If set to true, delete all the tables in the dataset when destroying the resource; otherwise, destroying the resource will fail if tables are present. | `bool` | `null` | no |
169+
| deletion\_protection | Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail | `bool` | `false` | no |
169170
| description | Dataset description. | `string` | `null` | no |
170171
| encryption\_key | Default encryption key to apply to the dataset. Defaults to null (Google-managed). | `string` | `null` | no |
171172
| external\_tables | A list of objects which include table\_id, expiration\_time, external\_data\_configuration, and labels. | <pre>list(object({<br> table_id = string,<br> autodetect = bool,<br> compression = string,<br> ignore_unknown_values = bool,<br> max_bad_records = number,<br> schema = string,<br> source_format = string,<br> source_uris = list(string),<br> csv_options = object({<br> quote = string,<br> allow_jagged_rows = bool,<br> allow_quoted_newlines = bool,<br> encoding = string,<br> field_delimiter = string,<br> skip_leading_rows = number,<br> }),<br> google_sheets_options = object({<br> range = string,<br> skip_leading_rows = number,<br> }),<br> hive_partitioning_options = object({<br> mode = string,<br> source_uri_prefix = string,<br> }),<br> expiration_time = string,<br> labels = map(string),<br> }))</pre> | `[]` | no |

examples/multiple_tables/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
provider "google" {
18-
version = "~> 3.57.0"
18+
version = "~> 3.63.0"
1919
scopes = [
2020
# To configure an external table with a Google Sheet you must pass this scope
2121
# see: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/bigquery_table#source_format

main.tf

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ resource "google_bigquery_dataset" "main" {
6060
}
6161

6262
resource "google_bigquery_table" "main" {
63-
for_each = local.tables
64-
dataset_id = google_bigquery_dataset.main.dataset_id
65-
friendly_name = each.key
66-
table_id = each.key
67-
labels = each.value["labels"]
68-
schema = each.value["schema"]
69-
clustering = each.value["clustering"]
70-
expiration_time = each.value["expiration_time"]
71-
project = var.project_id
63+
for_each = local.tables
64+
dataset_id = google_bigquery_dataset.main.dataset_id
65+
friendly_name = each.key
66+
table_id = each.key
67+
labels = each.value["labels"]
68+
schema = each.value["schema"]
69+
clustering = each.value["clustering"]
70+
expiration_time = each.value["expiration_time"]
71+
project = var.project_id
72+
deletion_protection = var.deletion_protection
7273

7374
dynamic "time_partitioning" {
7475
for_each = each.value["time_partitioning"] != null ? [each.value["time_partitioning"]] : []
@@ -94,12 +95,13 @@ resource "google_bigquery_table" "main" {
9495
}
9596

9697
resource "google_bigquery_table" "view" {
97-
for_each = local.views
98-
dataset_id = google_bigquery_dataset.main.dataset_id
99-
friendly_name = each.key
100-
table_id = each.key
101-
labels = each.value["labels"]
102-
project = var.project_id
98+
for_each = local.views
99+
dataset_id = google_bigquery_dataset.main.dataset_id
100+
friendly_name = each.key
101+
table_id = each.key
102+
labels = each.value["labels"]
103+
project = var.project_id
104+
deletion_protection = false
103105

104106
view {
105107
query = each.value["query"]
@@ -108,13 +110,14 @@ resource "google_bigquery_table" "view" {
108110
}
109111

110112
resource "google_bigquery_table" "external_table" {
111-
for_each = local.external_tables
112-
dataset_id = google_bigquery_dataset.main.dataset_id
113-
friendly_name = each.key
114-
table_id = each.key
115-
labels = each.value["labels"]
116-
expiration_time = each.value["expiration_time"]
117-
project = var.project_id
113+
for_each = local.external_tables
114+
dataset_id = google_bigquery_dataset.main.dataset_id
115+
friendly_name = each.key
116+
table_id = each.key
117+
labels = each.value["labels"]
118+
expiration_time = each.value["expiration_time"]
119+
project = var.project_id
120+
deletion_protection = var.deletion_protection
118121

119122
external_data_configuration {
120123
autodetect = each.value["autodetect"]

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ variable "delete_contents_on_destroy" {
4343
default = null
4444
}
4545

46+
variable "deletion_protection" {
47+
description = "Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail"
48+
type = bool
49+
default = false
50+
}
51+
4652
variable "default_table_expiration_ms" {
4753
description = "TTL of tables using the dataset in MS"
4854
type = number

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ terraform {
2020

2121
google = {
2222
source = "hashicorp/google"
23-
version = "~> 3.53"
23+
version = "~> 3.63.0"
2424
}
2525
}
2626

0 commit comments

Comments
 (0)