Skip to content

Allow for single field indexes in 'google_firestore_index' resources to support __name__ DESC indexes #8576

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

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
3 changes: 3 additions & 0 deletions .changelog/12121.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
firestore: allowed single field indexes to support `__name__ DESC` indexes in `google_firestore_index` resources
```
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ specified as the last field, it will be added automatically with the same
direction as that of the last field defined. If the final field in a
composite index is not directional, the '__name__' will be ordered
'"ASCENDING"' (unless explicitly specified otherwise).`,
MinItems: 2,
MinItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"array_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,57 @@ resource "google_firestore_index" "my-index" {
`, context)
}

func TestAccFirestoreIndex_firestoreIndexNameDescendingExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project_id": envvar.GetTestProjectFromEnv(),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckFirestoreIndexDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFirestoreIndex_firestoreIndexNameDescendingExample(context),
},
{
ResourceName: "google_firestore_index.my-index",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"collection", "database"},
},
},
})
}

func testAccFirestoreIndex_firestoreIndexNameDescendingExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_firestore_database" "database" {
project = "%{project_id}"
name = "tf-test-database-id%{random_suffix}"
location_id = "nam5"
type = "FIRESTORE_NATIVE"

delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
}

resource "google_firestore_index" "my-index" {
project = "%{project_id}"
database = google_firestore_database.database.name
collection = "atestcollection"

fields {
field_path = "__name__"
order = "DESCENDING"
}
}
`, context)
}

func testAccCheckFirestoreIndexDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
25 changes: 25 additions & 0 deletions website/docs/r/firestore_index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,31 @@ resource "google_firestore_index" "my-index" {
}
}
```
## Example Usage - Firestore Index Name Descending


```hcl
resource "google_firestore_database" "database" {
project = "my-project-name"
name = "database-id"
location_id = "nam5"
type = "FIRESTORE_NATIVE"

delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
}

resource "google_firestore_index" "my-index" {
project = "my-project-name"
database = google_firestore_database.database.name
collection = "atestcollection"

fields {
field_path = "__name__"
order = "DESCENDING"
}
}
```

## Argument Reference

Expand Down