Skip to content

Commit bafe101

Browse files
Make Backend Service Custom Metrics tests available in ga (#13274) (#939)
[upstream:38449e2c5533dd6bce0dbf9b0794b115cc57309f] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent f32e2f9 commit bafe101

File tree

8 files changed

+298
-0
lines changed

8 files changed

+298
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
resource "google_compute_network" "default" {
2+
name = "network-${local.name_suffix}"
3+
}
4+
5+
// Zonal NEG with GCE_VM_IP_PORT
6+
resource "google_compute_network_endpoint_group" "default" {
7+
name = "network-endpoint-${local.name_suffix}"
8+
network = google_compute_network.default.id
9+
default_port = "90"
10+
zone = "us-central1-a"
11+
network_endpoint_type = "GCE_VM_IP_PORT"
12+
}
13+
14+
resource "google_compute_backend_service" "default" {
15+
name = "backend-service-${local.name_suffix}"
16+
health_checks = [google_compute_health_check.default.id]
17+
18+
# WEIGHTED_ROUND_ROBIN and CUSTOM_METRICS require EXTERNAL_MANAGED.
19+
load_balancing_scheme = "EXTERNAL_MANAGED"
20+
locality_lb_policy = "WEIGHTED_ROUND_ROBIN"
21+
custom_metrics {
22+
name = "orca.application_utilization"
23+
# At least one metric should be not dry_run.
24+
dry_run = false
25+
}
26+
backend {
27+
group = google_compute_network_endpoint_group.default.id
28+
balancing_mode = "CUSTOM_METRICS"
29+
custom_metrics {
30+
name = "orca.cpu_utilization"
31+
max_utilization = 0.9
32+
dry_run = true
33+
}
34+
custom_metrics {
35+
name = "orca.named_metrics.foo"
36+
# At least one metric should be not dry_run.
37+
dry_run = false
38+
}
39+
}
40+
}
41+
42+
resource "google_compute_health_check" "default" {
43+
name = "health-check-${local.name_suffix}"
44+
timeout_sec = 1
45+
check_interval_sec = 1
46+
47+
tcp_health_check {
48+
port = "80"
49+
}
50+
}

backend_service_custom_metrics/motd

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Backend Service Custom Metrics - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="backend_service_custom_metrics" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
resource "google_compute_network" "default" {
2+
name = "network-${local.name_suffix}"
3+
}
4+
5+
// Zonal NEG with GCE_VM_IP_PORT
6+
resource "google_compute_network_endpoint_group" "default" {
7+
name = "network-endpoint-${local.name_suffix}"
8+
network = google_compute_network.default.id
9+
default_port = "90"
10+
zone = "us-central1-a"
11+
network_endpoint_type = "GCE_VM_IP_PORT"
12+
}
13+
14+
resource "google_compute_region_backend_service" "default" {
15+
region = "us-central1"
16+
name = "region-service-${local.name_suffix}"
17+
health_checks = [google_compute_health_check.health_check.id]
18+
load_balancing_scheme = "INTERNAL_MANAGED"
19+
locality_lb_policy = "WEIGHTED_ROUND_ROBIN"
20+
custom_metrics {
21+
name = "orca.application_utilization"
22+
# At least one metric should be not dry_run.
23+
dry_run = false
24+
}
25+
backend {
26+
group = google_compute_network_endpoint_group.default.id
27+
balancing_mode = "CUSTOM_METRICS"
28+
custom_metrics {
29+
name = "orca.cpu_utilization"
30+
max_utilization = 0.9
31+
dry_run = true
32+
}
33+
custom_metrics {
34+
name = "orca.named_metrics.foo"
35+
# At least one metric should be not dry_run.
36+
dry_run = false
37+
}
38+
}
39+
}
40+
41+
resource "google_compute_health_check" "health_check" {
42+
name = "rbs-health-check-${local.name_suffix}"
43+
http_health_check {
44+
port = 80
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Region Backend Service Ilb Custom Metrics - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="region_backend_service_ilb_custom_metrics" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```

0 commit comments

Comments
 (0)