Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bigtable: Check ForceNew for kms_key_name field in the diff function #13018

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6765.txt
@@ -0,0 +1,3 @@
```release-note:bug
bigtable: update checking ForceNew logic for `kms_key_name`
```
9 changes: 8 additions & 1 deletion google/resource_bigtable_instance.go
Expand Up @@ -81,7 +81,6 @@ func resourceBigtableInstance() *schema.Resource {
"kms_key_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Description: `Describes the Cloud KMS encryption key that will be used to protect the destination Bigtable cluster. The requirements for this key are: 1) The Cloud Bigtable service account associated with the project that contains this cluster must be granted the cloudkms.cryptoKeyEncrypterDecrypter role on the CMEK key. 2) Only regional keys can be used and the region of the CMEK key must match the region of the cluster. 3) All clusters within an instance must use the same CMEK key. Values are of the form projects/{project}/locations/{location}/keyRings/{keyring}/cryptoKeys/{key}`,
},
Expand Down Expand Up @@ -561,6 +560,14 @@ func resourceBigtableInstanceClusterReorderTypeList(_ context.Context, diff *sch
return fmt.Errorf("Error setting cluster diff: %s", err)
}
}

oKey, nKey := diff.GetChange(fmt.Sprintf("cluster.%d.kms_key_name", i))
if oKey != nKey {
err := diff.ForceNew(fmt.Sprintf("cluster.%d.kms_key_name", i))
if err != nil {
return fmt.Errorf("Error setting cluster diff: %s", err)
}
}
}

return nil
Expand Down
11 changes: 9 additions & 2 deletions google/resource_bigtable_instance_test.go
Expand Up @@ -172,7 +172,8 @@ func TestAccBigtableInstance_kms(t *testing.T) {
skipIfVcr(t)
t.Parallel()

kms := BootstrapKMSKeyInLocation(t, "us-central1")
kms1 := BootstrapKMSKeyInLocation(t, "us-central1")
kms2 := BootstrapKMSKeyInLocation(t, "us-east1")
pid := getTestProjectFromEnv()
instanceName := fmt.Sprintf("tf-test-%s", randString(t, 10))

Expand All @@ -182,14 +183,20 @@ func TestAccBigtableInstance_kms(t *testing.T) {
CheckDestroy: testAccCheckBigtableInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigtableInstance_kms(pid, instanceName, kms.CryptoKey.Name, 3),
Config: testAccBigtableInstance_kms(pid, instanceName, kms1.CryptoKey.Name, 3),
},
{
ResourceName: "google_bigtable_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection", "instance_type"}, // we don't read instance type back
},
// TODO(kevinsi4508): Verify that the instance can be recreated due to `kms_key_name` change.
{
Config: testAccBigtableInstance_kms(pid, instanceName, kms2.CryptoKey.Name, 3),
PlanOnly: true,
ExpectNonEmptyPlan: true,
},
},
})
}
Expand Down
6 changes: 2 additions & 4 deletions website/docs/r/bigtable_instance.html.markdown
Expand Up @@ -131,11 +131,9 @@ for a `DEVELOPMENT` instance.

* `kms_key_name` - (Optional) Describes the Cloud KMS encryption key that will be used to protect the destination Bigtable cluster. The requirements for this key are: 1) The Cloud Bigtable service account associated with the project that contains this cluster must be granted the `cloudkms.cryptoKeyEncrypterDecrypter` role on the CMEK key. 2) Only regional keys can be used and the region of the CMEK key must match the region of the cluster.

!> **Warning**: Modifying this field will cause Terraform to delete/recreate the entire resource.
-> **Note**: Removing the field entirely from the config will cause the provider to default to the backend value.

-> **Note**: To remove this field once it is set, set the value to an empty string. Removing the field entirely from the config will cause the provider to default to the backend value.

!> **Warning:** Modifying the `storage_type` or `zone` of an existing cluster (by
!> **Warning:** Modifying the `storage_type`, `zone` or `kms_key_name` of an existing cluster (by
`cluster_id`) will cause Terraform to delete/recreate the entire
`google_bigtable_instance` resource. If these values are changing, use a new
`cluster_id`.
Expand Down