删除google_kms_crypto_key资源时出现错误消息

时间:2020-05-04 14:58:29

标签: terraform terraform-provider-gcp google-cloud-kms

我正在与gcp terraform提供商管理kms密钥和密钥环

resource "google_kms_key_ring" "vault" {
  name     = "vault"
  location = "global"
}

resource "google_kms_crypto_key" "vault_init" {
  name            = "vault"
  key_ring        = google_kms_key_ring.vault.self_link
  rotation_period = "100000s" #
}

当我第一次运行它时,我能够成功创建密钥和密钥环,并且执行terraform destroy可以使terraform代码成功执行而没有任何错误。

下次我执行terraform apply时,我仅使用terraform import从GCP导入资源,代码执行就很好了。

但是一段时间后,某些密钥版本1被销毁。现在,每次执行terrafrom destroy时,都会出现以下错误

module.cluster_vault.google_kms_crypto_key.vault_init: Destroying... [id=projects/<MY-PROJECT>/locations/global/keyRings/vault/cryptoKeys/vault]

Error: googleapi: Error 400: The request cannot be fulfilled. Resource projects/<MY-PROJECT>/locations/global/keyRings/vault/cryptoKeys/vault/cryptoKeyVersions/1 has value DESTROYED in field crypto_key_version.state., failedPrecondition

是否有办法抑制此特定错误? KeyVersions 1-3被销毁。

enter image description here

1 个答案:

答案 0 :(得分:0)

当前,无法删除Cloud KMS资源。这完全违背了Terraform的期望行为,即完全破坏并重新创建资源。您将需要使用其他密钥名称或密钥环名称来继续。