Skip to content

Commit d1c89b9

Browse files
authored
fix!: Fix certificate map issue. Allow adding different types of certificates together. (#382)
1 parent 34fbda9 commit d1c89b9

File tree

40 files changed

+1650
-167
lines changed

40 files changed

+1650
-167
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Current version is 9.0. Upgrade guides:
3434
- [6.X -> 7.0](/docs/upgrading_to_v7.0.md)
3535
- [7.X -> 8.0](/docs/upgrading_to_v8.0.md)
3636
- [8.X -> 9.0](/docs/upgrading_to_v9.0.md)
37-
37+
- [9.X -> 10.0](/docs/upgrading_to_v10.0.m)
3838

3939
## Usage
4040

@@ -121,10 +121,11 @@ module "gce-lb-http" {
121121
|------|-------------|------|---------|:--------:|
122122
| address | Existing IPv4 address to use (the actual IP address value) | `string` | `null` | no |
123123
| backends | Map backend indices to list of backend maps. | <pre>map(object({<br> port = optional(number)<br> project = optional(string)<br> protocol = optional(string)<br> port_name = optional(string)<br> description = optional(string)<br> enable_cdn = optional(bool)<br> compression_mode = optional(string)<br> security_policy = optional(string, null)<br> edge_security_policy = optional(string, null)<br> custom_request_headers = optional(list(string))<br> custom_response_headers = optional(list(string))<br><br> timeout_sec = optional(number)<br> connection_draining_timeout_sec = optional(number)<br> session_affinity = optional(string)<br> affinity_cookie_ttl_sec = optional(number)<br><br> health_check = object({<br> host = optional(string)<br> request_path = optional(string)<br> request = optional(string)<br> response = optional(string)<br> port = optional(number)<br> port_name = optional(string)<br> proxy_header = optional(string)<br> port_specification = optional(string)<br> protocol = optional(string)<br> check_interval_sec = optional(number)<br> timeout_sec = optional(number)<br> healthy_threshold = optional(number)<br> unhealthy_threshold = optional(number)<br> logging = optional(bool)<br> })<br><br> log_config = object({<br> enable = optional(bool)<br> sample_rate = optional(number)<br> })<br><br> groups = list(object({<br> group = string<br><br> balancing_mode = optional(string)<br> capacity_scaler = optional(number)<br> description = optional(string)<br> max_connections = optional(number)<br> max_connections_per_instance = optional(number)<br> max_connections_per_endpoint = optional(number)<br> max_rate = optional(number)<br> max_rate_per_instance = optional(number)<br> max_rate_per_endpoint = optional(number)<br> max_utilization = optional(number)<br> }))<br> iap_config = object({<br> enable = bool<br> oauth2_client_id = optional(string)<br> oauth2_client_secret = optional(string)<br> })<br> cdn_policy = optional(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> negative_caching_policy = optional(object({<br> code = optional(number)<br> ttl = optional(number)<br> }))<br> serve_while_stale = optional(number)<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> }))<br> outlier_detection = optional(object({<br> base_ejection_time = optional(object({<br> seconds = number<br> nanos = optional(number)<br> }))<br> consecutive_errors = optional(number)<br> consecutive_gateway_failure = optional(number)<br> enforcing_consecutive_errors = optional(number)<br> enforcing_consecutive_gateway_failure = optional(number)<br> enforcing_success_rate = optional(number)<br> interval = optional(object({<br> seconds = number<br> nanos = optional(number)<br> }))<br> max_ejection_percent = optional(number)<br> success_rate_minimum_hosts = optional(number)<br> success_rate_request_volume = optional(number)<br> success_rate_stdev_factor = optional(number)<br> }))<br> }))</pre> | n/a | yes |
124-
| certificate | Content of the SSL certificate. Required if `ssl` is `true` and `ssl_certificates` is empty. | `string` | `null` | no |
125-
| certificate\_map | Certificate Map ID in format projects/{project}/locations/global/certificateMaps/{name}. Identifies a certificate map associated with the given target proxy | `string` | `null` | no |
124+
| certificate | Content of the SSL certificate. Requires `ssl` to be set to `true` and `create_ssl_certificate` set to `true` | `string` | `null` | no |
125+
| certificate\_map | Certificate Map ID in format projects/{project}/locations/global/certificateMaps/{name}. Identifies a certificate map associated with the given target proxy. Requires `ssl` to be set to `true` | `string` | `null` | no |
126126
| create\_address | Create a new global IPv4 address | `bool` | `true` | no |
127127
| create\_ipv6\_address | Allocate a new IPv6 address. Conflicts with "ipv6\_address" - if both specified, "create\_ipv6\_address" takes precedence. | `bool` | `false` | no |
128+
| create\_ssl\_certificate | If `true`, Create certificate using `private_key/certificate` | `bool` | `false` | no |
128129
| create\_url\_map | Set to `false` if url\_map variable is provided. | `bool` | `true` | no |
129130
| edge\_security\_policy | The resource URL for the edge security policy to associate with the backend service | `string` | `null` | no |
130131
| enable\_ipv6 | Enable IPv6 address on the CDN load-balancer | `bool` | `false` | no |
@@ -135,21 +136,20 @@ module "gce-lb-http" {
135136
| ipv6\_address | An existing IPv6 address to use (the actual IP address value) | `string` | `null` | no |
136137
| labels | The labels to attach to resources created by this module | `map(string)` | `{}` | no |
137138
| load\_balancing\_scheme | Load balancing scheme type (EXTERNAL for classic external load balancer, EXTERNAL\_MANAGED for Envoy-based load balancer, and INTERNAL\_SELF\_MANAGED for traffic director) | `string` | `"EXTERNAL"` | no |
138-
| managed\_ssl\_certificate\_domains | Create Google-managed SSL certificates for specified domains. Requires `ssl` to be set to `true` and `use_ssl_certificates` set to `false`. | `list(string)` | `[]` | no |
139+
| managed\_ssl\_certificate\_domains | Create Google-managed SSL certificates for specified domains. Requires `ssl` to be set to `true` | `list(string)` | `[]` | no |
139140
| name | Name for the forwarding rule and prefix for supporting resources | `string` | n/a | yes |
140141
| network | Network for INTERNAL\_SELF\_MANAGED load balancing scheme | `string` | `"default"` | no |
141-
| private\_key | Content of the private SSL key. Required if `ssl` is `true` and `ssl_certificates` is empty. | `string` | `null` | no |
142+
| private\_key | Content of the private SSL key. Requires `ssl` to be set to `true` and `create_ssl_certificate` set to `true` | `string` | `null` | no |
142143
| project | The project to deploy to, if not set the default provider project is used. | `string` | n/a | yes |
143144
| quic | Specifies the QUIC override policy for this resource. Set true to enable HTTP/3 and Google QUIC support, false to disable both. Defaults to null which enables support for HTTP/3 only. | `bool` | `null` | no |
144145
| random\_certificate\_suffix | Bool to enable/disable random certificate name generation. Set and keep this to true if you need to change the SSL cert. | `bool` | `false` | no |
145146
| security\_policy | The resource URL for the security policy to associate with the backend service | `string` | `null` | no |
146-
| ssl | Set to `true` to enable SSL support, requires variable `ssl_certificates` - a list of self\_link certs | `bool` | `false` | no |
147-
| ssl\_certificates | SSL cert self\_link list. Required if `ssl` is `true` and no `private_key` and `certificate` is provided. | `list(string)` | `[]` | no |
147+
| ssl | Set to `true` to enable SSL support. If `true` then at least one of these are required: 1) `ssl_certificates` OR 2) `create_ssl_certificate` set to `true` and `private_key/certificate` OR 3) `managed_ssl_certificate_domains`, OR 4) `certificate_map` | `bool` | `false` | no |
148+
| ssl\_certificates | SSL cert self\_link list. Requires `ssl` to be set to `true` | `list(string)` | `[]` | no |
148149
| ssl\_policy | Selfink to SSL Policy | `string` | `null` | no |
149150
| target\_service\_accounts | List of target service accounts for health check firewall rule. Exactly one of target\_tags or target\_service\_accounts should be specified. | `list(string)` | `[]` | no |
150151
| target\_tags | List of target tags for health check firewall rule. Exactly one of target\_tags or target\_service\_accounts should be specified. | `list(string)` | `[]` | no |
151152
| url\_map | The url\_map resource to use. Default is to send all traffic to first backend. | `string` | `null` | no |
152-
| use\_ssl\_certificates | If true, use the certificates provided by `ssl_certificates`, otherwise, create cert from `private_key` and `certificate` | `bool` | `false` | no |
153153

