|
1 | 1 | /**
|
2 |
| - * Copyright 2022 Google LLC |
| 2 | + * Copyright 2023 Google LLC |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -168,18 +168,88 @@ module "auth_dataset" {
|
168 | 168 | access = []
|
169 | 169 | }
|
170 | 170 |
|
| 171 | +resource "google_bigquery_table" "auth_ds_table" { |
| 172 | + deletion_protection = false |
| 173 | + dataset_id = module.auth_dataset.bigquery_dataset.dataset_id |
| 174 | + project = module.auth_dataset.bigquery_dataset.project |
| 175 | + table_id = "auth_db_table" |
| 176 | + |
| 177 | + view { |
| 178 | + query = "SELECT 1 as col1 from (select SESSION_USER())" |
| 179 | + use_legacy_sql = false |
| 180 | + } |
| 181 | +} |
| 182 | + |
| 183 | +resource "google_bigquery_routine" "auth_ds_routine1" { |
| 184 | + dataset_id = module.auth_dataset.bigquery_dataset.dataset_id |
| 185 | + project = module.auth_dataset.bigquery_dataset.project |
| 186 | + routine_id = "auth_ds_routine1" |
| 187 | + routine_type = "TABLE_VALUED_FUNCTION" |
| 188 | + language = "SQL" |
| 189 | + definition_body = <<-EOS |
| 190 | + SELECT 1 + value AS value |
| 191 | + EOS |
| 192 | + arguments { |
| 193 | + name = "value" |
| 194 | + argument_kind = "FIXED_TYPE" |
| 195 | + data_type = jsonencode({ "typeKind" = "INT64" }) |
| 196 | + } |
| 197 | + return_table_type = jsonencode({ "columns" = [ |
| 198 | + { "name" = "value", "type" = { "typeKind" = "INT64" } }, |
| 199 | + ] }) |
| 200 | +} |
| 201 | + |
| 202 | +resource "google_bigquery_routine" "auth_ds_routine2" { |
| 203 | + dataset_id = module.auth_dataset.bigquery_dataset.dataset_id |
| 204 | + project = module.auth_dataset.bigquery_dataset.project |
| 205 | + routine_id = "auth_ds_routine2" |
| 206 | + routine_type = "TABLE_VALUED_FUNCTION" |
| 207 | + language = "SQL" |
| 208 | + definition_body = <<-EOS |
| 209 | + SELECT 2 + value AS value |
| 210 | + EOS |
| 211 | + arguments { |
| 212 | + name = "value" |
| 213 | + argument_kind = "FIXED_TYPE" |
| 214 | + data_type = jsonencode({ "typeKind" = "INT64" }) |
| 215 | + } |
| 216 | + return_table_type = jsonencode({ "columns" = [ |
| 217 | + { "name" = "value", "type" = { "typeKind" = "INT64" } }, |
| 218 | + ] }) |
| 219 | +} |
| 220 | + |
171 | 221 | module "add_authorization" {
|
172 | 222 | source = "../../modules/authorization"
|
173 | 223 |
|
174 |
| - dataset_id = module.bigquery.bigquery_dataset.dataset_id |
175 |
| - project_id = module.bigquery.bigquery_dataset.project |
176 |
| - authorized_views = [] |
| 224 | + dataset_id = module.bigquery.bigquery_dataset.dataset_id |
| 225 | + project_id = module.bigquery.bigquery_dataset.project |
| 226 | + authorized_views = [ |
| 227 | + { |
| 228 | + project_id = module.auth_dataset.bigquery_dataset.project |
| 229 | + dataset_id = module.auth_dataset.bigquery_dataset.dataset_id |
| 230 | + table_id = google_bigquery_table.auth_ds_table.table_id |
| 231 | + }, |
| 232 | + ] |
177 | 233 | authorized_datasets = [
|
178 | 234 | {
|
179 | 235 | dataset_id = module.auth_dataset.bigquery_dataset.dataset_id
|
180 | 236 | project_id = module.auth_dataset.bigquery_dataset.project
|
181 | 237 | },
|
182 | 238 | ]
|
| 239 | + |
| 240 | + authorized_routines = [ |
| 241 | + { |
| 242 | + dataset_id = google_bigquery_routine.auth_ds_routine1.dataset_id |
| 243 | + project_id = google_bigquery_routine.auth_ds_routine1.project |
| 244 | + routine_id = google_bigquery_routine.auth_ds_routine1.routine_id |
| 245 | + }, |
| 246 | + { |
| 247 | + dataset_id = google_bigquery_routine.auth_ds_routine2.dataset_id |
| 248 | + project_id = google_bigquery_routine.auth_ds_routine2.project |
| 249 | + routine_id = google_bigquery_routine.auth_ds_routine2.routine_id |
| 250 | + }, |
| 251 | + ] |
| 252 | + |
183 | 253 | depends_on = [
|
184 | 254 | module.auth_dataset
|
185 | 255 | ]
|
|
0 commit comments