...
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_compute_autoscaler" "default" {
19 provider = google-beta
20
21 name = "my-autoscaler"
22 zone = "us-central1-f"
23 target = google_compute_instance_group_manager.default.id
24
25 autoscaling_policy {
26 max_replicas = 5
27 min_replicas = 1
28 cooldown_period = 60
29
30 metric {
31 name = "pubsub.googleapis.com/subscription/num_undelivered_messages"
32 filter = "resource.type = pubsub_subscription AND resource.label.subscription_id = our-subscription"
33 single_instance_assignment = 65535
34 }
35 }
36}
37
38resource "google_compute_instance_template" "default" {
39 provider = google-beta
40
41 name = "my-instance-template"
42 machine_type = "e2-medium"
43 can_ip_forward = false
44
45 tags = ["foo", "bar"]
46
47 disk {
48 source_image = data.google_compute_image.debian_9.id
49 }
50
51 network_interface {
52 network = "default"
53 }
54
55 metadata = {
56 foo = "bar"
57 }
58
59 service_account {
60 scopes = ["userinfo-email", "compute-ro", "storage-ro"]
61 }
62}
63
64resource "google_compute_target_pool" "default" {
65 provider = google-beta
66
67 name = "my-target-pool"
68}
69
70resource "google_compute_instance_group_manager" "default" {
71 provider = google-beta
72
73 name = "my-igm"
74 zone = "us-central1-f"
75
76 version {
77 instance_template = google_compute_instance_template.default.id
78 name = "primary"
79 }
80
81 target_pools = [google_compute_target_pool.default.id]
82 base_instance_name = "autoscaler-sample"
83}
84
85data "google_compute_image" "debian_9" {
86 provider = google-beta
87
88 family = "debian-11"
89 project = "debian-cloud"
90}
91
92provider "google-beta" {
93 region = "us-central1"
94 zone = "us-central1-a"
95
96}
97```
View as plain text