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

Sql database add deletion policy #6821

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions mmv1/products/sql/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,34 @@ overrides: !ruby/object:Overrides::ResourceOverrides
deletion_protection: "false"
oics_vars_overrides:
deletion_protection: "false"
- !ruby/object:Provider::Terraform::Examples
name: "sql_database_deletion_policy"
primary_resource_id: "database_deletion_policy"
vars:
database_name: "my-database"
database_instance_name: "my-database-instance"
deletion_protection: "true"
test_vars_overrides:
deletion_protection: "false"
oics_vars_overrides:
deletion_protection: "false"
properties:
collation: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
charset: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
diff_suppress_func: 'caseDiffSuppress'
virtual_fields:
- !ruby/object:Api::Type::String
name: 'deletion_policy'
description: |
The deletion policy for the database. Setting ABANDON allows the resource
to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be
deleted from the API if there are users other than cloudsqlsuperuser with access. Possible
values are: "ABANDON".
default_value: "ABANDON"
custom_code: !ruby/object:Provider::Terraform::CustomCode
pre_delete: templates/terraform/pre_delete/sql_database_deletion_policy.erb
SourceRepresentationInstance: !ruby/object:Overrides::Terraform::ResourceOverride
examples:
- !ruby/object:Provider::Terraform::Examples
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# [START cloud_sql_database_create]
resource "google_sql_database" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['database_name'] %>"
instance = google_sql_database_instance.instance.name
deletion_policy = "ABANDON"
slevenick marked this conversation as resolved.
Show resolved Hide resolved
}
# [END cloud_sql_database_create]

# See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
resource "google_sql_database_instance" "instance" {
name = "<%= ctx[:vars]['database_instance_name'] %>"
region = "us-central1"
database_version = "POSTGRES_14"
settings {
tier = "db-g1-small"
}

deletion_protection = "<%= ctx[:vars]['deletion_protection'] %>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if deletionPolicy := d.Get("deletion_policy"); deletionPolicy == "ABANDON" {
// Allows for database to be abandoned without deletion to avoid deletion failing
// for Postgres databases in some circumstances due to existing SQL users
return nil
}