Skip to content

Commit

Permalink
Add prevent_destroy metadata configuration. (#9383) (#16415)
Browse files Browse the repository at this point in the history
[upstream:921c254d638895d06d284f899a57c684ecc205a3]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Oct 31, 2023
1 parent 8732919 commit f7fd747
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .changelog/9383.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:none
redis: Updated the documentation examples to include the prevent_destroy metadata configuration

```
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func TestAccRedisCluster_redisClusterHaExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"prevent_destroy": false,
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
Expand Down Expand Up @@ -70,6 +71,10 @@ resource "google_redis_cluster" "cluster-ha" {
depends_on = [
google_network_connectivity_service_connection_policy.default
]
lifecycle {
prevent_destroy = %{prevent_destroy}
}
}
resource "google_network_connectivity_service_connection_policy" "default" {
Expand Down
43 changes: 34 additions & 9 deletions google/services/redis/resource_redis_instance_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func TestAccRedisInstance_redisInstanceBasicExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"prevent_destroy": false,
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -60,6 +61,10 @@ func testAccRedisInstance_redisInstanceBasicExample(context map[string]interface
resource "google_redis_instance" "cache" {
name = "tf-test-memory-cache%{random_suffix}"
memory_size_gb = 1
lifecycle {
prevent_destroy = %{prevent_destroy}
}
}
`, context)
}
Expand All @@ -68,8 +73,9 @@ func TestAccRedisInstance_redisInstanceFullExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"network_name": acctest.BootstrapSharedTestNetwork(t, "redis-full"),
"random_suffix": acctest.RandString(t, 10),
"network_name": acctest.BootstrapSharedTestNetwork(t, "redis-full"),
"prevent_destroy": false,
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
Expand Down Expand Up @@ -122,6 +128,10 @@ resource "google_redis_instance" "cache" {
}
}
}
lifecycle {
prevent_destroy = %{prevent_destroy}
}
}
// This example assumes this network already exists.
Expand All @@ -142,8 +152,9 @@ func TestAccRedisInstance_redisInstanceFullWithPersistenceConfigExample(t *testi
t.Parallel()

context := map[string]interface{}{
"network_name": acctest.BootstrapSharedTestNetwork(t, "redis-full-persis"),
"random_suffix": acctest.RandString(t, 10),
"network_name": acctest.BootstrapSharedTestNetwork(t, "redis-full-persis"),
"prevent_destroy": false,
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
Expand Down Expand Up @@ -177,6 +188,10 @@ resource "google_redis_instance" "cache-persis" {
persistence_mode = "RDB"
rdb_snapshot_period = "TWELVE_HOURS"
}
lifecycle {
prevent_destroy = %{prevent_destroy}
}
}
`, context)
}
Expand All @@ -185,8 +200,9 @@ func TestAccRedisInstance_redisInstancePrivateServiceTestExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "vpc-network-1"),
"random_suffix": acctest.RandString(t, 10),
"network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "vpc-network-1"),
"prevent_destroy": false,
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
Expand Down Expand Up @@ -234,6 +250,10 @@ resource "google_redis_instance" "cache" {
redis_version = "REDIS_4_0"
display_name = "Terraform Test Instance"
lifecycle {
prevent_destroy = %{prevent_destroy}
}
}
`, context)
}
Expand All @@ -242,8 +262,9 @@ func TestAccRedisInstance_redisInstanceMrrExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"network_name": acctest.BootstrapSharedTestNetwork(t, "redis-mrr"),
"random_suffix": acctest.RandString(t, 10),
"network_name": acctest.BootstrapSharedTestNetwork(t, "redis-mrr"),
"prevent_destroy": false,
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
Expand Down Expand Up @@ -286,6 +307,10 @@ resource "google_redis_instance" "cache" {
my_key = "my_val"
other_key = "other_val"
}
lifecycle {
prevent_destroy = %{prevent_destroy}
}
}
// This example assumes this network already exists.
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/redis_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ resource "google_redis_cluster" "cluster-ha" {
depends_on = [
google_network_connectivity_service_connection_policy.default
]
lifecycle {
prevent_destroy = true
}
}
resource "google_network_connectivity_service_connection_policy" "default" {
Expand Down
23 changes: 23 additions & 0 deletions website/docs/r/redis_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ To get more information about Instance, see:
resource "google_redis_instance" "cache" {
name = "memory-cache"
memory_size_gb = 1
lifecycle {
prevent_destroy = true
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
Expand Down Expand Up @@ -81,6 +85,10 @@ resource "google_redis_instance" "cache" {
}
}
}
lifecycle {
prevent_destroy = true
}
}
// This example assumes this network already exists.
Expand Down Expand Up @@ -115,6 +123,10 @@ resource "google_redis_instance" "cache-persis" {
persistence_mode = "RDB"
rdb_snapshot_period = "TWELVE_HOURS"
}
lifecycle {
prevent_destroy = true
}
}
```
## Example Usage - Redis Instance Private Service
Expand Down Expand Up @@ -163,6 +175,9 @@ resource "google_redis_instance" "cache" {
depends_on = [google_service_networking_connection.private_service_connection]
lifecycle {
prevent_destroy = true
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
Expand Down Expand Up @@ -194,6 +209,10 @@ resource "google_redis_instance" "cache" {
my_key = "my_val"
other_key = "other_val"
}
lifecycle {
prevent_destroy = true
}
}
// This example assumes this network already exists.
Expand Down Expand Up @@ -231,6 +250,10 @@ resource "google_redis_instance" "cache" {
other_key = "other_val"
}
customer_managed_key = google_kms_crypto_key.redis_key.id
lifecycle {
prevent_destroy = true
}
}
resource "google_kms_key_ring" "redis_keyring" {
Expand Down

0 comments on commit f7fd747

Please sign in to comment.