Skip to content

Commit

Permalink
test: Fix missing database for datastore_index test. (#10316) (#7189)
Browse files Browse the repository at this point in the history
[upstream:e040a9334c923903a7180deec51aa96113181354]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Apr 4, 2024
1 parent 9ca55f7 commit 1ec163e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/10316.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)
Expand All @@ -34,6 +35,7 @@ func TestAccDatastoreIndex_datastoreIndexExample(t *testing.T) {
t.Parallel()

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

Expand All @@ -56,6 +58,19 @@ func TestAccDatastoreIndex_datastoreIndexExample(t *testing.T) {

func testAccDatastoreIndex_datastoreIndexExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_firestore_database" "database" {
project = "%{project_id}"
# google_datastore_index resources only support the (default) database.
# However, google_firestore_index can express any Datastore Mode index
# and should be preferred in all cases.
name = "(default)"
location_id = "nam5"
type = "DATASTORE_MODE"
delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
}
resource "google_datastore_index" "default" {
kind = "foo"
properties {
Expand All @@ -66,6 +81,8 @@ resource "google_datastore_index" "default" {
name = "tf_test_property_b%{random_suffix}"
direction = "ASCENDING"
}
depends_on = [google_firestore_database.database]
}
`, context)
}
Expand Down
20 changes: 15 additions & 5 deletions website/docs/r/datastore_index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,23 @@ one, you can create a `google_app_engine_application` resource with
`database_type` set to `"CLOUD_DATASTORE_COMPATIBILITY"` to do so. Your
Datastore location will be the same as the App Engine location specified.

<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=datastore_index&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Datastore Index


```hcl
resource "google_firestore_database" "database" {
project = "my-project-name"
# google_datastore_index resources only support the (default) database.
# However, google_firestore_index can express any Datastore Mode index
# and should be preferred in all cases.
name = "(default)"
location_id = "nam5"
type = "DATASTORE_MODE"
delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
}
resource "google_datastore_index" "default" {
kind = "foo"
properties {
Expand All @@ -53,6 +61,8 @@ resource "google_datastore_index" "default" {
name = "property_b"
direction = "ASCENDING"
}
depends_on = [google_firestore_database.database]
}
```

Expand Down

0 comments on commit 1ec163e

Please sign in to comment.