Skip to content

Commit

Permalink
Add prevent_destroy metadata configuration. (GoogleCloudPlatform#9383)
Browse files Browse the repository at this point in the history
Co-authored-by: Demitri Swan <[email protected]>
  • Loading branch information
2 people authored and BBBmau committed Nov 28, 2023
1 parent 29a1d70 commit f6ef142
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 2 deletions.
5 changes: 5 additions & 0 deletions mmv1/products/redis/Cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions mmv1/products/redis/Instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,56 +44,86 @@ 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'
vars:
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'
primary_resource_id: 'cache'
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'
primary_resource_id: 'cache'
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'
skip_test: true
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
Expand Down
4 changes: 4 additions & 0 deletions mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 4 additions & 0 deletions mmv1/templates/terraform/examples/redis_instance_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -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'] %>
}
}
4 changes: 4 additions & 0 deletions mmv1/templates/terraform/examples/redis_instance_cmek.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 4 additions & 0 deletions mmv1/templates/terraform/examples/redis_instance_full.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] %>
}
}
4 changes: 4 additions & 0 deletions mmv1/templates/terraform/examples/redis_instance_mrr.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" {

depends_on = [google_service_networking_connection.private_service_connection]

}
lifecycle {
prevent_destroy = <%= ctx[:vars]['prevent_destroy'] %>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ resource "google_redis_instance" "<%= ctx[:primary_resource_id] %>" {

redis_version = "REDIS_4_0"
display_name = "Terraform Test Instance"
}

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

0 comments on commit f6ef142

Please sign in to comment.