Skip to content

Commit 3e92096

Browse files
jkrish-cmelinath
andauthored
Add new resource RegionHealthSource to terraform-beta (#14956)
Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
1 parent b87553c commit 3e92096

File tree

3 files changed

+328
-0
lines changed

3 files changed

+328
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Copyright 2025 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
# API resource name
16+
name: 'RegionHealthSource'
17+
# Resource description for the provider documentation.
18+
description: |
19+
A health source resource specifies the source resources and the health
20+
aggregation policy applied to the source resources to determine the
21+
aggregated health status.
22+
references:
23+
guides:
24+
'Health checks overview': 'https://cloud.google.com/load-balancing/docs/health-check-concepts'
25+
api: 'https://cloud.google.com/compute/docs/reference/rest/beta/regionHealthSources'
26+
min_version: beta
27+
28+
# URL for the resource's standard List method. https://google.aip.dev/132
29+
# Terraform field names enclosed in double curly braces are replaced with
30+
# the field values from the resource at runtime.
31+
base_url: 'projects/{{project}}/regions/{{region}}/healthSources'
32+
# URL for the resource's standard Get method. https://google.aip.dev/131
33+
# Terraform field names enclosed in double curly braces are replaced with
34+
# the field values from the resource at runtime.
35+
self_link: 'projects/{{project}}/regions/{{region}}/healthSources/{{name}}'
36+
37+
# URL for the resource's standard Create method, including query parameters.
38+
# https://google.aip.dev/133
39+
# Terraform field names enclosed in double curly braces are replaced with
40+
# the field values from the resource at runtime.
41+
create_url: 'projects/{{project}}/regions/{{region}}/healthSources'
42+
43+
# Overrides the URL for the resource's standard Update method. (If unset, the
44+
# self_link URL is used by default.) https://google.aip.dev/134
45+
# Terraform field names enclosed in double curly braces are replaced with
46+
# the field values from the resource at runtime.
47+
update_url: 'projects/{{project}}/regions/{{region}}/healthSources/{{name}}'
48+
# The HTTP verb used to update a resource. Allowed values: :POST, :PUT, :PATCH. Default: :PUT.
49+
update_verb: 'PATCH'
50+
# If true, the resource sets an `updateMask` query parameter listing modified
51+
# fields when updating the resource. If false, it does not.
52+
update_mask: true
53+
54+
# If true, code for handling long-running operations is generated along with
55+
# the resource. If false, that code is not generated.
56+
autogen_async: true
57+
# Sets parameters for handling operations returned by the API.
58+
async:
59+
# Overrides which API calls return operations. Default: ['create',
60+
# 'update', 'delete']
61+
# actions: ['create', 'update', 'delete']
62+
operation:
63+
base_url: 'projects/{{project}}/regions/{{region}}/operations/{{op_id}}'
64+
65+
examples:
66+
- name: "compute_region_health_source_basic"
67+
primary_resource_id: "example_test_health_source"
68+
vars:
69+
name: "test-health-source"
70+
description: "Example health source basic"
71+
min_version: 'beta'
72+
test_env_vars:
73+
project: 'PROJECT_NAME'
74+
75+
parameters:
76+
- name: 'region'
77+
type: String
78+
required: true
79+
immutable: true
80+
url_param_only: true
81+
description: |
82+
URL of the region where the health source resides.
83+
- name: 'name'
84+
type: String
85+
required: true
86+
immutable: true
87+
description: |
88+
Name of the resource. Provided by the client when the resource is created.
89+
The name must be 1-63 characters long, and comply with RFC1035.
90+
Specifically, the name must be 1-63 characters long and match the regular
91+
expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first
92+
character must be a lowercase letter, and all following characters must
93+
be a dash, lowercase letter, or digit, except the last character, which
94+
cannot be a dash.
95+
96+
properties:
97+
- name: 'description'
98+
type: String
99+
description: |
100+
An optional description of this resource. Provide this property when you
101+
create the resource.
102+
- name: 'sourceType'
103+
type: Enum
104+
description: |
105+
Specifies the type of the `HealthSource`. The only allowed value
106+
is `BACKEND_SERVICE`. Must be specified when the
107+
`HealthSource` is created, and cannot be mutated.
108+
enum_values:
109+
- 'BACKEND_SERVICE'
110+
required: true
111+
immutable: true
112+
- name: 'sources'
113+
type: Array
114+
item_type:
115+
name: 'source'
116+
type: ResourceRef
117+
resource: 'RegionBackendService'
118+
imports: 'selfLink'
119+
description: |
120+
URLs to the source resources. Must be size 1. Must be a
121+
`BackendService` if the `sourceType` is `BACKEND_SERVICE`. The
122+
`BackendService` must have load balancing scheme
123+
`INTERNAL` or `INTERNAL_MANAGED` and must be regional
124+
and in the same region as the `HealthSource` (cross-region
125+
deployment for `INTERNAL_MANAGED` is not supported). The
126+
`BackendService` may use only IGs, MIGs, or NEGs of type
127+
`GCE_VM_IP` or `GCE_VM_IP_PORT`. The
128+
`BackendService` may not use `haPolicy`. Can be
129+
mutated.
130+
min_size: 1
131+
max_size: 1
132+
- name: 'healthAggregationPolicy'
133+
type: ResourceRef
134+
resource: 'RegionHealthAggregationPolicy'
135+
imports: 'selfLink'
136+
description: |
137+
URL to the `HealthAggregationPolicy` resource. Must be set. Must
138+
be regional and in the same region as the `HealthSource`. Can be
139+
mutated.
140+
- name: 'id'
141+
type: String
142+
description: 'The unique identifier for the resource. This identifier is defined by the server.'
143+
output: true
144+
- name: 'creationTimestamp'
145+
type: String
146+
description: 'Creation timestamp in RFC3339 text format.'
147+
output: true
148+
- name: 'selfLinkWithId'
149+
type: String
150+
description: 'Server-defined URL with id for the resource.'
151+
output: true
152+
- name: 'fingerprint'
153+
type: Fingerprint
154+
description: |
155+
Fingerprint of this resource. A hash of the contents stored in this object.
156+
This field is used in optimistic locking.
157+
output: true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "google_compute_region_health_aggregation_policy" "hap" {
2+
provider = google-beta
3+
name = "{{index $.Vars "name"}}-hap"
4+
description = "health aggregation policy for health source"
5+
region = "us-central1"
6+
}
7+
8+
resource "google_compute_health_check" "default" {
9+
provider = google-beta
10+
name = "{{index $.Vars "name"}}-hc"
11+
http_health_check {
12+
port = 80
13+
}
14+
}
15+
16+
resource "google_compute_region_backend_service" "default" {
17+
provider = google-beta
18+
name = "{{index $.Vars "name"}}-bs"
19+
region = "us-central1"
20+
health_checks = [google_compute_health_check.default.id]
21+
load_balancing_scheme = "INTERNAL"
22+
}
23+
24+
resource "google_compute_region_health_source" "{{$.PrimaryResourceId}}" {
25+
provider = google-beta
26+
name = "{{index $.Vars "name"}}"
27+
description = "{{index $.Vars "description"}}"
28+
region = "us-central1"
29+
source_type = "BACKEND_SERVICE"
30+
sources = [google_compute_region_backend_service.default.id]
31+
health_aggregation_policy = google_compute_region_health_aggregation_policy.hap.id
32+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package compute_test
2+
{{ if ne $.TargetVersionName `ga` -}}
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
8+
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"github.com/hashicorp/terraform-provider-google/google/envvar"
10+
)
11+
12+
func TestAccComputeRegionHealthSource_update(t *testing.T) {
13+
t.Parallel()
14+
15+
context := map[string]interface{}{
16+
"project": envvar.GetTestProjectFromEnv(),
17+
"random_suffix": acctest.RandString(t, 10),
18+
"region": "us-central1",
19+
}
20+
21+
acctest.VcrTest(t, resource.TestCase{
22+
PreCheck: func() { acctest.AccTestPreCheck(t) },
23+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
24+
CheckDestroy: testAccCheckComputeRegionHealthSourceDestroyProducer(t),
25+
Steps: []resource.TestStep{
26+
{
27+
Config: testAccComputeRegionHealthSource_basic(context),
28+
},
29+
{
30+
ResourceName: "google_compute_region_health_source.example_test_health_source",
31+
ImportState: true,
32+
ImportStateVerify: true,
33+
},
34+
{
35+
Config: testAccComputeRegionHealthSource_update(context),
36+
ConfigPlanChecks: resource.ConfigPlanChecks{
37+
PreApply: []plancheck.PlanCheck{
38+
plancheck.ExpectResourceAction("google_compute_region_health_source.example_test_health_source", plancheck.ResourceActionUpdate),
39+
},
40+
},
41+
},
42+
{
43+
ResourceName: "google_compute_region_health_source.example_test_health_source",
44+
ImportState: true,
45+
ImportStateVerify: true,
46+
},
47+
},
48+
})
49+
}
50+
51+
func testAccComputeRegionHealthSource_basic(context map[string]interface{}) string {
52+
return acctest.Nprintf(`
53+
resource "google_compute_region_health_aggregation_policy" "hap" {
54+
provider = google-beta
55+
name = "tf-test-hap-%{random_suffix}"
56+
description = "health aggregation policy for health source"
57+
region = "%{region}"
58+
}
59+
60+
resource "google_compute_health_check" "default" {
61+
provider = google-beta
62+
name = "tf-test-hc-%{random_suffix}"
63+
http_health_check {
64+
port = 80
65+
}
66+
}
67+
68+
resource "google_compute_region_backend_service" "default" {
69+
provider = google-beta
70+
name = "tf-test-bs-%{random_suffix}"
71+
region = "%{region}"
72+
health_checks = [google_compute_health_check.default.id]
73+
load_balancing_scheme = "INTERNAL"
74+
}
75+
76+
resource "google_compute_region_health_source" "example_test_health_source" {
77+
provider = google-beta
78+
name = "tf-test-health-source-%{random_suffix}"
79+
description = "Example health source basic"
80+
region = "%{region}"
81+
source_type = "BACKEND_SERVICE"
82+
sources = [google_compute_region_backend_service.default.id]
83+
health_aggregation_policy = google_compute_region_health_aggregation_policy.hap.id
84+
}
85+
`, context)
86+
}
87+
88+
func testAccComputeRegionHealthSource_update(context map[string]interface{}) string {
89+
return acctest.Nprintf(`
90+
resource "google_compute_region_health_aggregation_policy" "hap" {
91+
provider = google-beta
92+
name = "tf-test-hap-%{random_suffix}"
93+
description = "health aggregation policy for health source"
94+
region = "%{region}"
95+
}
96+
97+
resource "google_compute_health_check" "default" {
98+
provider = google-beta
99+
name = "tf-test-hc-%{random_suffix}"
100+
http_health_check {
101+
port = 80
102+
}
103+
}
104+
105+
resource "google_compute_region_backend_service" "default" {
106+
provider = google-beta
107+
name = "tf-test-bs-%{random_suffix}"
108+
region = "%{region}"
109+
health_checks = [google_compute_health_check.default.id]
110+
load_balancing_scheme = "INTERNAL"
111+
}
112+
113+
resource "google_compute_region_health_aggregation_policy" "hap2" {
114+
provider = google-beta
115+
name = "tf-test-hap2-%{random_suffix}"
116+
description = "health aggregation policy for health source 2"
117+
region = "%{region}"
118+
}
119+
120+
resource "google_compute_region_backend_service" "default2" {
121+
provider = google-beta
122+
name = "tf-test-bs2-%{random_suffix}"
123+
region = "%{region}"
124+
health_checks = [google_compute_health_check.default.id]
125+
load_balancing_scheme = "INTERNAL"
126+
}
127+
128+
resource "google_compute_region_health_source" "example_test_health_source" {
129+
provider = google-beta
130+
name = "tf-test-health-source-%{random_suffix}"
131+
description = "Updated description"
132+
region = "%{region}"
133+
source_type = "BACKEND_SERVICE"
134+
sources = [google_compute_region_backend_service.default2.id]
135+
health_aggregation_policy = google_compute_region_health_aggregation_policy.hap2.id
136+
}
137+
`, context)
138+
}
139+
{{- end }}

0 commit comments

Comments
 (0)