Skip to content

Commit 687152d

Browse files
authored
fix!: Adding regex validation for service name and adding apphub (#522)
1 parent 6e7e878 commit 687152d

File tree

9 files changed

+70
-7
lines changed

9 files changed

+70
-7
lines changed

modules/backend/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This module creates `google_compute_backend_service` resource and its dependenci
88
|------|-------------|------|---------|:--------:|
99
| affinity\_cookie\_ttl\_sec | Lifetime of cookies in seconds if session\_affinity is GENERATED\_COOKIE. | `number` | `null` | no |
1010
| backend\_bucket\_name | The name of GCS bucket which serves the traffic. | `string` | `""` | no |
11-
| cdn\_policy | Cloud CDN configuration for this BackendService. | <pre>object({<br> cache_mode = optional(string)<br> signed_url_cache_max_age_sec = optional(string)<br> default_ttl = optional(number)<br> max_ttl = optional(number)<br> client_ttl = optional(number)<br> negative_caching = optional(bool)<br> serve_while_stale = optional(number)<br> bypass_cache_on_request_headers = optional(list(string))<br> negative_caching_policy = optional(object({<br> code = optional(number)<br> ttl = optional(number)<br> }))<br> cache_key_policy = optional(object({<br> include_host = optional(bool)<br> include_protocol = optional(bool)<br> include_query_string = optional(bool)<br> query_string_blacklist = optional(list(string))<br> query_string_whitelist = optional(list(string))<br> include_http_headers = optional(list(string))<br> include_named_cookies = optional(list(string))<br> }))<br> })</pre> | <pre>{<br> "cache_mode": "CACHE_ALL_STATIC",<br> "client_ttl": 3600,<br> "default_ttl": 3600,<br> "max_ttl": 86400,<br> "signed_url_cache_max_age_sec": 0<br>}</pre> | no |
11+
| cdn\_policy | Cloud CDN configuration for this BackendService. | <pre>object({<br> cache_mode = optional(string)<br> signed_url_cache_max_age_sec = optional(string)<br> default_ttl = optional(number)<br> max_ttl = optional(number)<br> client_ttl = optional(number)<br> negative_caching = optional(bool)<br> serve_while_stale = optional(number)<br> bypass_cache_on_request_headers = optional(list(string))<br> negative_caching_policy = optional(object({<br> code = optional(number)<br> ttl = optional(number)<br> }))<br> cache_key_policy = optional(object({<br> include_host = optional(bool)<br> include_protocol = optional(bool)<br> include_query_string = optional(bool)<br> query_string_blacklist = optional(list(string))<br> query_string_whitelist = optional(list(string))<br> include_http_headers = optional(list(string))<br> include_named_cookies = optional(list(string))<br> }))<br> })</pre> | <pre>{<br> "cache_mode": "CACHE_ALL_STATIC",<br> "client_ttl": 3600,<br> "default_ttl": 3600,<br> "max_ttl": 86400,<br> "signed_url_cache_max_age_sec": "0"<br>}</pre> | no |
1212
| compression\_mode | Compress text responses using Brotli or gzip compression. | `string` | `"DISABLED"` | no |
1313
| connection\_draining\_timeout\_sec | Time for which instance will be drained (not accept new connections, but still work to finish started). | `number` | `null` | no |
1414
| custom\_request\_headers | Headers that the HTTP/S load balancer should add to proxied requests. | `list(string)` | `[]` | no |
@@ -42,6 +42,7 @@ This module creates `google_compute_backend_service` resource and its dependenci
4242

4343
| Name | Description |
4444
|------|-------------|
45+
| apphub\_service\_uri | Service URI in CAIS style to be used by Apphub. |
4546
| backend\_service\_info | Host, path and backend service mapping |
4647

4748
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/backend/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ resource "google_compute_backend_service" "default" {
6767
dynamic "backend" {
6868
for_each = toset(var.serverless_neg_backends)
6969
content {
70-
group = google_compute_region_network_endpoint_group.serverless_negs["neg-${var.name}-${backend.value.service_name}-${backend.value.region}"].id
70+
group = google_compute_region_network_endpoint_group.serverless_negs["neg-${var.name}-${backend.value.region}-${substr(md5(backend.value.service_name), 0, 4)}"].id
7171
}
7272
}
7373

@@ -163,7 +163,7 @@ resource "google_compute_backend_service" "default" {
163163

164164
resource "google_compute_region_network_endpoint_group" "serverless_negs" {
165165
for_each = { for serverless_neg_backend in local.serverless_neg_backends :
166-
"neg-${var.name}-${serverless_neg_backend.service_name}-${serverless_neg_backend.region}" => serverless_neg_backend }
166+
"neg-${var.name}-${serverless_neg_backend.region}-${substr(md5(serverless_neg_backend.service_name), 0, 4)}" => serverless_neg_backend }
167167

168168

169169
provider = google-beta

modules/backend/metadata.display.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ spec:
9696
name:
9797
name: name
9898
title: Name
99-
regexValidation: ^[a-z][a-z0-9-]{0,40}[a-z0-9]$
100-
validation: Use lowercase letters, numbers, and hyphens. Start with a letter and end with letter/number. Must be 42 characters or fewer.
99+
regexValidation: ^[a-z][a-z0-9-]{0,36}[a-z0-9]$
100+
validation: Use lowercase letters, numbers, and hyphens. Start with a letter and end with letter/number. Must be 38 characters or fewer.
101101
outlier_detection:
102102
name: outlier_detection
103103
title: Outlier Detection

modules/backend/metadata.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ spec:
229229
client_ttl: 3600
230230
default_ttl: 3600
231231
max_ttl: 86400
232-
signed_url_cache_max_age_sec: 0
232+
signed_url_cache_max_age_sec: "0"
233233
- name: outlier_detection
234234
description: Settings controlling eviction of unhealthy hosts from the load balancing pool.
235235
varType: |-
@@ -311,6 +311,14 @@ spec:
311311
defaultValue:
312312
- 10.127.0.0/23
313313
outputs:
314+
- name: apphub_service_uri
315+
description: Service URI in CAIS style to be used by Apphub.
316+
type:
317+
- list
318+
- - object
319+
- location: string
320+
service_id: string
321+
service_uri: string
314322
- name: backend_service_info
315323
description: Host, path and backend service mapping
316324
type:

modules/backend/outputs.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ output "backend_service_info" {
3030
] : []
3131
)
3232
}
33+
34+
output "apphub_service_uri" {
35+
value = [
36+
{
37+
service_uri = "//compute.googleapis.com/${google_compute_backend_service.default[0].id}"
38+
service_id = substr("${google_compute_backend_service.default[0].name}-${md5("global-be-service-${var.project_id}")}", 0, 63)
39+
location = "global"
40+
}
41+
]
42+
description = "Service URI in CAIS style to be used by Apphub."
43+
}

modules/backend/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ variable "cdn_policy" {
193193
default_ttl = 3600
194194
client_ttl = 3600
195195
max_ttl = 86400
196-
signed_url_cache_max_age_sec = 0
196+
signed_url_cache_max_age_sec = "0"
197197
}
198198
}
199199

modules/frontend/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ This module creates `HTTP(S) forwarding rule` and its dependencies. This modules
4141

4242
| Name | Description |
4343
|------|-------------|
44+
| apphub\_service\_uri | Service URI in CAIS style to be used by Apphub. |
4445
| external\_ip | The external IPv4 assigned to the global fowarding rule. |
4546
| external\_ipv6\_address | The external IPv6 assigned to the global fowarding rule. |
4647
| http\_proxy | The HTTP proxy used by this module. |

modules/frontend/metadata.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ spec:
201201
}))
202202
defaultValue: []
203203
outputs:
204+
- name: apphub_service_uri
205+
description: Service URI in CAIS style to be used by Apphub.
206+
type:
207+
- list
208+
- - object
209+
- location: string
210+
service_id: string
211+
service_uri: string
204212
- name: external_ip
205213
description: The external IPv4 assigned to the global fowarding rule.
206214
type: string

modules/frontend/outputs.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,37 @@ output "ssl_certificate_created" {
5858
description = "The SSL certificate create from key/pem"
5959
value = google_compute_ssl_certificate.default[*].self_link
6060
}
61+
62+
output "apphub_service_uri" {
63+
value = concat(
64+
local.create_http_forward && !local.is_internal_managed ? [
65+
{
66+
service_uri = "//compute.googleapis.com/${google_compute_global_forwarding_rule.http[0].id}"
67+
service_id = substr("${google_compute_global_forwarding_rule.http[0].name}-${md5("global-lb-${var.project_id}")}", 0, 63)
68+
location = "global"
69+
}
70+
] : [],
71+
var.ssl && !local.is_internal_managed ? [
72+
{
73+
service_uri = "//compute.googleapis.com/${google_compute_global_forwarding_rule.https[0].id}"
74+
service_id = substr("${google_compute_global_forwarding_rule.https[0].name}-${md5("global-lb-${var.project_id}")}", 0, 63)
75+
location = "global"
76+
}
77+
] : [],
78+
(var.enable_ipv6 && local.create_http_forward && !local.is_internal_managed) ? [
79+
{
80+
service_uri = "//compute.googleapis.com/${google_compute_global_forwarding_rule.http_ipv6[0].id}"
81+
service_id = substr("${google_compute_global_forwarding_rule.http_ipv6[0].name}-${md5("global-lb-${var.project_id}")}", 0, 63)
82+
location = "global"
83+
}
84+
] : [],
85+
var.enable_ipv6 && var.ssl && !local.is_internal_managed ? [
86+
{
87+
service_uri = "//compute.googleapis.com/${google_compute_global_forwarding_rule.https_ipv6[0].id}"
88+
service_id = substr("${google_compute_global_forwarding_rule.https_ipv6[0].name}-${md5("global-lb-${var.project_id}")}", 0, 63)
89+
location = "global"
90+
}
91+
] : [],
92+
)
93+
description = "Service URI in CAIS style to be used by Apphub."
94+
}

0 commit comments

Comments
 (0)