Skip to content

Commit 50775aa

Browse files
Added Fingerprint to TargetHttpProxy and TartgetHttpsProxy (#14193) (#10175)
[upstream:50cb21c344228c799747b74044b5dca798c85ab2] Signed-off-by: Modular Magician <[email protected]>
1 parent a8e0f8b commit 50775aa

9 files changed

+349
-0
lines changed

.changelog/14193.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `fingerprint` field in `google_compute_target_http_proxy` and `google_compute_target_https_proxy` resources.
3+
```

google-beta/services/compute/resource_compute_target_http_proxy.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ this target proxy has a loadBalancingScheme set to INTERNAL_SELF_MANAGED.`,
107107
Computed: true,
108108
Description: `Creation timestamp in RFC3339 text format.`,
109109
},
110+
"fingerprint": {
111+
Type: schema.TypeString,
112+
Computed: true,
113+
Description: `Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking.
114+
This field will be ignored when inserting a TargetHttpProxy. An up-to-date fingerprint must be provided in order to
115+
patch/update the TargetHttpProxy; otherwise, the request will fail with error 412 conditionNotMet.
116+
To see the latest fingerprint, make a get() request to retrieve the TargetHttpProxy.
117+
A base64-encoded string.`,
118+
},
110119
"proxy_id": {
111120
Type: schema.TypeInt,
112121
Computed: true,
@@ -165,6 +174,12 @@ func resourceComputeTargetHttpProxyCreate(d *schema.ResourceData, meta interface
165174
} else if v, ok := d.GetOkExists("http_keep_alive_timeout_sec"); !tpgresource.IsEmptyValue(reflect.ValueOf(httpKeepAliveTimeoutSecProp)) && (ok || !reflect.DeepEqual(v, httpKeepAliveTimeoutSecProp)) {
166175
obj["httpKeepAliveTimeoutSec"] = httpKeepAliveTimeoutSecProp
167176
}
177+
fingerprintProp, err := expandComputeTargetHttpProxyFingerprint(d.Get("fingerprint"), d, config)
178+
if err != nil {
179+
return err
180+
} else if v, ok := d.GetOkExists("fingerprint"); !tpgresource.IsEmptyValue(reflect.ValueOf(fingerprintProp)) && (ok || !reflect.DeepEqual(v, fingerprintProp)) {
181+
obj["fingerprint"] = fingerprintProp
182+
}
168183

169184
url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/targetHttpProxies")
170185
if err != nil {
@@ -285,6 +300,9 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{}
285300
if err := d.Set("http_keep_alive_timeout_sec", flattenComputeTargetHttpProxyHttpKeepAliveTimeoutSec(res["httpKeepAliveTimeoutSec"], d, config)); err != nil {
286301
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
287302
}
303+
if err := d.Set("fingerprint", flattenComputeTargetHttpProxyFingerprint(res["fingerprint"], d, config)); err != nil {
304+
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
305+
}
288306
if err := d.Set("self_link", tpgresource.ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
289307
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
290308
}
@@ -493,6 +511,10 @@ func flattenComputeTargetHttpProxyHttpKeepAliveTimeoutSec(v interface{}, d *sche
493511
return v // let terraform core handle it otherwise
494512
}
495513

514+
func flattenComputeTargetHttpProxyFingerprint(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
515+
return v
516+
}
517+
496518
func expandComputeTargetHttpProxyDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
497519
return v, nil
498520
}
@@ -516,3 +538,7 @@ func expandComputeTargetHttpProxyProxyBind(v interface{}, d tpgresource.Terrafor
516538
func expandComputeTargetHttpProxyHttpKeepAliveTimeoutSec(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
517539
return v, nil
518540
}
541+
542+
func expandComputeTargetHttpProxyFingerprint(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
543+
return v, nil
544+
}

google-beta/services/compute/resource_compute_target_http_proxy_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ api_resource_type_kind: 'TargetHttpProxy'
77
fields:
88
- field: 'creation_timestamp'
99
- field: 'description'
10+
- field: 'fingerprint'
1011
- field: 'http_keep_alive_timeout_sec'
1112
- field: 'name'
1213
- field: 'proxy_bind'

google-beta/services/compute/resource_compute_target_http_proxy_generated_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,81 @@ resource "google_compute_url_map" "default" {
214214
`, context)
215215
}
216216

217+
func TestAccComputeTargetHttpProxy_targetHttpProxyFingerprintExample(t *testing.T) {
218+
t.Parallel()
219+
220+
context := map[string]interface{}{
221+
"random_suffix": acctest.RandString(t, 10),
222+
}
223+
224+
acctest.VcrTest(t, resource.TestCase{
225+
PreCheck: func() { acctest.AccTestPreCheck(t) },
226+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
227+
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroyProducer(t),
228+
Steps: []resource.TestStep{
229+
{
230+
Config: testAccComputeTargetHttpProxy_targetHttpProxyFingerprintExample(context),
231+
},
232+
{
233+
ResourceName: "google_compute_target_http_proxy.default",
234+
ImportState: true,
235+
ImportStateVerify: true,
236+
ImportStateVerifyIgnore: []string{"url_map"},
237+
},
238+
},
239+
})
240+
}
241+
242+
func testAccComputeTargetHttpProxy_targetHttpProxyFingerprintExample(context map[string]interface{}) string {
243+
return acctest.Nprintf(`
244+
resource "google_compute_target_http_proxy" "default" {
245+
name = "tf-test-test-fingerprint-proxy%{random_suffix}"
246+
url_map = google_compute_url_map.default.id
247+
}
248+
249+
resource "google_compute_url_map" "default" {
250+
name = "tf-test-url-map%{random_suffix}"
251+
default_service = google_compute_backend_service.default.id
252+
253+
host_rule {
254+
hosts = ["mysite.com"]
255+
path_matcher = "allpaths"
256+
}
257+
258+
path_matcher {
259+
name = "allpaths"
260+
default_service = google_compute_backend_service.default.id
261+
262+
path_rule {
263+
paths = ["/*"]
264+
service = google_compute_backend_service.default.id
265+
}
266+
}
267+
}
268+
269+
resource "google_compute_backend_service" "default" {
270+
name = "tf-test-backend-service%{random_suffix}"
271+
port_name = "http"
272+
protocol = "HTTP"
273+
timeout_sec = 10
274+
275+
health_checks = [google_compute_http_health_check.default.id]
276+
}
277+
278+
resource "google_compute_http_health_check" "default" {
279+
name = "tf-test-http-health-check%{random_suffix}"
280+
request_path = "/"
281+
check_interval_sec = 1
282+
timeout_sec = 1
283+
}
284+
285+
output "target_http_proxy_fingerprint" {
286+
value = google_compute_target_http_proxy.default.fingerprint
287+
description = "The fingerprint of the target HTTP proxy for optimistic locking"
288+
}
289+
`, context)
290+
}
291+
217292
func testAccCheckComputeTargetHttpProxyDestroyProducer(t *testing.T) func(s *terraform.State) error {
218293
return func(s *terraform.State) error {
219294
for name, rs := range s.RootModule().Resources {

google-beta/services/compute/resource_compute_target_https_proxy.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ This applies to TLS 1.3 connections over TCP (HTTP/2) as well as over UDP (QUIC/
192192
Computed: true,
193193
Description: `Creation timestamp in RFC3339 text format.`,
194194
},
195+
"fingerprint": {
196+
Type: schema.TypeString,
197+
Computed: true,
198+
Description: `Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking.
199+
This field will be ignored when inserting a TargetHttpsProxy. An up-to-date fingerprint must be provided in order to
200+
patch the TargetHttpsProxy; otherwise, the request will fail with error 412 conditionNotMet.
201+
To see the latest fingerprint, make a get() request to retrieve the TargetHttpsProxy.
202+
A base64-encoded string.`,
203+
},
195204
"proxy_id": {
196205
Type: schema.TypeInt,
197206
Computed: true,
@@ -292,6 +301,12 @@ func resourceComputeTargetHttpsProxyCreate(d *schema.ResourceData, meta interfac
292301
} else if v, ok := d.GetOkExists("server_tls_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(serverTlsPolicyProp)) && (ok || !reflect.DeepEqual(v, serverTlsPolicyProp)) {
293302
obj["serverTlsPolicy"] = serverTlsPolicyProp
294303
}
304+
fingerprintProp, err := expandComputeTargetHttpsProxyFingerprint(d.Get("fingerprint"), d, config)
305+
if err != nil {
306+
return err
307+
} else if v, ok := d.GetOkExists("fingerprint"); !tpgresource.IsEmptyValue(reflect.ValueOf(fingerprintProp)) && (ok || !reflect.DeepEqual(v, fingerprintProp)) {
308+
obj["fingerprint"] = fingerprintProp
309+
}
295310

296311
obj, err = resourceComputeTargetHttpsProxyEncoder(d, meta, obj)
297312
if err != nil {
@@ -450,6 +465,9 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
450465
if err := d.Set("server_tls_policy", flattenComputeTargetHttpsProxyServerTlsPolicy(res["serverTlsPolicy"], d, config)); err != nil {
451466
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
452467
}
468+
if err := d.Set("fingerprint", flattenComputeTargetHttpsProxyFingerprint(res["fingerprint"], d, config)); err != nil {
469+
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
470+
}
453471
if err := d.Set("self_link", tpgresource.ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
454472
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
455473
}
@@ -983,6 +1001,10 @@ func flattenComputeTargetHttpsProxyServerTlsPolicy(v interface{}, d *schema.Reso
9831001
return tpgresource.ConvertSelfLinkToV1(v.(string))
9841002
}
9851003

1004+
func flattenComputeTargetHttpsProxyFingerprint(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1005+
return v
1006+
}
1007+
9861008
func expandComputeTargetHttpsProxyDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
9871009
return v, nil
9881010
}
@@ -1072,6 +1094,10 @@ func expandComputeTargetHttpsProxyServerTlsPolicy(v interface{}, d tpgresource.T
10721094
return v, nil
10731095
}
10741096

1097+
func expandComputeTargetHttpsProxyFingerprint(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1098+
return v, nil
1099+
}
1100+
10751101
func resourceComputeTargetHttpsProxyEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
10761102

10771103
if _, ok := obj["certificateManagerCertificates"]; ok {

google-beta/services/compute/resource_compute_target_https_proxy_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fields:
99
- field: 'certificate_map'
1010
- field: 'creation_timestamp'
1111
- field: 'description'
12+
- field: 'fingerprint'
1213
- field: 'http_keep_alive_timeout_sec'
1314
- field: 'name'
1415
- field: 'proxy_bind'

google-beta/services/compute/resource_compute_target_https_proxy_generated_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,90 @@ resource "google_compute_backend_service" "default" {
386386
`, context)
387387
}
388388

389+
func TestAccComputeTargetHttpsProxy_targetHttpsProxyFingerprintExample(t *testing.T) {
390+
t.Parallel()
391+
392+
context := map[string]interface{}{
393+
"random_suffix": acctest.RandString(t, 10),
394+
}
395+
396+
acctest.VcrTest(t, resource.TestCase{
397+
PreCheck: func() { acctest.AccTestPreCheck(t) },
398+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
399+
CheckDestroy: testAccCheckComputeTargetHttpsProxyDestroyProducer(t),
400+
Steps: []resource.TestStep{
401+
{
402+
Config: testAccComputeTargetHttpsProxy_targetHttpsProxyFingerprintExample(context),
403+
},
404+
{
405+
ResourceName: "google_compute_target_https_proxy.default",
406+
ImportState: true,
407+
ImportStateVerify: true,
408+
ImportStateVerifyIgnore: []string{"server_tls_policy", "ssl_policy", "url_map"},
409+
},
410+
},
411+
})
412+
}
413+
414+
func testAccComputeTargetHttpsProxy_targetHttpsProxyFingerprintExample(context map[string]interface{}) string {
415+
return acctest.Nprintf(`
416+
resource "google_compute_target_https_proxy" "default" {
417+
name = "tf-test-test-fingerprint-proxy%{random_suffix}"
418+
url_map = google_compute_url_map.default.id
419+
ssl_certificates = [google_compute_ssl_certificate.default.id]
420+
}
421+
422+
resource "google_compute_ssl_certificate" "default" {
423+
name = "tf-test-my-certificate%{random_suffix}"
424+
private_key = file("test-fixtures/test.key")
425+
certificate = file("test-fixtures/test.crt")
426+
}
427+
428+
resource "google_compute_url_map" "default" {
429+
name = "tf-test-url-map%{random_suffix}"
430+
description = "a description"
431+
432+
default_service = google_compute_backend_service.default.id
433+
434+
host_rule {
435+
hosts = ["mysite.com"]
436+
path_matcher = "allpaths"
437+
}
438+
439+
path_matcher {
440+
name = "allpaths"
441+
default_service = google_compute_backend_service.default.id
442+
443+
path_rule {
444+
paths = ["/*"]
445+
service = google_compute_backend_service.default.id
446+
}
447+
}
448+
}
449+
450+
resource "google_compute_backend_service" "default" {
451+
name = "tf-test-backend-service%{random_suffix}"
452+
port_name = "http"
453+
protocol = "HTTP"
454+
timeout_sec = 10
455+
456+
health_checks = [google_compute_http_health_check.default.id]
457+
}
458+
459+
resource "google_compute_http_health_check" "default" {
460+
name = "tf-test-http-health-check%{random_suffix}"
461+
request_path = "/"
462+
check_interval_sec = 1
463+
timeout_sec = 1
464+
}
465+
466+
output "target_https_proxy_fingerprint" {
467+
value = google_compute_target_https_proxy.default.fingerprint
468+
description = "The fingerprint of the target HTTPS proxy for optimistic locking"
469+
}
470+
`, context)
471+
}
472+
389473
func testAccCheckComputeTargetHttpsProxyDestroyProducer(t *testing.T) func(s *terraform.State) error {
390474
return func(s *terraform.State) error {
391475
for name, rs := range s.RootModule().Resources {

website/docs/r/compute_target_http_proxy.html.markdown

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,61 @@ resource "google_compute_url_map" "default" {
156156
}
157157
}
158158
```
159+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
160+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=target_http_proxy_fingerprint&open_in_editor=main.tf" target="_blank">
161+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
162+
</a>
163+
</div>
164+
## Example Usage - Target Http Proxy Fingerprint
165+
166+
167+
```hcl
168+
resource "google_compute_target_http_proxy" "default" {
169+
name = "test-fingerprint-proxy"
170+
url_map = google_compute_url_map.default.id
171+
}
172+
173+
resource "google_compute_url_map" "default" {
174+
name = "url-map"
175+
default_service = google_compute_backend_service.default.id
176+
177+
host_rule {
178+
hosts = ["mysite.com"]
179+
path_matcher = "allpaths"
180+
}
181+
182+
path_matcher {
183+
name = "allpaths"
184+
default_service = google_compute_backend_service.default.id
185+
186+
path_rule {
187+
paths = ["/*"]
188+
service = google_compute_backend_service.default.id
189+
}
190+
}
191+
}
192+
193+
resource "google_compute_backend_service" "default" {
194+
name = "backend-service"
195+
port_name = "http"
196+
protocol = "HTTP"
197+
timeout_sec = 10
198+
199+
health_checks = [google_compute_http_health_check.default.id]
200+
}
201+
202+
resource "google_compute_http_health_check" "default" {
203+
name = "http-health-check"
204+
request_path = "/"
205+
check_interval_sec = 1
206+
timeout_sec = 1
207+
}
208+
209+
output "target_http_proxy_fingerprint" {
210+
value = google_compute_target_http_proxy.default.fingerprint
211+
description = "The fingerprint of the target HTTP proxy for optimistic locking"
212+
}
213+
```
159214

160215
## Argument Reference
161216

@@ -217,6 +272,13 @@ In addition to the arguments listed above, the following computed attributes are
217272

218273
* `proxy_id` -
219274
The unique identifier for the resource.
275+
276+
* `fingerprint` -
277+
Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking.
278+
This field will be ignored when inserting a TargetHttpProxy. An up-to-date fingerprint must be provided in order to
279+
patch/update the TargetHttpProxy; otherwise, the request will fail with error 412 conditionNotMet.
280+
To see the latest fingerprint, make a get() request to retrieve the TargetHttpProxy.
281+
A base64-encoded string.
220282
* `self_link` - The URI of the created resource.
221283

222284

0 commit comments

Comments
 (0)