-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
resource_privateca_certificate_test.go
214 lines (205 loc) · 5.03 KB
/
resource_privateca_certificate_test.go
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package google
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccPrivatecaCertificate_privatecaCertificateUpdate(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"pool_name": BootstrapSharedCaPoolInLocation(t, "us-central1"),
"pool_location": "us-central1",
"deletion_protection": false,
"random_suffix": randString(t, 10),
}
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPrivatecaCertificateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccPrivatecaCertificate_privatecaCertificateStart(context),
},
{
ResourceName: "google_privateca_certificate.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"pool", "name", "location", "certificate_authority"},
},
{
Config: testAccPrivatecaCertificate_privatecaCertificateEnd(context),
},
{
ResourceName: "google_privateca_certificate.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"pool", "name", "location", "certificate_authority"},
},
{
Config: testAccPrivatecaCertificate_privatecaCertificateStart(context),
},
{
ResourceName: "google_privateca_certificate.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"pool", "name", "location", "certificate_authority"},
},
},
})
}
func testAccPrivatecaCertificate_privatecaCertificateStart(context map[string]interface{}) string {
return Nprintf(`
resource "google_privateca_certificate_authority" "default" {
// This example assumes this pool already exists.
// Pools cannot be deleted in normal test circumstances, so we depend on static pools
pool = "%{pool_name}"
certificate_authority_id = "tf-test-my-certificate-authority-%{random_suffix}"
location = "%{pool_location}"
deletion_protection = false
skip_grace_period = true
config {
subject_config {
subject {
organization = "HashiCorp"
common_name = "my-certificate-authority"
}
subject_alt_name {
dns_names = ["hashicorp.com"]
}
}
x509_config {
ca_options {
is_ca = true
max_issuer_path_length = 10
}
key_usage {
base_key_usage {
cert_sign = true
crl_sign = true
}
extended_key_usage {}
}
}
}
lifetime = "86400s"
key_spec {
algorithm = "RSA_PKCS1_4096_SHA256"
}
}
resource "google_privateca_certificate" "default" {
pool = "%{pool_name}"
location = "%{pool_location}"
certificate_authority = google_privateca_certificate_authority.default.certificate_authority_id
lifetime = "860s"
name = "my-certificate-%{random_suffix}"
config {
subject_config {
subject {
common_name = "san1.example.com"
organization = "HashiCorp"
}
subject_alt_name {
email_addresses = ["email@example.com"]
}
}
x509_config {
ca_options {
is_ca = false
}
key_usage {
base_key_usage {
crl_sign = false
decipher_only = false
}
extended_key_usage {
server_auth = false
}
}
}
public_key {
format = "PEM"
key = filebase64("test-fixtures/rsa_public.pem")
}
}
}
`, context)
}
func testAccPrivatecaCertificate_privatecaCertificateEnd(context map[string]interface{}) string {
return Nprintf(`
resource "google_privateca_certificate_authority" "default" {
// This example assumes this pool already exists.
// Pools cannot be deleted in normal test circumstances, so we depend on static pools
pool = "%{pool_name}"
certificate_authority_id = "tf-test-my-certificate-authority-%{random_suffix}"
location = "%{pool_location}"
deletion_protection = false
skip_grace_period = true
config {
subject_config {
subject {
organization = "HashiCorp"
common_name = "my-certificate-authority"
}
subject_alt_name {
dns_names = ["hashicorp.com"]
}
}
x509_config {
ca_options {
is_ca = true
max_issuer_path_length = 10
}
key_usage {
base_key_usage {
cert_sign = true
crl_sign = true
}
extended_key_usage {}
}
}
}
lifetime = "86400s"
key_spec {
algorithm = "RSA_PKCS1_4096_SHA256"
}
}
resource "google_privateca_certificate" "default" {
pool = "%{pool_name}"
location = "%{pool_location}"
certificate_authority = google_privateca_certificate_authority.default.certificate_authority_id
lifetime = "860s"
name = "my-certificate-%{random_suffix}"
config {
subject_config {
subject {
common_name = "san1.example.com"
organization = "HashiCorp"
}
subject_alt_name {
email_addresses = ["email@example.com"]
}
}
x509_config {
ca_options {
is_ca = false
}
key_usage {
base_key_usage {
crl_sign = false
decipher_only = false
}
extended_key_usage {
server_auth = false
}
}
}
public_key {
format = "PEM"
key = filebase64("test-fixtures/rsa_public.pem")
}
}
labels = {
foo = "bar"
}
}
`, context)
}