Skip to content

Commit d1cb9d3

Browse files
Address dependency issues in TestAccFirestoreField_* tests (#9957) (#7046)
* 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]>
1 parent eb392a2 commit d1cb9d3

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.changelog/9957.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/services/firestore/resource_firestore_field_generated_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
2626
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
27+
"google.golang.org/api/googleapi"
2728

2829
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
2930
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
@@ -231,6 +232,15 @@ func testAccCheckFirestoreFieldDestroyProducer(t *testing.T) func(s *terraform.S
231232
UserAgent: config.UserAgent,
232233
})
233234
if err != nil {
235+
e := err.(*googleapi.Error)
236+
if e.Code == 403 && strings.Contains(e.Message, "Cloud Firestore API has not been used in project") {
237+
// The acceptance test has provisioned the resources under test in a new project, and the destory check is seeing the
238+
// effects of the project not existing. This means the service isn't enabled, and that the resource is definitely destroyed.
239+
// We do not return the error in this case - destroy was successful
240+
return nil
241+
}
242+
243+
// Return err in all other cases
234244
return err
235245
}
236246

google-beta/services/firestore/resource_firestore_field_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ resource "google_firestore_database" "database" {
105105
location_id = "nam5"
106106
type = "FIRESTORE_NATIVE"
107107
108-
depends_on = [google_project_service.firestore]
108+
# used to control delete order
109+
depends_on = [
110+
google_project_service.firestore,
111+
google_project.project
112+
]
109113
}
110114
`, context)
111115
} else {
@@ -117,7 +121,7 @@ resource "google_firestore_database" "database" {
117121
type = "FIRESTORE_NATIVE"
118122
119123
delete_protection_state = "DELETE_PROTECTION_DISABLED"
120-
deletion_policy = "DELETE"
124+
deletion_policy = "DELETE"
121125
}
122126
`, context)
123127
}

0 commit comments

Comments
 (0)