Skip to content

Commit

Permalink
make database_encryption updateable (#3728) (#2259)
Browse files Browse the repository at this point in the history
* make datbase_encryption updateable

* add update test

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 8, 2020
1 parent ea82976 commit 4a38e72
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/3728.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
container: added the ability to update `database_encryption` without recreating the cluster.
```
28 changes: 25 additions & 3 deletions google-beta/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,21 +1016,18 @@ func resourceContainerCluster() *schema.Resource {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ForceNew: true,
Computed: true,
Description: `Application-layer Secrets Encryption settings. The object format is {state = string, key_name = string}. Valid values of state are: "ENCRYPTED"; "DECRYPTED". key_name is the name of a CloudKMS key.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"state": {
Type: schema.TypeString,
ForceNew: true,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"ENCRYPTED", "DECRYPTED"}, false),
Description: `ENCRYPTED or DECRYPTED.`,
},
"key_name": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Description: `The key to use to encrypt/decrypt secrets.`,
},
Expand Down Expand Up @@ -2098,6 +2095,31 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
}
}

if d.HasChange("database_encryption") {
c := d.Get("database_encryption")
req := &containerBeta.UpdateClusterRequest{
Update: &containerBeta.ClusterUpdate{
DesiredDatabaseEncryption: expandDatabaseEncryption(c),
},
}

updateF := func() error {
name := containerClusterFullName(project, location, clusterName)
op, err := config.clientContainerBeta.Projects.Locations.Clusters.Update(name, req).Do()
if err != nil {
return err
}
// Wait until it's updated
return containerOperationWait(config, op, project, location, "updating GKE cluster database encryption config", d.Timeout(schema.TimeoutUpdate))
}
if err := lockedCall(lockKey, updateF); err != nil {
return err
}
log.Printf("[INFO] GKE cluster %s database encryption config has been updated", d.Id())

d.SetPartial("database_encryption")
}

if d.HasChange("pod_security_policy_config") {
c := d.Get("pod_security_policy_config")
req := &containerBeta.UpdateClusterRequest{
Expand Down
12 changes: 10 additions & 2 deletions google-beta/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,15 @@ func TestAccContainerCluster_withDatabaseEncryption(t *testing.T) {
Config: testAccContainerCluster_withDatabaseEncryption(clusterName, kmsData),
},
{
ResourceName: "google_container_cluster.with_database_encryption",
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_basic(clusterName),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
},
Expand Down Expand Up @@ -3848,7 +3856,7 @@ resource "google_kms_key_ring_iam_policy" "test_key_ring_iam_policy" {
policy_data = data.google_iam_policy.test_kms_binding.policy_data
}
resource "google_container_cluster" "with_database_encryption" {
resource "google_container_cluster" "primary" {
name = "%[3]s"
location = "us-central1-a"
initial_node_count = 1
Expand Down

0 comments on commit 4a38e72

Please sign in to comment.