Skip to content

Commit 9a0ba91

Browse files
BigQueryDestinationConfig to include merge and Append-only as configure write modes (#11116) (#745)
[upstream:0f42b5700ef7a6f8639231e8a56ab073ebcb7046] Signed-off-by: Modular Magician <[email protected]>
1 parent 764ea16 commit 9a0ba91

File tree

5 files changed

+204
-0
lines changed

5 files changed

+204
-0
lines changed

datastream_stream_bigquery/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ resource "google_datastream_stream" "default" {
106106
kms_key_name = "bigquery-kms-name-${local.name_suffix}"
107107
}
108108
}
109+
merge {}
109110
}
110111
}
111112

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_sql_database_instance" "instance" {
5+
name = "my-instance-${local.name_suffix}"
6+
database_version = "MYSQL_8_0"
7+
region = "us-central1"
8+
settings {
9+
tier = "db-f1-micro"
10+
backup_configuration {
11+
enabled = true
12+
binary_log_enabled = true
13+
}
14+
15+
ip_configuration {
16+
17+
// Datastream IPs will vary by region.
18+
authorized_networks {
19+
value = "34.71.242.81"
20+
}
21+
22+
authorized_networks {
23+
value = "34.72.28.29"
24+
}
25+
26+
authorized_networks {
27+
value = "34.67.6.157"
28+
}
29+
30+
authorized_networks {
31+
value = "34.67.234.134"
32+
}
33+
34+
authorized_networks {
35+
value = "34.72.239.218"
36+
}
37+
}
38+
}
39+
40+
deletion_protection = false
41+
}
42+
43+
resource "google_sql_database" "db" {
44+
instance = google_sql_database_instance.instance.name
45+
name = "db"
46+
}
47+
48+
resource "random_password" "pwd" {
49+
length = 16
50+
special = false
51+
}
52+
53+
resource "google_sql_user" "user" {
54+
name = "user"
55+
instance = google_sql_database_instance.instance.name
56+
host = "%"
57+
password = random_password.pwd.result
58+
}
59+
60+
resource "google_datastream_connection_profile" "source_connection_profile" {
61+
display_name = "Source connection profile"
62+
location = "us-central1"
63+
connection_profile_id = "source-profile-${local.name_suffix}"
64+
65+
mysql_profile {
66+
hostname = google_sql_database_instance.instance.public_ip_address
67+
username = google_sql_user.user.name
68+
password = google_sql_user.user.password
69+
}
70+
}
71+
72+
resource "google_datastream_connection_profile" "destination_connection_profile" {
73+
display_name = "Connection profile"
74+
location = "us-central1"
75+
connection_profile_id = "destination-profile-${local.name_suffix}"
76+
77+
bigquery_profile {}
78+
}
79+
80+
resource "google_datastream_stream" "default" {
81+
stream_id = "my-stream-${local.name_suffix}"
82+
location = "us-central1"
83+
display_name = "my stream"
84+
source_config {
85+
source_connection_profile = google_datastream_connection_profile.source_connection_profile.id
86+
mysql_source_config {}
87+
}
88+
destination_config {
89+
destination_connection_profile = google_datastream_connection_profile.destination_connection_profile.id
90+
bigquery_destination_config {
91+
source_hierarchy_datasets {
92+
dataset_template {
93+
location = "us-central1"
94+
}
95+
}
96+
append_only {}
97+
}
98+
}
99+
100+
backfill_none {
101+
}
102+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Datastream Stream Bigquery Append Only - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="datastream_stream_bigquery_append_only" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```

0 commit comments

Comments
 (0)