154154
## Outputs
155155

@@ -161,6 +161,7 @@ module "gce-lb-http" {
161161
| http\_proxy | The HTTP proxy used by this module. |
162162
| https\_proxy | The HTTPS proxy used by this module. |
163163
| ipv6\_enabled | Whether IPv6 configuration is enabled on this load-balancer |
164+
| ssl\_certificate\_created | The SSL certificate create from key/pem |
164165
| url\_map | The default URL map used by this module. |
165166

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

autogen/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Current version is 9.0. Upgrade guides:
5050
- [6.X -> 7.0](/docs/upgrading_to_v7.0.md)
5151
- [7.X -> 8.0](/docs/upgrading_to_v8.0.md)
5252
- [8.X -> 9.0](/docs/upgrading_to_v9.0.md)
53-
53+
- [9.X -> 10.0](/docs/upgrading_to_v10.0.m)
5454

5555
## Usage
5656

autogen/main.tf.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ resource "google_compute_global_forwarding_rule" "http" {
4747
resource "google_compute_global_forwarding_rule" "https" {
4848
provider = google-beta
4949
project = var.project
50-
count = var.ssl || var.certificate_map != null ? 1 : 0
50+
count = var.ssl ? 1 : 0
5151
name = "${var.name}-https"
5252
target = google_compute_target_https_proxy.default[0].self_link
5353
ip_address = local.address
@@ -84,7 +84,7 @@ resource "google_compute_global_forwarding_rule" "http_ipv6" {
8484
resource "google_compute_global_forwarding_rule" "https_ipv6" {
8585
provider = google-beta
8686
project = var.project
87-
count = var.enable_ipv6 && (var.ssl || var.certificate_map != null) ? 1 : 0
87+
count = var.enable_ipv6 && var.ssl ? 1 : 0
8888
name = "${var.name}-ipv6-https"
8989
target = google_compute_target_https_proxy.default[0].self_link
9090
ip_address = local.ipv6_address
@@ -115,7 +115,7 @@ resource "google_compute_target_http_proxy" "default" {
115115
# HTTPS proxy when ssl is true
116116
resource "google_compute_target_https_proxy" "default" {
117117
project = var.project
118-
count = var.ssl || var.certificate_map != null ? 1 : 0
118+
count = var.ssl ? 1 : 0
119119
name = "${var.name}-https-proxy"
120120
url_map = local.url_map
121121

@@ -127,7 +127,7 @@ resource "google_compute_target_https_proxy" "default" {
127127

128128
resource "google_compute_ssl_certificate" "default" {
129129
project = var.project
130-
count = var.ssl && length(var.managed_ssl_certificate_domains) == 0 && !var.use_ssl_certificates ? 1 : 0
130+
count = var.ssl && var.create_ssl_certificate ? 1 : 0
131131
name_prefix = "${var.name}-certificate-"
132132
private_key = var.private_key
133133
certificate = var.certificate
@@ -150,7 +150,7 @@ resource "random_id" "certificate" {
150150
resource "google_compute_managed_ssl_certificate" "default" {
151151
provider = google-beta
152152
project = var.project
153-
count = var.ssl && length(var.managed_ssl_certificate_domains) > 0 && !var.use_ssl_certificates ? 1 : 0
153+
count = var.ssl && length(var.managed_ssl_certificate_domains) > 0 ? 1 : 0
154154
name = var.random_certificate_suffix == true ? random_id.certificate[0].hex : "${var.name}-cert"
155155

156156
lifecycle {

autogen/outputs.tf.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ output "url_map" {
4949
description = "The default URL map used by this module."
5050
value = google_compute_url_map.default[*].self_link
5151
}
52+
53+
output "ssl_certificate_created" {
54+
description = "The SSL certificate create from key/pem"
55+
value = google_compute_ssl_certificate.default.*.self_link
56+
}

autogen/variables.tf.tmpl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -215,51 +215,57 @@ variable "http_forward" {
215215
}
216216

217217
variable "ssl" {
218-
description = "Set to `true` to enable SSL support, requires variable `ssl_certificates` - a list of self_link certs"
218+
description = "Set to `true` to enable SSL support. If `true` then at least one of these are required: 1) `ssl_certificates` OR 2) `create_ssl_certificate` set to `true` and `private_key/certificate` OR 3) `managed_ssl_certificate_domains`, OR 4) `certificate_map`"
219219
type = bool
220220
default = false
221221
}
222222

223-
variable "ssl_policy" {
224-
type = string
225-
description = "Selfink to SSL Policy"
226-
default = null
223+
variable "create_ssl_certificate" {
224+
description = "If `true`, Create certificate using `private_key/certificate`"
225+
type = bool
226+
default = false
227227
}
228228

229-
variable "quic" {
230-
type = bool
231-
description = "Specifies the QUIC override policy for this resource. Set true to enable HTTP/3 and Google QUIC support, false to disable both. Defaults to null which enables support for HTTP/3 only."
232-
default = null
229+
variable "ssl_certificates" {
230+
description = "SSL cert self_link list. Requires `ssl` to be set to `true`"
231+
type = list(string)
232+
default = []
233233
}
234234

235235
variable "private_key" {
236-
description = "Content of the private SSL key. Required if `ssl` is `true` and `ssl_certificates` is empty."
236+
description = "Content of the private SSL key. Requires `ssl` to be set to `true` and `create_ssl_certificate` set to `true`"
237237
type = string
238238
default = null
239239
}
240240

241241
variable "certificate" {
242-
description = "Content of the SSL certificate. Required if `ssl` is `true` and `ssl_certificates` is empty."
242+
description = "Content of the SSL certificate. Requires `ssl` to be set to `true` and `create_ssl_certificate` set to `true`"
243243
type = string
244244
default = null
245245
}
246246

247247
variable "managed_ssl_certificate_domains" {
248-
description = "Create Google-managed SSL certificates for specified domains. Requires `ssl` to be set to `true` and `use_ssl_certificates` set to `false`."
248+
description = "Create Google-managed SSL certificates for specified domains. Requires `ssl` to be set to `true`"
249249
type = list(string)
250250
default = []
251251
}
252252

253-
variable "use_ssl_certificates" {
254-
description = "If true, use the certificates provided by `ssl_certificates`, otherwise, create cert from `private_key` and `certificate`"
255-
type = bool
256-
default = false
253+
variable "certificate_map" {
254+
description = "Certificate Map ID in format projects/{project}/locations/global/certificateMaps/{name}. Identifies a certificate map associated with the given target proxy. Requires `ssl` to be set to `true`"
255+
type = string
256+
default = null
257257
}
258258

259-
variable "ssl_certificates" {
260-
description = "SSL cert self_link list. Required if `ssl` is `true` and no `private_key` and `certificate` is provided."
261-
type = list(string)
262-
default = []
259+
variable "ssl_policy" {
260+
type = string
261+
description = "Selfink to SSL Policy"
262+
default = null
263+
}
264+
265+
variable "quic" {
266+
type = bool
267+
description = "Specifies the QUIC override policy for this resource. Set true to enable HTTP/3 and Google QUIC support, false to disable both. Defaults to null which enables support for HTTP/3 only."
268+
default = null
263269
}
264270

265271
variable "edge_security_policy" {
@@ -298,12 +304,6 @@ variable "load_balancing_scheme" {
298304
default = "EXTERNAL"
299305
}
300306

301-
variable "certificate_map" {
302-
description = "Certificate Map ID in format projects/{project}/locations/global/certificateMaps/{name}. Identifies a certificate map associated with the given target proxy"
303-
type = string
304-
default = null
305-
}
306-
307307
variable "network" {
308308
description = "Network for INTERNAL_SELF_MANAGED load balancing scheme"
309309
type = string

build/int.cloudbuild.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
timeout: 4200s
15+
timeout: 5400s
1616
steps:
1717
- id: swap-module-refs
1818
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
@@ -62,6 +62,32 @@ steps:
6262
- id: traffic-director-example-teardown
6363
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
6464
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/traffic-director --stage teardown --verbose']
65+
# certificate-map example
66+
- id: certificate-map-example-init
67+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
68+
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/certificate-map --stage init --verbose']
69+
- id: certificate-map-example-apply
70+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
71+
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/certificate-map --stage apply --verbose']
72+
- id: certificate-map-example-verify
73+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
74+
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/certificate-map --stage verify --verbose']
75+
- id: certificate-map-example-teardown
76+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
77+
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/certificate-map --stage teardown --verbose']
78+
# managed-manual-certificates example
79+
- id: user-managed-google-managed-ssl-example-init
80+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
81+
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/user-managed-google-managed-ssl --stage init --verbose']
82+
- id: user-managed-google-managed-ssl-example-apply
83+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
84+
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/user-managed-google-managed-ssl --stage apply --verbose']
85+
- id: user-managed-google-managed-ssl-example-verify
86+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
87+
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/user-managed-google-managed-ssl --stage verify --verbose']
88+
- id: user-managed-google-managed-ssl-example-teardown
89+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
90+
args: ['/bin/bash', '-c', 'cft test run TestAll/examples/user-managed-google-managed-ssl --stage teardown --verbose']
6591
tags:
6692
- 'ci'
6793
- 'integration'

0 commit comments

Comments
 (0)