@@ -22,6 +22,35 @@ resource "google_compute_ssl_certificate" "default" {
22
22
description = "a description"
23
23
private_key = "${file("path/to/private.key")}"
24
24
certificate = "${file("path/to/certificate.crt")}"
25
+
26
+ lifecycle {
27
+ create_before_destroy = true
28
+ }
29
+ }
30
+
31
+ # You may also want to control name generation explicitly:
32
+
33
+ resource "random_id" "certificate" {
34
+ byte_length = 4
35
+ prefix = "my-certificate-"
36
+
37
+ # For security, do not expose raw certificate values in the output
38
+ keepers {
39
+ private_key = "${base64sha256(file("path/to/private.key"))}"
40
+ certificate = "${base64sha256(file("path/to/certificate.crt"))}"
41
+ }
42
+ }
43
+
44
+ resource "google_compute_ssl_certificate" "default" {
45
+ # The name will contain 8 random hex digits,
46
+ # e.g. "my-certificate-48ab27cd2a"
47
+ name = "${random_id.certificate.hex}"
48
+ private_key = "${file("path/to/private.key")}"
49
+ certificate = "${file("path/to/certificate.crt")}"
50
+
51
+ lifecycle {
52
+ create_before_destroy = true
53
+ }
25
54
}
26
55
```
27
56
@@ -32,8 +61,8 @@ specified configuration, Terraform will destroy the existing resource
32
61
and create a replacement. To effectively use an SSL certificate resource
33
62
with a [ Target HTTPS Proxy resource] [ 1 ] , it's recommended to specify
34
63
` create_before_destroy ` in a [ lifecycle] [ 2 ] block. Either omit the
35
- Instance Template ` name ` attribute, or specify a partial name with
36
- ` name_prefix ` . Example:
64
+ Instance Template ` name ` attribute, specify a partial name with
65
+ ` name_prefix ` , or use [ random_id ] [ 3 ] resource . Example:
37
66
38
67
``` hcl
39
68
resource "google_compute_ssl_certificate" "default" {
@@ -90,6 +119,7 @@ exported:
90
119
91
120
[ 1 ] : /docs/providers/google/r/compute_target_https_proxy.html
92
121
[ 2 ] : /docs/configuration/resources.html#lifecycle
122
+ [ 3 ] : /docs/providers/random/r/id.html
93
123
94
124
## Import
95
125
0 commit comments