...

Text file src/github.com/GoogleCloudPlatform/k8s-config-connector/scripts/resource-autogen/generated/samples/Datastream-DatastreamStream-datastream_stream_basic/main.tf

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/scripts/resource-autogen/generated/samples/Datastream-DatastreamStream-datastream_stream_basic

     1/**
     2 * Copyright 2022 Google LLC
     3 *
     4 * Licensed under the Apache License, Version 2.0 (the "License");
     5 * you may not use this file except in compliance with the License.
     6 * You may obtain a copy of the License at
     7 *
     8 *      http://www.apache.org/licenses/LICENSE-2.0
     9 *
    10 * Unless required by applicable law or agreed to in writing, software
    11 * distributed under the License is distributed on an "AS IS" BASIS,
    12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13 * See the License for the specific language governing permissions and
    14 * limitations under the License.
    15 */
    16
    17```hcl
    18data "google_project" "project" {
    19}
    20
    21resource "google_sql_database_instance" "instance" {
    22    name             = "my-instance"
    23    database_version = "MYSQL_8_0"
    24    region           = "us-central1"
    25    settings {
    26        tier = "db-f1-micro"
    27        backup_configuration {
    28            enabled            = true
    29            binary_log_enabled = true
    30        }
    31
    32        ip_configuration {
    33
    34            // Datastream IPs will vary by region.
    35            authorized_networks {
    36                value = "34.71.242.81"
    37            }
    38
    39            authorized_networks {
    40                value = "34.72.28.29"
    41            }
    42
    43            authorized_networks {
    44                value = "34.67.6.157"
    45            }
    46
    47            authorized_networks {
    48                value = "34.67.234.134"
    49            }
    50
    51            authorized_networks {
    52                value = "34.72.239.218"
    53            }
    54        }
    55    }
    56
    57    deletion_protection  = true
    58}
    59
    60resource "google_sql_database" "db" {
    61    instance = google_sql_database_instance.instance.name
    62    name     = "db"
    63}
    64
    65resource "random_password" "pwd" {
    66    length = 16
    67    special = false
    68}
    69
    70resource "google_sql_user" "user" {
    71    name     = "user"
    72    instance = google_sql_database_instance.instance.name
    73    host     = "%"
    74    password = random_password.pwd.result
    75}
    76
    77resource "google_datastream_connection_profile" "source_connection_profile" {
    78    display_name          = "Source connection profile"
    79    location              = "us-central1"
    80    connection_profile_id = "source-profile"
    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
    89resource "google_storage_bucket" "bucket" {
    90  name                        = "my-bucket"
    91  location                    = "US"
    92  uniform_bucket_level_access = true
    93}
    94
    95resource "google_storage_bucket_iam_member" "viewer" {
    96    bucket = google_storage_bucket.bucket.name
    97    role   = "roles/storage.objectViewer"
    98    member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-datastream.iam.gserviceaccount.com"
    99}
   100
   101resource "google_storage_bucket_iam_member" "creator" {
   102    bucket = google_storage_bucket.bucket.name
   103    role   = "roles/storage.objectCreator"
   104    member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-datastream.iam.gserviceaccount.com"
   105}
   106
   107resource "google_storage_bucket_iam_member" "reader" {
   108    bucket = google_storage_bucket.bucket.name
   109    role   = "roles/storage.legacyBucketReader"
   110    member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-datastream.iam.gserviceaccount.com"
   111}
   112
   113resource "google_datastream_connection_profile" "destination_connection_profile" {
   114    display_name          = "Connection profile"
   115    location              = "us-central1"
   116    connection_profile_id = "destination-profile"
   117
   118    gcs_profile {
   119        bucket    = google_storage_bucket.bucket.name
   120        root_path = "/path"
   121    }
   122}
   123
   124resource "google_datastream_stream" "default" {
   125    stream_id = "my-stream"
   126    location = "us-central1"
   127    display_name = "my stream"
   128    source_config {
   129        source_connection_profile = google_datastream_connection_profile.source_connection_profile.id
   130        mysql_source_config {}
   131    }
   132    destination_config {
   133        destination_connection_profile = google_datastream_connection_profile.destination_connection_profile.id
   134        gcs_destination_config {
   135            avro_file_format {}
   136        }
   137    }
   138
   139    backfill_none {
   140    }
   141}
   142```

View as plain text