Skip to content

Commit 71ab312

Browse files
m-habibpandirigoog
authored andcommitted
Add BigQuery BigLake Managed Tables as a Datastream destination (GoogleCloudPlatform#13189)
1 parent 539939f commit 71ab312

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed

mmv1/products/datastream/Stream.yaml

+50
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ examples:
197197
external_providers: ["random", "time"]
198198
# Random provider
199199
skip_vcr: true
200+
- name: 'datastream_stream_bigquery_blmt'
201+
primary_resource_id: 'default'
202+
vars:
203+
stream_id: 'blmt-stream'
204+
database_instance_name: 'blmt-instance'
205+
deletion_protection: 'true'
206+
source_connection_profile_id: 'blmt-source-profile'
207+
destination_connection_profile_id: 'blmt-destination-profile'
208+
blmt_bucket_name: 'blmt-bucket'
209+
blmt_connection_id: 'blmt-connection'
210+
test_vars_overrides:
211+
'deletion_protection': 'false'
212+
external_providers: ["random"]
213+
skip_vcr: true
214+
# Involves complex dependency creation, which makes it impractical in this context
215+
exclude_test: true
200216
virtual_fields:
201217
- name: 'desired_state'
202218
description: |
@@ -1224,6 +1240,40 @@ properties:
12241240
encryption key. i.e. projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{cryptoKey}.
12251241
See https://cloud.google.com/bigquery/docs/customer-managed-encryption for more information.
12261242
immutable: true
1243+
- name: 'blmtConfig'
1244+
type: NestedObject
1245+
description: 'BigLake Managed Tables configuration for BigQuery streams.'
1246+
properties:
1247+
- name: 'bucket'
1248+
type: String
1249+
description: |
1250+
The Cloud Storage bucket name.
1251+
required: true
1252+
- name: 'connectionName'
1253+
type: String
1254+
description: |
1255+
The bigquery connection. Format: `{project}.{location}.{name}`
1256+
required: true
1257+
- name: 'fileFormat'
1258+
type: String
1259+
description: |
1260+
The file format.
1261+
required: true
1262+
enum_values:
1263+
- FILE_FORMAT_UNSPECIFIED
1264+
- PARQUET
1265+
- name: 'tableFormat'
1266+
type: String
1267+
description: |
1268+
The table format.
1269+
required: true
1270+
enum_values:
1271+
- TABLE_FORMAT_UNSPECIFIED
1272+
- ICEBERG
1273+
- name: 'rootPath'
1274+
type: String
1275+
description: |
1276+
The root path inside the Cloud Storage bucket.
12271277
- name: 'merge'
12281278
type: NestedObject
12291279
description: |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_sql_database_instance" "instance" {
5+
name = "{{index $.Vars "database_instance_name"}}"
6+
database_version = "MYSQL_8_0"
7+
region = "us-central1"
8+
settings {
9+
tier = "db-f1-micro"
10+
ip_configuration {
11+
12+
// Datastream IPs will vary by region.
13+
authorized_networks {
14+
value = "34.71.242.81"
15+
}
16+
17+
authorized_networks {
18+
value = "34.72.28.29"
19+
}
20+
21+
authorized_networks {
22+
value = "34.67.6.157"
23+
}
24+
25+
authorized_networks {
26+
value = "34.67.234.134"
27+
}
28+
29+
authorized_networks {
30+
value = "34.72.239.218"
31+
}
32+
}
33+
}
34+
deletion_protection = {{index $.Vars "deletion_protection"}}
35+
}
36+
37+
resource "google_sql_database" "db" {
38+
instance = google_sql_database_instance.instance.name
39+
name = "db"
40+
}
41+
42+
resource "random_password" "pwd" {
43+
length = 16
44+
special = false
45+
}
46+
47+
resource "google_sql_user" "user" {
48+
name = "user"
49+
instance = google_sql_database_instance.instance.name
50+
host = "%"
51+
password = random_password.pwd.result
52+
}
53+
54+
resource "google_storage_bucket" "blmt_bucket" {
55+
# Use variable from Stream.yaml for the name
56+
name = "{{index $.Vars "blmt_bucket_name"}}"
57+
location = "us-central1"
58+
force_destroy = true
59+
}
60+
61+
resource "google_bigquery_connection" "blmt_connection" {
62+
project = data.google_project.project.project_id
63+
location = "us-central1"
64+
connection_id = "{{index $.Vars "blmt_connection_id"}}"
65+
friendly_name = "Datastream BLMT Test Connection"
66+
description = "Connection for Datastream BLMT test"
67+
68+
cloud_resource {}
69+
}
70+
71+
resource "google_storage_bucket_iam_member" "blmt_connection_bucket_admin" {
72+
bucket = google_storage_bucket.blmt_bucket.name
73+
role = "roles/storage.admin"
74+
member = "serviceAccount:${google_bigquery_connection.blmt_connection.cloud_resource[0].service_account_id}"
75+
}
76+
77+
resource "google_datastream_connection_profile" "source_connection_profile" {
78+
display_name = "Source connection profile"
79+
location = "us-central1"
80+
connection_profile_id = "{{index $.Vars "source_connection_profile_id"}}"
81+
82+
mysql_profile {
83+
hostname = google_sql_database_instance.instance.public_ip_address
84+
username = google_sql_user.user.name
85+
password = google_sql_user.user.password
86+
}
87+
}
88+
89+
resource "google_datastream_connection_profile" "destination_connection_profile" {
90+
display_name = "Connection profile"
91+
location = "us-central1"
92+
connection_profile_id = "{{index $.Vars "destination_connection_profile_id"}}"
93+
94+
bigquery_profile {}
95+
}
96+
97+
resource "google_datastream_stream" "{{$.PrimaryResourceId}}" {
98+
stream_id = "{{index $.Vars "stream_id"}}"
99+
location = "us-central1"
100+
display_name = "My BLMT stream"
101+
source_config {
102+
source_connection_profile = google_datastream_connection_profile.source_connection_profile.id
103+
mysql_source_config {}
104+
}
105+
destination_config {
106+
destination_connection_profile = google_datastream_connection_profile.destination_connection_profile.id
107+
bigquery_destination_config {
108+
source_hierarchy_datasets {
109+
dataset_template {
110+
location = "us-central1"
111+
}
112+
}
113+
blmt_config {
114+
bucket = google_storage_bucket.blmt_bucket.name
115+
connection_name = "${google_bigquery_connection.blmt_connection.project}.${google_bigquery_connection.blmt_connection.location}.${google_bigquery_connection.blmt_connection.connection_id}"
116+
file_format = "PARQUET"
117+
table_format = "ICEBERG"
118+
root_path = "/"
119+
}
120+
append_only {}
121+
}
122+
}
123+
124+
backfill_none {
125+
}
126+
}

0 commit comments

Comments
 (0)