Skip to content

Commit

Permalink
Address dependency issues in TestAccFirestoreField_* tests (#9957) (#…
Browse files Browse the repository at this point in the history
…17490)

* Add additional wait in TestAccFirestoreField_* tests

* Boost wait in test to 6 minutes

* Add dependency between database and service to control delete order

* Update dependency to explicitly include project

* Make firestore fields be removed from state when they're 'deleted'

* Add `destroy_duration`

* Remove from state after log line that uses id value

* Update destory check to accept a 403 as valid

* Remove unneeded changes in PR

* Remove call to SetId

[upstream:3791c34c28ff987929f1e1869c9eba723c80a095]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 5, 2024
1 parent 135b6f4 commit 197eb51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/9957.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 @@ -24,6 +24,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"google.golang.org/api/googleapi"

"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
Expand Down Expand Up @@ -231,6 +232,15 @@ func testAccCheckFirestoreFieldDestroyProducer(t *testing.T) func(s *terraform.S
UserAgent: config.UserAgent,
})
if err != nil {
e := err.(*googleapi.Error)
if e.Code == 403 && strings.Contains(e.Message, "Cloud Firestore API has not been used in project") {
// The acceptance test has provisioned the resources under test in a new project, and the destory check is seeing the
// effects of the project not existing. This means the service isn't enabled, and that the resource is definitely destroyed.
// We do not return the error in this case - destroy was successful
return nil
}

// Return err in all other cases
return err
}

Expand Down
8 changes: 6 additions & 2 deletions google/services/firestore/resource_firestore_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ resource "google_firestore_database" "database" {
location_id = "nam5"
type = "FIRESTORE_NATIVE"
depends_on = [google_project_service.firestore]
# used to control delete order
depends_on = [
google_project_service.firestore,
google_project.project
]
}
`, context)
} else {
Expand All @@ -117,7 +121,7 @@ resource "google_firestore_database" "database" {
type = "FIRESTORE_NATIVE"
delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
deletion_policy = "DELETE"
}
`, context)
}
Expand Down

0 comments on commit 197eb51

Please sign in to comment.