Skip to content

Commit

Permalink
Add deletion_protection to v2 cloud run service resource (#11318)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Rodgers <[email protected]>
  • Loading branch information
avianap and trodge authored Aug 6, 2024
1 parent 40c0cc6 commit 1c7aa4d
Show file tree
Hide file tree
Showing 47 changed files with 185 additions and 29 deletions.
29 changes: 29 additions & 0 deletions mmv1/products/cloudrunv2/Job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ iam_policy: !ruby/object:Api::Resource::IamPolicy
id_format: 'projects/{{project}}/locations/{{location}}/jobs/{{name}}'
import_format: ['projects/{{project}}/locations/{{location}}/jobs/{{name}}']
autogen_async: true
virtual_fields:
- !ruby/object:Api::Type::Boolean
name: 'deletion_protection'
default_value: true
description: |
Whether Terraform will be prevented from destroying the job. Defaults to true.
When a`terraform destroy` or `terraform apply` would delete the job,
the command will fail if this field is not set to false in Terraform state.
When the field is set to true or unset in Terraform state, a `terraform apply`
or `terraform destroy` that would delete the job will fail.
When the field is set to false, deleting the job is allowed.
custom_code: !ruby/object:Provider::Terraform::CustomCode
pre_delete: 'templates/terraform/pre_delete/cloudrunv2_job_deletion_policy.go.erb'
examples:
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_job_basic'
Expand All @@ -59,11 +72,15 @@ examples:
])"
vars:
cloud_run_job_name: 'cloudrun-job'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_job_limits'
primary_resource_id: 'default'
vars:
cloud_run_job_name: 'cloudrun-job'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_job_sql'
primary_resource_id: 'default'
Expand All @@ -79,6 +96,8 @@ examples:
deletion_protection: 'false'
oics_vars_overrides:
deletion_protection: 'false'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_job_vpcaccess'
primary_resource_id: 'default'
Expand All @@ -90,13 +109,17 @@ examples:
vpc_access_connector_name: 'run-vpc'
vpc_compute_subnetwork_name: 'run-subnetwork'
compute_network_name: 'run-network'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_job_directvpc'
primary_resource_id: 'default'
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-job%s\", context[\"random_suffix\"\
])"
vars:
cloud_run_job_name: 'cloudrun-job'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_job_secret'
primary_resource_id: 'default'
Expand All @@ -106,6 +129,8 @@ examples:
vars:
cloud_run_job_name: 'cloudrun-job'
secret_id: 'secret'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_job_emptydir'
min_version: 'beta'
Expand All @@ -114,6 +139,8 @@ examples:
])"
vars:
cloud_run_job_name: 'cloudrun-job'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_job_run_job'
min_version: beta
Expand All @@ -122,6 +149,8 @@ examples:
])"
vars:
cloud_run_job_name: 'cloudrun-job'
ignore_read_extra:
- 'deletion_protection'
parameters:
- !ruby/object:Api::Type::String
name: 'location'
Expand Down
35 changes: 33 additions & 2 deletions mmv1/products/cloudrunv2/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,35 @@ async: !ruby/object:Api::OpAsync
id_format: 'projects/{{project}}/locations/{{location}}/services/{{name}}'
import_format: ['projects/{{project}}/locations/{{location}}/services/{{name}}']
autogen_async: true
virtual_fields:
- !ruby/object:Api::Type::Boolean
name: 'deletion_protection'
default_value: true
description: |
Whether Terraform will be prevented from destroying the service. Defaults to true.
When a`terraform destroy` or `terraform apply` would delete the service,
the command will fail if this field is not set to false in Terraform state.
When the field is set to true or unset in Terraform state, a `terraform apply`
or `terraform destroy` that would delete the service will fail.
When the field is set to false, deleting the service is allowed.
custom_code: !ruby/object:Provider::Terraform::CustomCode
pre_delete: 'templates/terraform/pre_delete/cloudrunv2_service_deletion_policy.go.erb'
examples:
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_basic'
primary_resource_id: 'default'
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-service%s\", context[\"random_suffix\"])"
vars:
cloud_run_service_name: 'cloudrun-service'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_limits'
primary_resource_id: 'default'
vars:
cloud_run_service_name: 'cloudrun-service'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_sql'
primary_resource_id: 'default'
Expand All @@ -74,6 +91,8 @@ examples:
deletion_protection: 'false'
oics_vars_overrides:
deletion_protection: 'false'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_vpcaccess'
primary_resource_id: 'default'
Expand All @@ -83,25 +102,33 @@ examples:
vpc_access_connector_name: 'run-vpc'
vpc_compute_subnetwork_name: 'run-subnetwork'
compute_network_name: 'run-network'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_directvpc'
primary_resource_id: 'default'
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_service_name: 'cloudrun-service'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_probes'
primary_resource_id: 'default'
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_service_name: 'cloudrun-service'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_secret'
primary_resource_id: 'default'
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_service_name: 'cloudrun-service'
secret_id: 'secret-1'
ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_multicontainer'
min_version: 'beta'
Expand All @@ -110,20 +137,24 @@ examples:
random_suffix\"])"
vars:
cloud_run_service_name: 'cloudrun-service'

ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_mount_gcs'
primary_resource_id: 'default'
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-service-%s\", context[\"random_suffix\"])"
vars:
cloud_run_service_name: 'cloudrun-service'

