Add deletion_protection to bigquery module
This commit is contained in:
parent
cd6e1c254d
commit
faa3a1cfe9
|
@ -79,26 +79,41 @@ module "bigquery-dataset" {
|
|||
Tables are created via the `tables` variable, or the `view` variable for views. Support for external tables will be added in a future release.
|
||||
|
||||
```hcl
|
||||
locals {
|
||||
countries_schema = jsonencode([
|
||||
{ name = "country", type = "STRING" },
|
||||
{ name = "population", type = "INT64" },
|
||||
])
|
||||
}
|
||||
|
||||
module "bigquery-dataset" {
|
||||
source = "./modules/bigquery-dataset"
|
||||
project_id = "my-project"
|
||||
id = "my-dataset"
|
||||
id = "my_dataset"
|
||||
tables = {
|
||||
table_a = {
|
||||
friendly_name = "Table a"
|
||||
countries = {
|
||||
friendly_name = "Countries"
|
||||
labels = {}
|
||||
options = null
|
||||
partitioning = null
|
||||
schema = file("table-a.json")
|
||||
schema = local.countries_schema
|
||||
deletion_protection = true
|
||||
}
|
||||
}
|
||||
}
|
||||
# tftest:skip
|
||||
# tftest:modules=1:resources=2
|
||||
```
|
||||
|
||||
If partitioning is needed, populate the `partitioning` variable using either the `time` or `range` attribute.
|
||||
|
||||
```hcl
|
||||
locals {
|
||||
countries_schema = jsonencode([
|
||||
{ name = "country", type = "STRING" },
|
||||
{ name = "population", type = "INT64" },
|
||||
])
|
||||
}
|
||||
|
||||
module "bigquery-dataset" {
|
||||
source = "./modules/bigquery-dataset"
|
||||
project_id = "my-project"
|
||||
|
@ -113,43 +128,50 @@ module "bigquery-dataset" {
|
|||
range = null # use start/end/interval for range
|
||||
time = { type = "DAY", expiration_ms = null }
|
||||
}
|
||||
schema = file("table-a.json")
|
||||
schema = local.countries_schema
|
||||
deletion_protection = true
|
||||
}
|
||||
}
|
||||
}
|
||||
# tftest:skip
|
||||
# tftest:modules=1:resources=2
|
||||
```
|
||||
|
||||
To create views use the `view` variable. If you're querying a table created by the same module `terraform apply` will initially fail and eventually succeed once the underlying table has been created. You can probably also use the module's output in the view's query to create a dependency on the table.
|
||||
|
||||
```hcl
|
||||
locals {
|
||||
countries_schema = jsonencode([
|
||||
{ name = "country", type = "STRING" },
|
||||
{ name = "population", type = "INT64" },
|
||||
])
|
||||
}
|
||||
|
||||
module "bigquery-dataset" {
|
||||
source = "./modules/bigquery-dataset"
|
||||
project_id = "my-project"
|
||||
id = "my-dataset"
|
||||
id = "my_dataset"
|
||||
tables = {
|
||||
table_a = {
|
||||
friendly_name = "Table a"
|
||||
countries = {
|
||||
friendly_name = "Countries"
|
||||
labels = {}
|
||||
options = null
|
||||
partitioning = {
|
||||
field = null
|
||||
range = null # use start/end/interval for range
|
||||
time = { type = "DAY", expiration_ms = null }
|
||||
}
|
||||
schema = file("table-a.json")
|
||||
partitioning = null
|
||||
schema = local.countries_schema
|
||||
deletion_protection = true
|
||||
}
|
||||
}
|
||||
views = {
|
||||
view_a = {
|
||||
friendly_name = "View a"
|
||||
population = {
|
||||
friendly_name = "Population"
|
||||
labels = {}
|
||||
query = "SELECT * from `my-project.my-dataset.table_a`"
|
||||
query = "SELECT SUM(population) FROM my_dataset.countries"
|
||||
use_legacy_sql = false
|
||||
deletion_protection = true
|
||||
}
|
||||
}
|
||||
}
|
||||
# tftest:skip
|
||||
|
||||
# tftest:modules=1:resources=3
|
||||
```
|
||||
|
||||
<!-- BEGIN TFDOC -->
|
||||
|
@ -168,8 +190,8 @@ module "bigquery-dataset" {
|
|||
| *labels* | Dataset labels. | <code title="map(string)">map(string)</code> | | <code title="">{}</code> |
|
||||
| *location* | Dataset location. | <code title="">string</code> | | <code title="">EU</code> |
|
||||
| *options* | Dataset options. | <code title="object({ default_table_expiration_ms = number default_partition_expiration_ms = number delete_contents_on_destroy = bool })">object({...})</code> | | <code title="{ default_table_expiration_ms = null default_partition_expiration_ms = null delete_contents_on_destroy = false }">...</code> |
|
||||
| *tables* | Table definitions. Options and partitioning default to null. Partitioning can only use `range` or `time`, set the unused one to null. | <code title="map(object({ friendly_name = string labels = map(string) options = object({ clustering = list(string) encryption_key = string expiration_time = number }) partitioning = object({ field = string range = object({ end = number interval = number start = number }) time = object({ expiration_ms = number type = string }) }) schema = string }))">map(object({...}))</code> | | <code title="">{}</code> |
|
||||
| *views* | View definitions. | <code title="map(object({ friendly_name = string labels = map(string) query = string use_legacy_sql = bool }))">map(object({...}))</code> | | <code title="">{}</code> |
|
||||
| *tables* | Table definitions. Options and partitioning default to null. Partitioning can only use `range` or `time`, set the unused one to null. | <code title="map(object({ friendly_name = string labels = map(string) options = object({ clustering = list(string) encryption_key = string expiration_time = number }) partitioning = object({ field = string range = object({ end = number interval = number start = number }) time = object({ expiration_ms = number type = string }) }) schema = string deletion_protection = bool }))">map(object({...}))</code> | | <code title="">{}</code> |
|
||||
| *views* | View definitions. | <code title="map(object({ friendly_name = string labels = map(string) query = string use_legacy_sql = bool deletion_protection = bool }))">map(object({...}))</code> | | <code title="">{}</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
|
|
@ -162,6 +162,7 @@ resource "google_bigquery_table" "default" {
|
|||
expiration_time = try(each.value.options.expiration_time, null)
|
||||
labels = each.value.labels
|
||||
schema = each.value.schema
|
||||
deletion_protection = each.value.deletion_protection
|
||||
|
||||
dynamic "encryption_configuration" {
|
||||
for_each = try(each.value.options.encryption_key, null) != null ? [""] : []
|
||||
|
@ -202,6 +203,7 @@ resource "google_bigquery_table" "views" {
|
|||
friendly_name = each.value.friendly_name
|
||||
description = "Terraform managed."
|
||||
labels = each.value.labels
|
||||
deletion_protection = each.value.deletion_protection
|
||||
|
||||
view {
|
||||
query = each.value.query
|
||||
|
|
|
@ -126,6 +126,7 @@ variable "tables" {
|
|||
})
|
||||
})
|
||||
schema = string
|
||||
deletion_protection = bool
|
||||
}))
|
||||
default = {}
|
||||
}
|
||||
|
@ -137,6 +138,7 @@ variable "views" {
|
|||
labels = map(string)
|
||||
query = string
|
||||
use_legacy_sql = bool
|
||||
deletion_protection = bool
|
||||
}))
|
||||
default = {}
|
||||
}
|
||||
|
|
|
@ -16,4 +16,8 @@
|
|||
|
||||
terraform {
|
||||
required_version = ">= 0.12.6"
|
||||
required_providers {
|
||||
google = ">= 3.58"
|
||||
google-beta = ">= 3.58"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue