Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
run "setup" {
module {
source = "./tests/setup"
}
}
run "test_service_with_default_variable_values_and_load_balancer_enabled" {
variables {
name = run.setup.random_name
enable_load_balancer = true
dns_names = {
webapp = "${run.setup.random_name}.test.example.gcp.uis.cam.ac.uk"
}
containers = {
webapp = {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
}
assert {
condition = google_cloud_run_v2_service.webapp.ingress == "INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER"
error_message = "Ingress should be 'INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER'."
}
assert {
condition = google_cloud_run_v2_service.webapp.launch_stage == "GA"
error_message = "Launch stage should be 'GA'."
}
assert {
condition = google_cloud_run_v2_service.webapp.location == "europe-west2"
error_message = "Location should be 'europe-west2'."
}
assert {
condition = google_cloud_run_v2_service.webapp.template[0].execution_environment == "EXECUTION_ENVIRONMENT_GEN1"
error_message = "Execution environment should be 'EXECUTION_ENVIRONMENT_GEN1'."
}
assert {
condition = google_cloud_run_v2_service.webapp.template[0].timeout == "300s"
error_message = "Timeout should be '300s'."
}
assert {
condition = google_cloud_run_v2_service_iam_member.webapp_all_users_invoker[0].role == "roles/run.invoker"
error_message = "google_cloud_run_v2_service_iam_member.webapp_all_users_invoker.role should be 'roles/run.invoker'."
}
assert {
condition = google_cloud_run_v2_service_iam_member.webapp_all_users_invoker[0].member == "allUsers"
error_message = "google_cloud_run_v2_service_iam_member.webapp_all_users_invoker.member should be 'allUsers'."
}
assert {
condition = google_service_account.webapp.name != null
error_message = "A dedicated service account should be created for the Cloud Run service."
}
assert {
condition = google_compute_region_network_endpoint_group.webapp[0].network_endpoint_type == "SERVERLESS"
error_message = "Network endpoint group type should be 'SERVERLESS'."
}
assert {
condition = google_compute_region_network_endpoint_group.webapp[0].cloud_run[0].service == google_cloud_run_v2_service.webapp.name
error_message = "Network endpoint group must contain the created Cloud Run service in its definition."
}
assert {
condition = google_compute_ssl_policy.default[0].min_tls_version == "TLS_1_2"
error_message = "Minimum TLS version should be 'TLS_1_2'."
}
assert {
condition = google_compute_ssl_policy.default[0].profile == "MODERN"
error_message = "SSL profile should be 'MODERN'."
}
assert {
condition = module.webapp_http_load_balancer[0].backend_services["default"].protocol == "HTTP"
error_message = "The default backend service protocol should be 'HTTP'."
}
assert {
condition = module.webapp_http_load_balancer[0].backend_services["default"].enable_cdn == false
error_message = "The default backend service should not enable CDN."
}
assert {
condition = module.webapp_http_load_balancer[0].backend_services["default"].log_config[0].enable == true
error_message = "The default backend service log config should be enabled."
}
assert {
condition = module.webapp_http_load_balancer[0].backend_services["default"].log_config[0].sample_rate == 1.0
error_message = "The default backend service log sample rate should be '1.0'."
}
assert {
condition = length(module.webapp_http_load_balancer[0].backend_services["default"].backend) == 1
error_message = "The default backend service should be configured with a single backend block."
}
assert {
condition = contains([
for backend in module.webapp_http_load_balancer[0].backend_services["default"].backend : backend.group
], google_compute_region_network_endpoint_group.webapp[0].self_link)
error_message = "The default backend service group should be configured to use the created network_endpoint_group."
}
assert {
condition = module.webapp_http_load_balancer[0].http_proxy != null
error_message = "A http proxy resource should be created by the load balancer module."
}
assert {
condition = module.webapp_http_load_balancer[0].https_proxy != null
error_message = "A https proxy resource should be created by the load balancer module."
}
}
run "test_service_with_load_balancer_enabled_and_ingress_set_to_allow_all" {
variables {
name = run.setup.random_name
enable_load_balancer = true
ingress = "INGRESS_TRAFFIC_ALL"
dns_names = {
webapp = "${run.setup.random_name}.test.example.gcp.uis.cam.ac.uk"
}
containers = {
webapp = {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
}
assert {
condition = google_cloud_run_v2_service.webapp.ingress == "INGRESS_TRAFFIC_ALL"
error_message = "Ingress should be 'INGRESS_TRAFFIC_ALL'."
}
}
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
run "test_service_with_load_balancer_enabled_and_load_balancer_backend_overrides" {
variables {
name = run.setup.random_name
enable_load_balancer = true
dns_names = {
webapp = "${run.setup.random_name}.test.example.gcp.uis.cam.ac.uk"
}
load_balancer_backend = {
description = "Lift, Load, Balance!"
log_config = {
enable = true
sample_rate = 0.5
}
}
containers = {
webapp = {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
}
assert {
condition = module.webapp_http_load_balancer[0].backend_services["default"].log_config[0].sample_rate == 0.5
error_message = "The default backend service log sample rate should be '0.5'."
}
assert {
condition = module.webapp_http_load_balancer[0].backend_services["default"].description == "Lift, Load, Balance!"
error_message = "The default backend service description should be 'Lift, Load, Balance!'."
}
}