Skip to content

Commit 5769f82

Browse files
Treat skip_initial_version_creation as a create-only parameter for Cloud KMS keys (#14802) (#23984)
[upstream:09ea20ad848581c4ac7d98371ec8737624580b41] Signed-off-by: Modular Magician <[email protected]>
1 parent b9428f8 commit 5769f82

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

.changelog/14802.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
kms: `skip_initial_version_creation` field is no longer immutable in `google_kms_crypto_key`, but is still only settable at-creation
3+
```

google/services/kms/resource_kms_crypto_key.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ letter 's' (seconds). It must be greater than a day (ie, 86400).`,
137137
"skip_initial_version_creation": {
138138
Type: schema.TypeBool,
139139
Optional: true,
140-
ForceNew: true,
141140
Description: `If set to true, the request will create a CryptoKey without any CryptoKeyVersions.
142141
You must use the 'google_kms_crypto_key_version' resource to create a new CryptoKeyVersion
143-
or 'google_kms_key_ring_import_job' resource to import the CryptoKeyVersion.`,
142+
or 'google_kms_key_ring_import_job' resource to import the CryptoKeyVersion.
143+
This field is only applicable during initial CryptoKey creation.`,
144144
},
145145
"version_template": {
146146
Type: schema.TypeList,
@@ -530,10 +530,6 @@ func resourceKMSCryptoKeyImport(d *schema.ResourceData, meta interface{}) ([]*sc
530530
return nil, fmt.Errorf("Error setting name: %s", err)
531531
}
532532

533-
if err := d.Set("skip_initial_version_creation", false); err != nil {
534-
return nil, fmt.Errorf("Error setting skip_initial_version_creation: %s", err)
535-
}
536-
537533
id, err := tpgresource.ReplaceVars(d, config, "{{key_ring}}/cryptoKeys/{{name}}")
538534
if err != nil {
539535
return nil, fmt.Errorf("Error constructing id: %s", err)

google/services/kms/resource_kms_crypto_key_test.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ func TestAccKmsCryptoKey_basic(t *testing.T) {
174174
ResourceName: "google_kms_crypto_key.crypto_key",
175175
ImportState: true,
176176
ImportStateVerify: true,
177-
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
177+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation", "labels", "terraform_labels"},
178178
},
179179
// Test importing with a short id
180180
{
181181
ResourceName: "google_kms_crypto_key.crypto_key",
182182
ImportState: true,
183183
ImportStateId: fmt.Sprintf("%s/%s/%s/%s", projectId, location, keyRingName, cryptoKeyName),
184184
ImportStateVerify: true,
185-
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
185+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation", "labels", "terraform_labels"},
186186
},
187187
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
188188
{
@@ -219,25 +219,28 @@ func TestAccKmsCryptoKey_rotation(t *testing.T) {
219219
Config: testGoogleKmsCryptoKey_rotation(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, rotationPeriod),
220220
},
221221
{
222-
ResourceName: "google_kms_crypto_key.crypto_key",
223-
ImportState: true,
224-
ImportStateVerify: true,
222+
ResourceName: "google_kms_crypto_key.crypto_key",
223+
ImportState: true,
224+
ImportStateVerify: true,
225+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
225226
},
226227
{
227228
Config: testGoogleKmsCryptoKey_rotation(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, updatedRotationPeriod),
228229
},
229230
{
230-
ResourceName: "google_kms_crypto_key.crypto_key",
231-
ImportState: true,
232-
ImportStateVerify: true,
231+
ResourceName: "google_kms_crypto_key.crypto_key",
232+
ImportState: true,
233+
ImportStateVerify: true,
234+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
233235
},
234236
{
235237
Config: testGoogleKmsCryptoKey_rotationRemoved(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName),
236238
},
237239
{
238-
ResourceName: "google_kms_crypto_key.crypto_key",
239-
ImportState: true,
240-
ImportStateVerify: true,
240+
ResourceName: "google_kms_crypto_key.crypto_key",
241+
ImportState: true,
242+
ImportStateVerify: true,
243+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
241244
},
242245
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
243246
{
@@ -272,17 +275,19 @@ func TestAccKmsCryptoKey_template(t *testing.T) {
272275
Config: testGoogleKmsCryptoKey_template(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, algorithm),
273276
},
274277
{
275-
ResourceName: "google_kms_crypto_key.crypto_key",
276-
ImportState: true,
277-
ImportStateVerify: true,
278+
ResourceName: "google_kms_crypto_key.crypto_key",
279+
ImportState: true,
280+
ImportStateVerify: true,
281+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
278282
},
279283
{
280284
Config: testGoogleKmsCryptoKey_template(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, updatedAlgorithm),
281285
},
282286
{
283-
ResourceName: "google_kms_crypto_key.crypto_key",
284-
ImportState: true,
285-
ImportStateVerify: true,
287+
ResourceName: "google_kms_crypto_key.crypto_key",
288+
ImportState: true,
289+
ImportStateVerify: true,
290+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
286291
},
287292
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
288293
{
@@ -318,7 +323,7 @@ func TestAccKmsCryptoKey_destroyDuration(t *testing.T) {
318323
ResourceName: "google_kms_crypto_key.crypto_key",
319324
ImportState: true,
320325
ImportStateVerify: true,
321-
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
326+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation", "labels", "terraform_labels"},
322327
},
323328
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
324329
{

website/docs/r/kms_crypto_key.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ The following arguments are supported:
155155
If set to true, the request will create a CryptoKey without any CryptoKeyVersions.
156156
You must use the `google_kms_crypto_key_version` resource to create a new CryptoKeyVersion
157157
or `google_kms_key_ring_import_job` resource to import the CryptoKeyVersion.
158+
This field is only applicable during initial CryptoKey creation.
158159

159160

160161

0 commit comments

Comments
 (0)