...
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_alloydb_backup" "default" {
19 location = "us-central1"
20 backup_id = "alloydb-backup"
21 cluster_name = google_alloydb_cluster.default.name
22
23 description = "example description"
24 labels = {
25 "label" = "key"
26 }
27 depends_on = [google_alloydb_instance.default]
28}
29
30resource "google_alloydb_cluster" "default" {
31 cluster_id = "alloydb-cluster"
32 location = "us-central1"
33 network = data.google_compute_network.default.id
34}
35
36resource "google_alloydb_instance" "default" {
37 cluster = google_alloydb_cluster.default.name
38 instance_id = "alloydb-instance"
39 instance_type = "PRIMARY"
40
41 depends_on = [google_service_networking_connection.vpc_connection]
42}
43
44resource "google_compute_global_address" "private_ip_alloc" {
45 name = "alloydb-cluster"
46 address_type = "INTERNAL"
47 purpose = "VPC_PEERING"
48 prefix_length = 16
49 network = data.google_compute_network.default.id
50}
51
52resource "google_service_networking_connection" "vpc_connection" {
53 network = data.google_compute_network.default.id
54 service = "servicenetworking.googleapis.com"
55 reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
56}
57
58data "google_compute_network" "default" {
59 name = "alloydb-network"
60}
61```
View as plain text