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

Add DeletionProtectionEnabled to Redis Cluster #10367

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions mmv1/products/redis/Cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ examples:
policy_name: "mypolicy"
subnet_name: "mysubnet"
network_name: "mynetwork"
prevent_destroy: 'true'
deletion_protection_enabled: 'true'
test_vars_overrides:
prevent_destroy: 'false'
deletion_protection_enabled: 'false'
oics_vars_overrides:
prevent_destroy: 'false'
deletion_protection_enabled: 'false'
properties:
- !ruby/object:Api::Type::Time
name: createTime
Expand Down Expand Up @@ -231,3 +231,9 @@ properties:
description: |
Required. Number of shards for the Redis cluster.
required: true
- !ruby/object:Api::Type::Boolean
name: deletionProtectionEnabled
description: |
Optional. Indicates if the cluster is deletion protected or not. Default value is true.
required: false
default_value: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a better fit for default_from_api if this is also a server-side default -- if this config was manually overridden for a pre-existing resource by a user via cloud console or pantheon, adding a field with a default value could potentially introduce a breaking change for users' configs (i.e. it potentially planning to do false -> true for users who don't manually add deletion_protection_enabled = false to their config)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @NickElliot , it is not the default value. The server-side default is false. It will also not be backward compatible for existing terraform plans. Is my understanding correct?

5 changes: 1 addition & 4 deletions mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ resource "google_redis_cluster" "<%= ctx[:primary_resource_id] %>" {
node_type = "REDIS_SHARED_CORE_NANO"
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
authorization_mode = "AUTH_MODE_DISABLED"
deletion_protection_enabled = <%= ctx[:vars]['deletion_protection_enabled'] == 'true' %>
depends_on = [
google_network_connectivity_service_connection_policy.default
]

lifecycle {
prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %>
}
}

resource "google_network_connectivity_service_connection_policy" "default" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"psc_configs"},
},
{
// set deletion protection to false
Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 0, /* shardCount = */ 3, false, /*nodeType = */ "REDIS_STANDARD_SMALL"),
},
{
ResourceName: "google_redis_cluster.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"psc_configs"},
},
{
// clean up the resource
Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 0, /* shardCount = */ 3, false, /*nodeType = */ "REDIS_STANDARD_SMALL"),
Expand Down Expand Up @@ -69,6 +79,16 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"psc_configs"},
},
{
// set deletion protection to false
Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 2, /* shardCount = */ 3, false, /*nodeType = */ ""),
},
{
ResourceName: "google_redis_cluster.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"psc_configs"},
},
{
// clean up the resource
Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 2, /* shardCount = */ 3, false, /*nodeType = */ ""),
Expand All @@ -83,6 +103,16 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"psc_configs"},
},
{
// set deletion protection to false
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, false, /*nodeType = */ ""),
},
{
ResourceName: "google_redis_cluster.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"psc_configs"},
},
{
// clean up the resource
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, false, /*nodeType = */ ""),
Expand Down Expand Up @@ -123,6 +153,16 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"psc_configs"},
},
{
// set deletion protection to false
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, false, /* nodeType = */ ""),
},
{
ResourceName: "google_redis_cluster.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"psc_configs"},
},
{
// clean up the resource
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, false, /* nodeType = */ ""),
Expand All @@ -131,29 +171,22 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
})
}

func createOrUpdateRedisCluster(name string, replicaCount int, shardCount int, preventDestroy bool, nodeType string) string {
lifecycleBlock := ""
if preventDestroy {
lifecycleBlock = `
lifecycle {
prevent_destroy = true
}`
}
func createOrUpdateRedisCluster(name string, replicaCount int, shardCount int, deletionProtectionEnabled bool, nodeType string) string {
return fmt.Sprintf(`
resource "google_redis_cluster" "test" {
provider = google-beta
name = "%s"
replica_count = %d
shard_count = %d
node_type = "%s"
deletion_protection_enabled = %v
region = "us-central1"
NickElliot marked this conversation as resolved.
Show resolved Hide resolved
psc_configs {
network = google_compute_network.producer_net.id
}
depends_on = [
google_network_connectivity_service_connection_policy.default
]
%s
}

resource "google_network_connectivity_service_connection_policy" "default" {
Expand Down Expand Up @@ -181,6 +214,6 @@ resource "google_compute_network" "producer_net" {
name = "%s"
auto_create_subnetworks = false
}
`, name, replicaCount, shardCount, nodeType, lifecycleBlock, name, name, name)
`, name, replicaCount, shardCount, nodeType, deletionProtectionEnabled, name, name, name)
}
<% end -%>