Skip to content

Commit 09ea20a

Browse files
authored
Treat skip_initial_version_creation as a create-only parameter for Cloud KMS keys (#14802)
1 parent db59fd3 commit 09ea20a

3 files changed

Lines changed: 27 additions & 25 deletions

File tree

mmv1/products/kms/CryptoKey.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ parameters:
7575
If set to true, the request will create a CryptoKey without any CryptoKeyVersions.
7676
You must use the `google_kms_crypto_key_version` resource to create a new CryptoKeyVersion
7777
or `google_kms_key_ring_import_job` resource to import the CryptoKeyVersion.
78+
This field is only applicable during initial CryptoKey creation.
7879
url_param_only: true
79-
immutable: true
80+
ignore_read: true
8081
properties:
8182
- name: 'name'
8283
type: String

mmv1/templates/terraform/custom_import/kms_crypto_key.go.tmpl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
return nil, fmt.Errorf("Error setting name: %s", err)
1414
}
1515

16-
if err := d.Set("skip_initial_version_creation", false); err != nil {
17-
return nil, fmt.Errorf("Error setting skip_initial_version_creation: %s", err)
18-
}
19-
2016
id, err := tpgresource.ReplaceVars(d, config, "{{$.GetIdFormat}}")
2117
if err != nil {
2218
return nil, fmt.Errorf("Error constructing id: %s", err)

mmv1/third_party/terraform/services/kms/resource_kms_crypto_key_test.go.tmpl

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ func TestAccKmsCryptoKey_basic(t *testing.T) {
158158
ResourceName: "google_kms_crypto_key.crypto_key",
159159
ImportState: true,
160160
ImportStateVerify: true,
161-
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
161+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation", "labels", "terraform_labels"},
162162
},
163163
// Test importing with a short id
164164
{
165165
ResourceName: "google_kms_crypto_key.crypto_key",
166166
ImportState: true,
167167
ImportStateId: fmt.Sprintf("%s/%s/%s/%s", projectId, location, keyRingName, cryptoKeyName),
168168
ImportStateVerify: true,
169-
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
169+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation", "labels", "terraform_labels"},
170170
},
171171
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
172172
{
@@ -203,25 +203,28 @@ func TestAccKmsCryptoKey_rotation(t *testing.T) {
203203
Config: testGoogleKmsCryptoKey_rotation(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, rotationPeriod),
204204
},
205205
{
206-
ResourceName: "google_kms_crypto_key.crypto_key",
207-
ImportState: true,
208-
ImportStateVerify: true,
206+
ResourceName: "google_kms_crypto_key.crypto_key",
207+
ImportState: true,
208+
ImportStateVerify: true,
209+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
209210
},
210211
{
211212
Config: testGoogleKmsCryptoKey_rotation(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, updatedRotationPeriod),
212213
},
213214
{
214-
ResourceName: "google_kms_crypto_key.crypto_key",
215-
ImportState: true,
216-
ImportStateVerify: true,
215+
ResourceName: "google_kms_crypto_key.crypto_key",
216+
ImportState: true,
217+
ImportStateVerify: true,
218+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
217219
},
218220
{
219221
Config: testGoogleKmsCryptoKey_rotationRemoved(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName),
220222
},
221223
{
222-
ResourceName: "google_kms_crypto_key.crypto_key",
223-
ImportState: true,
224-
ImportStateVerify: true,
224+
ResourceName: "google_kms_crypto_key.crypto_key",
225+
ImportState: true,
226+
ImportStateVerify: true,
227+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
225228
},
226229
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
227230
{
@@ -256,17 +259,19 @@ func TestAccKmsCryptoKey_template(t *testing.T) {
256259
Config: testGoogleKmsCryptoKey_template(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, algorithm),
257260
},
258261
{
259-
ResourceName: "google_kms_crypto_key.crypto_key",
260-
ImportState: true,
261-
ImportStateVerify: true,
262+
ResourceName: "google_kms_crypto_key.crypto_key",
263+
ImportState: true,
264+
ImportStateVerify: true,
265+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
262266
},
263267
{
264268
Config: testGoogleKmsCryptoKey_template(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, updatedAlgorithm),
265269
},
266270
{
267-
ResourceName: "google_kms_crypto_key.crypto_key",
268-
ImportState: true,
269-
ImportStateVerify: true,
271+
ResourceName: "google_kms_crypto_key.crypto_key",
272+
ImportState: true,
273+
ImportStateVerify: true,
274+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation"},
270275
},
271276
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
272277
{
@@ -302,7 +307,7 @@ func TestAccKmsCryptoKey_destroyDuration(t *testing.T) {
302307
ResourceName: "google_kms_crypto_key.crypto_key",
303308
ImportState: true,
304309
ImportStateVerify: true,
305-
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
310+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation", "labels", "terraform_labels"},
306311
},
307312
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
308313
{
@@ -344,7 +349,7 @@ func TestAccKmsCryptoKey_keyAccessJustificationsPolicy(t *testing.T) {
344349
ResourceName: "google_kms_crypto_key.crypto_key",
345350
ImportState: true,
346351
ImportStateVerify: true,
347-
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
352+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation", "labels", "terraform_labels"},
348353
},
349354
{
350355
Config: testGoogleKmsCryptoKey_keyAccessJustificationsPolicy(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, updatedAllowedAccessReason),
@@ -353,7 +358,7 @@ func TestAccKmsCryptoKey_keyAccessJustificationsPolicy(t *testing.T) {
353358
ResourceName: "google_kms_crypto_key.crypto_key",
354359
ImportState: true,
355360
ImportStateVerify: true,
356-
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
361+
ImportStateVerifyIgnore: []string{"skip_initial_version_creation", "labels", "terraform_labels"},
357362
},
358363
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
359364
{

0 commit comments

Comments
 (0)