|
| 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