Skip to content

Commit 9b1a11e

Browse files
google_datastream_stream: Add support for projectID field in SourceHierarchyDatasets (#14858)
Co-authored-by: Nick Elliot <[email protected]>
1 parent aa289e7 commit 9b1a11e

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

mmv1/products/datastream/Stream.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,26 @@ examples:
180180
external_providers: ["random", "time"]
181181
# Random provider
182182
skip_vcr: true
183+
- name: 'datastream_stream_bigquery_cross_project_source_hierachy'
184+
primary_resource_id: 'default'
185+
vars:
186+
stream_id: 'my-stream'
187+
private_connection_id: 'my-connection'
188+
network_name: 'my-network'
189+
source_connection_profile_id: 'source-profile'
190+
database_instance_name: 'my-instance'
191+
deletion_protection: 'true'
192+
destination_connection_profile_id: 'destination-profile'
193+
test_env_vars:
194+
org_id: 'ORG_ID'
195+
billing_account: 'BILLING_ACCT'
196+
test_vars_overrides:
197+
'deletion_protection': 'false'
198+
oics_vars_overrides:
199+
'deletion_protection': 'false'
200+
external_providers: ["random", "time"]
201+
# Random provider
202+
skip_vcr: true
183203
- name: 'datastream_stream_bigquery_append_only'
184204
primary_resource_id: 'default'
185205
vars:
@@ -1337,6 +1357,10 @@ properties:
13371357
encryption key. i.e. projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{cryptoKey}.
13381358
See https://cloud.google.com/bigquery/docs/customer-managed-encryption for more information.
13391359
immutable: true
1360+
- name: 'projectId'
1361+
type: string
1362+
description: |
1363+
Optional. The project id of the BigQuery dataset. If not specified, the project will be inferred from the stream resource.
13401364
- name: 'blmtConfig'
13411365
type: NestedObject
13421366
description: 'BigLake Managed Tables configuration for BigQuery streams.'
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_project" "cross-project-dataset" {
5+
project_id = "tf-test%{random_suffix}"
6+
name = "tf-test%{random_suffix}"
7+
org_id = "{{index $.TestEnvVars "org_id"}}"
8+
billing_account = "{{index $.TestEnvVars "billing_account"}}"
9+
deletion_policy = "DELETE"
10+
}
11+
12+
resource "time_sleep" "wait_60_seconds" {
13+
create_duration = "60s"
14+
depends_on = [google_project.cross-project-dataset]
15+
}
16+
17+
resource "google_project_service" "bigquery" {
18+
project = google_project.cross-project-dataset.project_id
19+
service = "bigquery.googleapis.com"
20+
disable_on_destroy = false
21+
depends_on = [time_sleep.wait_60_seconds]
22+
}
23+
24+
resource "google_project_iam_member" "datastream_bigquery_admin" {
25+
project = google_project.cross-project-dataset.project_id
26+
role = "roles/bigquery.admin"
27+
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-datastream.iam.gserviceaccount.com"
28+
depends_on = [time_sleep.wait_60_seconds]
29+
}
30+
31+
resource "google_sql_database_instance" "instance" {
32+
name = "{{index $.Vars "database_instance_name"}}"
33+
database_version = "MYSQL_8_0"
34+
region = "us-central1"
35+
settings {
36+
tier = "db-f1-micro"
37+
backup_configuration {
38+
enabled = true
39+
binary_log_enabled = true
40+
}
41+
42+
ip_configuration {
43+
44+
// Datastream IPs will vary by region.
45+
authorized_networks {
46+
value = "34.71.242.81"
47+
}
48+
49+
authorized_networks {
50+
value = "34.72.28.29"
51+
}
52+
53+
authorized_networks {
54+
value = "34.67.6.157"
55+
}
56+
57+
authorized_networks {
58+
value = "34.67.234.134"
59+
}
60+
61+
authorized_networks {
62+
value = "34.72.239.218"
63+
}
64+
}
65+
}
66+
67+
deletion_protection = {{index $.Vars "deletion_protection"}}
68+
}
69+
70+
resource "google_sql_database" "db" {
71+
instance = google_sql_database_instance.instance.name
72+
name = "db"
73+
}
74+
75+
resource "random_password" "pwd" {
76+
length = 16
77+
special = false
78+
}
79+
80+
resource "google_sql_user" "user" {
81+
name = "user"
82+
instance = google_sql_database_instance.instance.name
83+
host = "%"
84+
password = random_password.pwd.result
85+
}
86+
87+
resource "google_datastream_connection_profile" "source_connection_profile" {
88+
display_name = "Source connection profile"
89+
location = "us-central1"
90+
connection_profile_id = "{{index $.Vars "source_connection_profile_id"}}"
91+
92+
mysql_profile {
93+
hostname = google_sql_database_instance.instance.public_ip_address
94+
username = google_sql_user.user.name
95+
password = google_sql_user.user.password
96+
}
97+
}
98+
99+
resource "google_datastream_connection_profile" "destination_connection_profile" {
100+
display_name = "Connection profile"
101+
location = "us-central1"
102+
connection_profile_id = "{{index $.Vars "destination_connection_profile_id"}}"
103+
104+
bigquery_profile {}
105+
}
106+
107+
resource "google_datastream_stream" "{{$.PrimaryResourceId}}" {
108+
stream_id = "{{index $.Vars "stream_id"}}"
109+
location = "us-central1"
110+
display_name = "my stream"
111+
source_config {
112+
source_connection_profile = google_datastream_connection_profile.source_connection_profile.id
113+
mysql_source_config {}
114+
}
115+
destination_config {
116+
destination_connection_profile = google_datastream_connection_profile.destination_connection_profile.id
117+
bigquery_destination_config {
118+
source_hierarchy_datasets {
119+
dataset_template {
120+
location = "us-central1"
121+
}
122+
project_id = google_project.cross-project-dataset.project_id
123+
}
124+
}
125+
}
126+
127+
backfill_none {
128+
}
129+
}

0 commit comments

Comments
 (0)