Skip to content
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
27 changes: 26 additions & 1 deletion mmv1/products/firestore/Index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ custom_code:
encoder: 'templates/terraform/encoders/index.go.tmpl'
custom_import: 'templates/terraform/custom_import/index_self_link_as_name_set_project.go.tmpl'
custom_create: 'templates/terraform/custom_create/firestore_index.go.tmpl'
pre_delete: 'templates/terraform/pre_delete/firestore_index.go.tmpl'
error_retry_predicates:

- 'transport_tpg.FirestoreIndex409Retry'
examples:
- name: 'firestore_index_basic'
Expand Down Expand Up @@ -107,12 +107,37 @@ examples:
project_id: 'PROJECT_NAME'
ignore_read_extra:
- 'skip_wait'
- name: 'firestore_index_deletion_policy'
primary_resource_id: 'my-index'
vars:
database_id: 'database-id-deletion-policy'
deletion_policy: '"PREVENT"'
test_env_vars:
project_id: 'PROJECT_NAME'
# Example will show delete_protection as true, but in test we will actually set to false
# so the test can cleanup after itself.
test_vars_overrides:
'deletion_policy': '"DELETE"'
ignore_read_extra:
- 'deletion_policy'
virtual_fields:
- name: "skip_wait"
type: Boolean
default_value: false
description: "Whether to skip waiting for the index to be created."
ignore_read: true
- name: 'deletion_policy'
type: Enum
default_value: 'DELETE'
ignore_read: true
enum_values:
- 'DELETE'
- 'PREVENT'
description: |
Deletion behavior for this index.
If the deletion policy is `PREVENT`, the index cannot be deleted and a terraform destroy will fail.
If the deletion policy is `DELETE`, the index will both be removed from Terraform state and deleted from Google Cloud upon destruction.
The default value is `DELETE`.
parameters:
# Firestore uses a custom create function. Any new fields must be explicitly handled there.
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "google_firestore_database" "database" {
project = "{{index $.TestEnvVars "project_id"}}"
name = "{{index $.Vars "database_id"}}"
location_id = "nam5"
type = "FIRESTORE_NATIVE"

delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
}

resource "google_firestore_index" "{{$.PrimaryResourceId}}" {
project = "{{index $.TestEnvVars "project_id"}}"
database = google_firestore_database.database.name
collection = "atestcollection"

fields {
field_path = "name"
order = "ASCENDING"
}

fields {
field_path = "description"
order = "DESCENDING"
}
deletion_policy = "{{index $.Vars "deletion_policy"}}"
}
3 changes: 3 additions & 0 deletions mmv1/templates/terraform/pre_delete/firestore_index.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if d.Get("deletion_policy").(string) == "PREVENT" {
return fmt.Errorf("cannot destroy google_firestore_index resource with id : %q without setting deletion_policy=DELETE and running `terraform apply`", d.Id())
}
Loading