...
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
18resource "google_sql_database_instance" "instance" {
19 name = "my-database-instance"
20 database_version = "POSTGRES_11"
21 region = "us-central1"
22 settings {
23 tier = "db-f1-micro"
24 }
25
26 deletion_protection = "true"
27}
28
29resource "google_sql_database" "db" {
30 instance = google_sql_database_instance.instance.name
31 name = "db"
32}
33
34resource "random_password" "pwd" {
35 length = 16
36 special = false
37}
38
39resource "google_sql_user" "user" {
40 name = "user"
41 instance = google_sql_database_instance.instance.name
42 password = random_password.pwd.result
43}
44
45resource "google_bigquery_connection" "connection" {
46 connection_id = "my-connection"
47 location = "US"
48 friendly_name = "👋"
49 description = "a riveting description"
50 cloud_sql {
51 instance_id = google_sql_database_instance.instance.connection_name
52 database = google_sql_database.db.name
53 type = "POSTGRES"
54 credential {
55 username = google_sql_user.user.name
56 password = google_sql_user.user.password
57 }
58 }
59}
60```
View as plain text