ignore_read_extra:
- 'deletion_protection'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_mount_nfs'
primary_resource_id: 'default'
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-service-%s\", context[\"random_suffix\"])"
vars:
cloud_run_service_name: 'cloudrun-service'
ignore_read_extra:
- 'deletion_protection'

parameters:
- !ruby/object:Api::Type::String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
deletion_protection = false

template {
template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
deletion_protection = false
launch_stage = "GA"
template {
template{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
deletion_protection = false
launch_stage = "BETA"
template {
template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
deletion_protection = false

template {
template {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
deletion_protection = false
start_execution_token = "start-once-created"
template {
template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
deletion_protection = false

template {
template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"

deletion_protection = false
template {
template{
volumes {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
deletion_protection = false

template {
template{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"

template {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
deletion_protection = false
launch_stage = "BETA"
ingress = "INGRESS_TRAFFIC_ALL"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
deletion_protection = false
launch_stage = "GA"
template {
containers {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"

template {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"

location = "us-central1"
deletion_protection = false
launch_stage = "BETA"

template {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"

location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"
launch_stage = "BETA"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
deletion_protection = false
launch_stage = "BETA"
ingress = "INGRESS_TRAFFIC_ALL"
template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
deletion_protection = false

template {
containers {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"

template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"

template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
deletion_protection = false

template {
containers {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_job" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "cloud_run_job_name"}}"
location = "us-central1"
deletion_protection = false

template {
template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_job" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "cloud_run_job_name"}}"
location = "us-central1"
deletion_protection = false
launch_stage = "GA"
template {
template{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ resource "google_cloud_run_v2_job" "{{$.PrimaryResourceId}}" {
provider = google-beta
name = "{{index $.Vars "cloud_run_job_name"}}"
location = "us-central1"
deletion_protection = false
launch_stage = "BETA"
template {
template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_job" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "cloud_run_job_name"}}"
location = "us-central1"
deletion_protection = false

template {
template {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ resource "google_cloud_run_v2_job" "{{$.PrimaryResourceId}}" {
provider = google-beta
name = "{{index $.Vars "cloud_run_job_name"}}"
location = "us-central1"
deletion_protection = false
start_execution_token = "start-once-created"
template {
template {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "google_cloud_run_v2_job" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "cloud_run_job_name"}}"
location = "us-central1"
deletion_protection = false

template {
template {
Expand Down
Loading

0 comments on commit 1c7aa4d

Please sign in to comment.