|
| 1 | +# Terraform configuration to set up providers by version. |
| 2 | +terraform { |
| 3 | + required_providers { |
| 4 | + google-beta = { |
| 5 | + source = "hashicorp/google-beta" |
| 6 | + version = "~> 4.0" |
| 7 | + } |
| 8 | + } |
| 9 | +} |
| 10 | + |
| 11 | +# Configure the provider not to use the specified project for quota check. |
| 12 | +# This provider should only be used during project creation and initializing services. |
| 13 | +provider "google-beta" { |
| 14 | + alias = "no_user_project_override" |
| 15 | + user_project_override = false |
| 16 | +} |
| 17 | + |
| 18 | +# Configure the provider that uses the new project's quota. |
| 19 | +provider "google-beta" { |
| 20 | + user_project_override = true |
| 21 | +} |
| 22 | + |
| 23 | +# Create a new Google Cloud project. |
| 24 | +resource "google_project" "default" { |
| 25 | + provider = google-beta.no_user_project_override |
| 26 | + |
| 27 | + # TODO: REPLACE WITH YOUR OWN VALUES |
| 28 | + name = "<PROJECT_NAME_OF_YOUR_PROJECT>" |
| 29 | + project_id = "<PROJECT_ID_OF_YOUR_PROJECT>" |
| 30 | + |
| 31 | + # Required for the project to display in any list of Firebase projects. |
| 32 | + labels = { |
| 33 | + "firebase" = "enabled" |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +# Enable the required underlying Service Usage API. |
| 38 | +resource "google_project_service" "serviceusage" { |
| 39 | + provider = google-beta.no_user_project_override |
| 40 | + |
| 41 | + project = google_project.default.project_id |
| 42 | + service = "serviceusage.googleapis.com" |
| 43 | + |
| 44 | + # Don't disable the service if the resource block is removed by accident. |
| 45 | + disable_on_destroy = false |
| 46 | +} |
| 47 | + |
| 48 | +# Enable the required underlying Firebase Management API. |
| 49 | +resource "google_project_service" "firebase" { |
| 50 | + provider = google-beta.no_user_project_override |
| 51 | + |
| 52 | + project = google_project.default.project_id |
| 53 | + service = "firebase.googleapis.com" |
| 54 | + |
| 55 | + # Don't disable the service if the resource block is removed by accident. |
| 56 | + disable_on_destroy = false |
| 57 | +} |
| 58 | + |
| 59 | +# Enable Firebase services for the new project created above. |
| 60 | +resource "google_firebase_project" "default" { |
| 61 | + provider = google-beta |
| 62 | + |
| 63 | + project = google_project.default.project_id |
| 64 | + |
| 65 | + # Wait until the required APIs are enabled. |
| 66 | + depends_on = [ |
| 67 | + google_project_service.firebase, |
| 68 | + google_project_service.serviceusage, |
| 69 | + ] |
| 70 | +} |
| 71 | + |
| 72 | +# Create a Firebase Web App in the new project created above. |
| 73 | +resource "google_firebase_web_app" "default" { |
| 74 | + provider = google-beta |
| 75 | + |
| 76 | + project = google_firebase_project.default.project |
| 77 | + # TODO: REPLACE WITH YOUR OWN VALUE |
| 78 | + display_name = "<DISPLAY_NAME_OF_YOUR_WEB_APP>" |
| 79 | + deletion_policy = "DELETE" |
| 80 | +} |
0 commit comments