Skip to content

Commit 6cffceb

Browse files
Made kms crypto key import set id correctly (#6305) (#12164)
Resolved #12056 Signed-off-by: Modular Magician <[email protected]>
1 parent c2f709d commit 6cffceb

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

.changelog/6305.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
kms: fixed setting of resource id post-import for `google_kms_crypto_key`
3+
```

google/resource_kms_crypto_key.go

+6
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,12 @@ func resourceKMSCryptoKeyImport(d *schema.ResourceData, meta interface{}) ([]*sc
423423
return nil, fmt.Errorf("Error setting skip_initial_version_creation: %s", err)
424424
}
425425

426+
id, err := replaceVars(d, config, "{{key_ring}}/cryptoKeys/{{name}}")
427+
if err != nil {
428+
return nil, fmt.Errorf("Error constructing id: %s", err)
429+
}
430+
d.SetId(id)
431+
426432
return []*schema.ResourceData{d}, nil
427433
}
428434

google/resource_kms_crypto_key_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ func TestAccKmsCryptoKey_basic(t *testing.T) {
187187
ImportState: true,
188188
ImportStateVerify: true,
189189
},
190+
// Test importing with a short id
191+
{
192+
ResourceName: "google_kms_crypto_key.crypto_key",
193+
ImportState: true,
194+
ImportStateId: fmt.Sprintf("%s/%s/%s/%s", projectId, location, keyRingName, cryptoKeyName),
195+
ImportStateVerify: true,
196+
},
190197
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
191198
{
192199
Config: testGoogleKmsCryptoKey_removed(projectId, projectOrg, projectBillingAccount, keyRingName),

0 commit comments

Comments
 (0)