Skip to content

Commit

Permalink
fix: Check for default Firestore database (#124)
Browse files Browse the repository at this point in the history
Co-authored-by: Katie McLaughlin <katie@glasnt.com>
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 22, 2024
1 parent c502442 commit 757b4c7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/
locals {
nextauth_url = "http://${google_compute_global_address.default.address}"
firestore_enabled = length(data.google_cloud_asset_resources_search_all.firestore_database.results) == 1 ? true : false
nextauth_url = "http://${google_compute_global_address.default.address}"
has_default_firestore_database = length(data.google_cloud_asset_resources_search_all.default_firestore_database.results) > 0 ? true : false
}

### GCS bucket ###
Expand Down Expand Up @@ -318,17 +318,18 @@ data "http" "load_balancer_warm_up" {
### Firestore ###

# The following checks Asset Inventory for an existing Firestore database
data "google_cloud_asset_resources_search_all" "firestore_database" {
data "google_cloud_asset_resources_search_all" "default_firestore_database" {
provider = google-beta
scope = "projects/${var.project_id}"
query = "displayName:(default)"
asset_types = [
"firestore.googleapis.com/Database"
]
}

# If a Firestore database exists on the project, Terraform will skip this resource
resource "google_firestore_database" "database" {
count = var.init_firestore && !local.firestore_enabled ? 1 : 0
count = var.init_firestore && !local.has_default_firestore_database ? 1 : 0
project = var.project_id
name = "(default)"
location_id = "nam5"
Expand Down

0 comments on commit 757b4c7

Please sign in to comment.