From f6ef1422cff3277d3ad87ddaadcef516fe6d1ed5 Mon Sep 17 00:00:00 2001 From: Demitri Swan Date: Tue, 31 Oct 2023 14:04:18 -0700 Subject: [PATCH] Add prevent_destroy metadata configuration. (#9383) Co-authored-by: Demitri Swan --- mmv1/products/redis/Cluster.yaml | 5 ++++ mmv1/products/redis/Instance.yaml | 30 +++++++++++++++++++ .../examples/redis_cluster_ha.tf.erb | 4 +++ .../examples/redis_instance_basic.tf.erb | 4 +++ .../examples/redis_instance_cmek.tf.erb | 4 +++ .../examples/redis_instance_full.tf.erb | 4 +++ ...stance_full_with_persistence_config.tf.erb | 4 +++ .../examples/redis_instance_mrr.tf.erb | 4 +++ .../redis_instance_private_service.tf.erb | 5 +++- ...redis_instance_private_service_test.tf.erb | 6 +++- 10 files changed, 68 insertions(+), 2 deletions(-) diff --git a/mmv1/products/redis/Cluster.yaml b/mmv1/products/redis/Cluster.yaml index 0241b174a145..08751531ba2f 100644 --- a/mmv1/products/redis/Cluster.yaml +++ b/mmv1/products/redis/Cluster.yaml @@ -57,6 +57,11 @@ examples: policy_name: "mypolicy" subnet_name: "mysubnet" network_name: "mynetwork" + prevent_destroy: 'true' + test_vars_overrides: + prevent_destroy: 'false' + oics_vars_overrides: + prevent_destroy: 'false' properties: - !ruby/object:Api::Type::Time name: createTime diff --git a/mmv1/products/redis/Instance.yaml b/mmv1/products/redis/Instance.yaml index 316af5aae8de..14c7b8e5ec85 100644 --- a/mmv1/products/redis/Instance.yaml +++ b/mmv1/products/redis/Instance.yaml @@ -44,22 +44,35 @@ examples: primary_resource_id: 'cache' vars: instance_name: 'memory-cache' + prevent_destroy: 'true' + test_vars_overrides: + prevent_destroy: 'false' + oics_vars_overrides: + prevent_destroy: 'false' - !ruby/object:Provider::Terraform::Examples name: 'redis_instance_full' primary_resource_id: 'cache' vars: instance_name: 'ha-memory-cache' network_name: 'redis-test-network' + prevent_destroy: 'true' test_vars_overrides: network_name: 'acctest.BootstrapSharedTestNetwork(t, "redis-full")' + prevent_destroy: 'false' + oics_vars_overrides: + prevent_destroy: 'false' - !ruby/object:Provider::Terraform::Examples name: 'redis_instance_full_with_persistence_config' primary_resource_id: 'cache-persis' vars: instance_name: 'ha-memory-cache-persis' network_name: 'redis-test-network' + prevent_destroy: 'true' test_vars_overrides: network_name: 'acctest.BootstrapSharedTestNetwork(t, "redis-full-persis")' + prevent_destroy: 'false' + oics_vars_overrides: + prevent_destroy: 'false' - !ruby/object:Provider::Terraform::Examples name: 'redis_instance_private_service' primary_resource_id: 'cache' @@ -67,6 +80,11 @@ examples: instance_name: 'private-cache' address_name: 'address' network_name: 'redis-test-network' + prevent_destroy: 'true' + test_vars_overrides: + prevent_destroy: 'false' + oics_vars_overrides: + prevent_destroy: 'false' skip_test: true - !ruby/object:Provider::Terraform::Examples name: 'redis_instance_private_service_test' @@ -74,8 +92,12 @@ examples: vars: instance_name: 'private-cache' network_name: 'redis-test-network' + prevent_destroy: 'true' test_vars_overrides: network_name: 'acctest.BootstrapSharedServiceNetworkingConnection(t, "vpc-network-1")' + prevent_destroy: 'false' + oics_vars_overrides: + prevent_destroy: 'false' skip_docs: true - !ruby/object:Provider::Terraform::Examples name: 'redis_instance_mrr' @@ -83,8 +105,12 @@ examples: vars: instance_name: 'mrr-memory-cache' network_name: 'redis-test-network' + prevent_destroy: 'true' test_vars_overrides: network_name: 'acctest.BootstrapSharedTestNetwork(t, "redis-mrr")' + prevent_destroy: 'false' + oics_vars_overrides: + prevent_destroy: 'false' - !ruby/object:Provider::Terraform::Examples name: 'redis_instance_cmek' primary_resource_id: 'cache' @@ -92,8 +118,12 @@ examples: vars: instance_name: 'cmek-memory-cache' network_name: 'redis-test-network' + prevent_destroy: 'true' test_vars_overrides: network_name: 'acctest.BootstrapSharedTestNetwork(t, "redis-cmek")' + prevent_destroy: 'false' + oics_vars_overrides: + prevent_destroy: 'false' parameters: # TODO: resourceref? - !ruby/object:Api::Type::String diff --git a/mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb b/mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb index 7abb93e5b601..a2ef9d488324 100644 --- a/mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb +++ b/mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb @@ -11,6 +11,10 @@ resource "google_redis_cluster" "<%= ctx[:primary_resource_id] %>" { depends_on = [ google_network_connectivity_service_connection_policy.default ] + + lifecycle { + prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %> + } } resource "google_network_connectivity_service_connection_policy" "default" { diff --git a/mmv1/templates/terraform/examples/redis_instance_basic.tf.erb b/mmv1/templates/terraform/examples/redis_instance_basic.tf.erb index ac403764b5ca..5cf774559a06 100644 --- a/mmv1/templates/terraform/examples/redis_instance_basic.tf.erb +++ b/mmv1/templates/terraform/examples/redis_instance_basic.tf.erb @@ -1,4 +1,8 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" { name = "<%= ctx[:vars]["instance_name"] %>" memory_size_gb = 1 + + lifecycle { + prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %> + } } diff --git a/mmv1/templates/terraform/examples/redis_instance_cmek.tf.erb b/mmv1/templates/terraform/examples/redis_instance_cmek.tf.erb index acb9ba91a95e..c40840101d3f 100644 --- a/mmv1/templates/terraform/examples/redis_instance_cmek.tf.erb +++ b/mmv1/templates/terraform/examples/redis_instance_cmek.tf.erb @@ -17,6 +17,10 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" { other_key = "other_val" } customer_managed_key = google_kms_crypto_key.redis_key.id + + lifecycle { + prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %> + } } resource "google_kms_key_ring" "redis_keyring" { diff --git a/mmv1/templates/terraform/examples/redis_instance_full.tf.erb b/mmv1/templates/terraform/examples/redis_instance_full.tf.erb index e737c4ec6111..2bcac657ff0c 100644 --- a/mmv1/templates/terraform/examples/redis_instance_full.tf.erb +++ b/mmv1/templates/terraform/examples/redis_instance_full.tf.erb @@ -28,6 +28,10 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" { } } } + + lifecycle { + prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %> + } } // This example assumes this network already exists. diff --git a/mmv1/templates/terraform/examples/redis_instance_full_with_persistence_config.tf.erb b/mmv1/templates/terraform/examples/redis_instance_full_with_persistence_config.tf.erb index c0d7774feaff..4f8bbf2654c5 100644 --- a/mmv1/templates/terraform/examples/redis_instance_full_with_persistence_config.tf.erb +++ b/mmv1/templates/terraform/examples/redis_instance_full_with_persistence_config.tf.erb @@ -9,4 +9,8 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" { persistence_mode = "RDB" rdb_snapshot_period = "TWELVE_HOURS" } + + lifecycle { + prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %> + } } diff --git a/mmv1/templates/terraform/examples/redis_instance_mrr.tf.erb b/mmv1/templates/terraform/examples/redis_instance_mrr.tf.erb index b0ab91f58bf2..2b038101dedf 100644 --- a/mmv1/templates/terraform/examples/redis_instance_mrr.tf.erb +++ b/mmv1/templates/terraform/examples/redis_instance_mrr.tf.erb @@ -18,6 +18,10 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" { my_key = "my_val" other_key = "other_val" } + + lifecycle { + prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %> + } } // This example assumes this network already exists. diff --git a/mmv1/templates/terraform/examples/redis_instance_private_service.tf.erb b/mmv1/templates/terraform/examples/redis_instance_private_service.tf.erb index 90e0e4ff5698..9eedaf4a9fb3 100644 --- a/mmv1/templates/terraform/examples/redis_instance_private_service.tf.erb +++ b/mmv1/templates/terraform/examples/redis_instance_private_service.tf.erb @@ -40,4 +40,7 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" { depends_on = [google_service_networking_connection.private_service_connection] -} \ No newline at end of file + lifecycle { + prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %> + } +} diff --git a/mmv1/templates/terraform/examples/redis_instance_private_service_test.tf.erb b/mmv1/templates/terraform/examples/redis_instance_private_service_test.tf.erb index afd73fa81f04..0b69e81cf45b 100644 --- a/mmv1/templates/terraform/examples/redis_instance_private_service_test.tf.erb +++ b/mmv1/templates/terraform/examples/redis_instance_private_service_test.tf.erb @@ -23,4 +23,8 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" { redis_version = "REDIS_4_0" display_name = "Terraform Test Instance" -} \ No newline at end of file + + lifecycle { + prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %> + } +}