Skip to content

Commit

Permalink
Made kms crypto key import set id correctly (#6305) (#12164)
Browse files Browse the repository at this point in the history
Resolved #12056

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 22, 2022
1 parent c2f709d commit 6cffceb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/6305.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
kms: fixed setting of resource id post-import for `google_kms_crypto_key`
```
6 changes: 6 additions & 0 deletions google/resource_kms_crypto_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ func resourceKMSCryptoKeyImport(d *schema.ResourceData, meta interface{}) ([]*sc
return nil, fmt.Errorf("Error setting skip_initial_version_creation: %s", err)
}

id, err := replaceVars(d, config, "{{key_ring}}/cryptoKeys/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return []*schema.ResourceData{d}, nil
}

Expand Down
7 changes: 7 additions & 0 deletions google/resource_kms_crypto_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ func TestAccKmsCryptoKey_basic(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
// Test importing with a short id
{
ResourceName: "google_kms_crypto_key.crypto_key",
ImportState: true,
ImportStateId: fmt.Sprintf("%s/%s/%s/%s", projectId, location, keyRingName, cryptoKeyName),
ImportStateVerify: true,
},
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
{
Config: testGoogleKmsCryptoKey_removed(projectId, projectOrg, projectBillingAccount, keyRingName),
Expand Down

0 comments on commit 6cffceb

Please sign in to comment.