From 6701d1f8980f8d8aaa52851afa89f6bce626b719 Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Tue, 11 Feb 2025 09:36:30 -0500 Subject: [PATCH 1/8] Terraform config for App Hosting Backend resource --- mmv1/products/firebaseapphosting/Backend.yaml | 210 ++++++++++++++++++ mmv1/products/firebaseapphosting/product.yaml | 24 ++ ...firebase_app_hosting_backend_basic.tf.tmpl | 18 ++ ...irebase_app_hosting_backend_github.tf.tmpl | 60 +++++ 4 files changed, 312 insertions(+) create mode 100644 mmv1/products/firebaseapphosting/Backend.yaml create mode 100644 mmv1/products/firebaseapphosting/product.yaml create mode 100644 mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl create mode 100644 mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl diff --git a/mmv1/products/firebaseapphosting/Backend.yaml b/mmv1/products/firebaseapphosting/Backend.yaml new file mode 100644 index 000000000000..b7e65c73e7ed --- /dev/null +++ b/mmv1/products/firebaseapphosting/Backend.yaml @@ -0,0 +1,210 @@ +# Copyright 2025 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +name: Backend +description: A Backend is the primary resource of App Hosting. +base_url: projects/{{project}}/locations/{{location}}/backends +update_mask: true +self_link: projects/{{project}}/locations/{{location}}/backends/{{backend_id}} +create_url: projects/{{project}}/locations/{{location}}/backends?backendId={{backend_id}} +# Always forces deletion because the child resource default `Domain` is always present. +delete_url: projects/{{project}}/locations/{{location}}/backends/{{backend_id}}?force=true +update_verb: PATCH +id_format: projects/{{project}}/locations/{{location}}/backends/{{backend_id}} +import_format: + - "projects/{{project}}/locations/{{location}}/backends/{{backend_id}}" + - "{{project}}/{{location}}/{{backend_id}}" + - "{{location}}/{{backend_id}}" +examples: + - name: firebase_app_hosting_backend_basic + primary_resource_id: example + vars: + location: 'us-central1' + backend_id: 'my-backend' + app_id: '1:0000000000:web:674cde32020e16fbce9dbd' + display_name: 'My Backend' + serving_locality: 'GLOBAL_ACCESS' + test_env_vars: + project_id: 'PROJECT_NAME' + test_vars_overrides: + 'location': '"us-central1"' + 'serving_locality': '"GLOBAL_ACCESS"' + 'app_id': '"1:0000000000:web:674cde32020e16fbce9dbd"' + - name: firebase_app_hosting_backend_github + primary_resource_id: example + vars: + location: 'us-central1' + backend_id: 'my-backend-gh' + app_id: 'firebase:app:id' + display_name: 'My Backend' + serving_locality: 'GLOBAL_ACCESS' + test_env_vars: + project_id: 'PROJECT_NAME' + test_vars_overrides: + 'location': '"us-central1"' + 'serving_locality': '"GLOBAL_ACCESS"' + skip_test: true # Can't establish a Github connection in automated tests. +autogen_async: true +async: + operation: + timeouts: + insert_minutes: 20 + update_minutes: 20 + delete_minutes: 20 + base_url: "{{op_id}}" + actions: + - create + - delete + - update + type: OpAsync + result: + resource_inside_response: true + include_project: false +autogen_status: QmFja2VuZA== +parameters: + - name: location + type: String + description: The canonical IDs of a Google Cloud location such as "us-east1". + immutable: true + url_param_only: true + required: true + - name: backendId + type: String + description: |- + Id of the backend. Also used as the service ID for Cloud Run, and as part + of the default domain name. + immutable: true + url_param_only: true + required: true +properties: + - name: servingLocality + type: Enum + description: |- + Immutable. Specifies how App Hosting will serve the content for this backend. It will + either be contained to a single region (REGIONAL_STRICT) or allowed to use + App Hosting's global-replicated serving infrastructure (GLOBAL_ACCESS). + enum_values: + - "REGIONAL_STRICT" + - "GLOBAL_ACCESS" + immutable: true + required: true + - name: appId + type: String + description: |- + The [ID of a Web + App](https://firebase.google.com/docs/reference/firebase-management/rest/v1beta1/projects.webApps#WebApp.FIELDS.app_id) + associated with the backend. + required: true + - name: serviceAccount + type: String + description: |- + The name of the service account used for Cloud Build and Cloud Run. + Should have the role roles/firebaseapphosting.computeRunner + or equivalent permissions. + required: true + - name: annotations + type: KeyValueAnnotations + description: |- + Unstructured key value map that may be set by external tools to + store and arbitrary metadata. They are not queryable and should be + preserved when modifying objects. + - name: displayName + type: String + description: Human-readable name. 63 character limit. + - name: environment + type: String + description: |- + The environment name of the backend, used to load environment variables + from environment specific configuration. + - name: labels + type: KeyValueLabels + description: |- + Unstructured key value map that can be used to organize and categorize + objects. + - name: etag + type: Fingerprint + description: |- + Server-computed checksum based on other values; may be sent + on update or delete to ensure operation is done on expected resource. + output: true + - name: name + type: String + description: |- + Identifier. The resource name of the backend. + + Format: + + `projects/{project}/locations/{locationId}/backends/{backendId}`. + output: true + - name: createTime + type: Time + description: Time at which the backend was created. + output: true + - name: deleteTime + type: Time + description: Time at which the backend was deleted. + output: true + - name: updateTime + type: Time + description: Time at which the backend was last updated. + output: true + - name: uid + type: String + description: System-assigned, unique identifier. + output: true + - name: uri + type: String + description: The primary URI to communicate with the backend. + output: true + - name: codebase + type: NestedObject + description: |- + The connection to an external source repository to watch for event-driven + updates to the backend. + properties: + - name: repository + type: String + description: |- + The resource name for the Developer Connect + [`gitRepositoryLink`](https://cloud.google.com/developer-connect/docs/api/reference/rest/v1/projects.locations.connections.gitRepositoryLinks) + connected to this backend, in the format: + + projects/{project}/locations/{location}/connections/{connection}/gitRepositoryLinks/{repositoryLink} + required: true + - name: rootDirectory + type: String + description: |- + If `repository` is provided, the directory relative to the root of the + repository to use as the root for the deployed web app. + - name: managedResources + type: Array + description: A list of the resources managed by this backend. + output: true + item_type: + type: NestedObject + properties: + - name: runService + type: NestedObject + description: |- + A managed Cloud Run + [`service`](https://cloud.google.com/run/docs/reference/rest/v2/projects.locations.services#resource:-service). + properties: + - name: service + type: String + description: |- + The name of the Cloud Run + [`service`](https://cloud.google.com/run/docs/reference/rest/v2/projects.locations.services#resource:-service), + in the format: + + projects/{project}/locations/{location}/services/{serviceId} diff --git a/mmv1/products/firebaseapphosting/product.yaml b/mmv1/products/firebaseapphosting/product.yaml new file mode 100644 index 000000000000..dba6d56e21ba --- /dev/null +++ b/mmv1/products/firebaseapphosting/product.yaml @@ -0,0 +1,24 @@ +# Copyright 2024 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +name: FirebaseAppHosting +display_name: Firebase App Hosting +scopes: + - https://www.googleapis.com/auth/cloud-platform +versions: + - base_url: https://firebaseapphosting.googleapis.com/v1beta/ + name: beta + # GA not available yet + # - base_url: https://firebaseapphosting.googleapis.com/v1main/ + # name: ga diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl new file mode 100644 index 000000000000..9d792e7517b0 --- /dev/null +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl @@ -0,0 +1,18 @@ +resource "google_firebase_app_hosting_backend" "example" { + project = "{{index $.TestEnvVars "project_id"}}" + location = "{{index $.Vars "location"}}" + backend_id = "{{index $.Vars "backend_id"}}" + app_id = "{{index $.Vars "app_id"}}" + display_name = "{{index $.Vars "display_name"}}" + serving_locality = "{{index $.Vars "serving_locality"}}" + service_account = "firebase-app-hosting-compute@{{index $.TestEnvVars "project_id"}}.iam.gserviceaccount.com" + environment = "prod" + + annotations = { + "key" = "value" + } + + labels = { + "key" = "value" + } +} diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl new file mode 100644 index 000000000000..47a76efe0caf --- /dev/null +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl @@ -0,0 +1,60 @@ +resource "google_firebase_app_hosting_backend" "example" { + project = "{{index $.TestEnvVars "project_id"}}" + location = "{{index $.Vars "location"}}" + backend_id = "{{index $.Vars "backend_id"}}" + app_id = "{{index $.Vars "app_id"}}" + display_name = "{{index $.Vars "display_name"}}" + serving_locality = "{{index $.Vars "serving_locality"}}" + service_account = "firebase-app-hosting-compute@{{index $.TestEnvVars "project_id"}}.iam.gserviceaccount.com" + environment = "prod" + + annotations = { + "key" = "value" + } + + labels = { + "key" = "value" + } + + codebase { + repository = google_developer_connect_git_repository_link.my-repository.name + root_directory = "/" + } +} + +resource "google_developer_connect_connection" "my-connection" { + project = "{{index $.TestEnvVars "project_id"}}" + location = "{{index $.Vars "location"}}" + connection_id = "tf-test-connection-new" + github_config { + github_app = "FIREBASE" + } + depends_on = [google_project_iam_member.devconnect-secret] +} + +resource "google_developer_connect_git_repository_link" "my-repository" { + project = "{{index $.TestEnvVars "project_id"}}" + location = "{{index $.Vars "location"}}" + + git_repository_link_id = "my-repo" + parent_connection = google_developer_connect_connection.my-connection.connection_id + clone_uri = "https://github.com/myuser/myrepo.git" +} + +output "next_steps" { + description = "Follow the action_uri if present to continue setup" + value = google_developer_connect_connection.my-connection.installation_state +} + +# Setup permissions. Only needed once per project +resource "google_project_service_identity" "devconnect-p4sa" { + provider = google-beta + project = "{{index $.TestEnvVars "project_id"}}" + service = "developerconnect.googleapis.com" +} + +resource "google_project_iam_member" "devconnect-secret" { + project = "{{index $.TestEnvVars "project_id"}}" + role = "roles/secretmanager.admin" + member = google_project_service_identity.devconnect-p4sa.member +} From 4ec72a295ec2c3c304298e1b67d25fcfba92c0a5 Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Tue, 11 Feb 2025 10:12:06 -0500 Subject: [PATCH 2/8] Add service account setup --- mmv1/products/firebaseapphosting/Backend.yaml | 39 ++++++++------- mmv1/products/firebaseapphosting/product.yaml | 6 +-- ...firebase_app_hosting_backend_basic.tf.tmpl | 48 ++++++++++++++++++- ...irebase_app_hosting_backend_github.tf.tmpl | 10 ++++ 4 files changed, 81 insertions(+), 22 deletions(-) diff --git a/mmv1/products/firebaseapphosting/Backend.yaml b/mmv1/products/firebaseapphosting/Backend.yaml index b7e65c73e7ed..3fc37b15b596 100644 --- a/mmv1/products/firebaseapphosting/Backend.yaml +++ b/mmv1/products/firebaseapphosting/Backend.yaml @@ -26,35 +26,38 @@ import_format: - "projects/{{project}}/locations/{{location}}/backends/{{backend_id}}" - "{{project}}/{{location}}/{{backend_id}}" - "{{location}}/{{backend_id}}" +min_version: beta examples: - name: firebase_app_hosting_backend_basic primary_resource_id: example + min_version: beta vars: - location: 'us-central1' - backend_id: 'my-backend' - app_id: '1:0000000000:web:674cde32020e16fbce9dbd' - display_name: 'My Backend' - serving_locality: 'GLOBAL_ACCESS' + location: "us-central1" + backend_id: "my-backend" + app_id: "1:0000000000:web:674cde32020e16fbce9dbd" + display_name: "My Backend" + serving_locality: "GLOBAL_ACCESS" test_env_vars: - project_id: 'PROJECT_NAME' + project_id: "PROJECT_NAME" test_vars_overrides: - 'location': '"us-central1"' - 'serving_locality': '"GLOBAL_ACCESS"' - 'app_id': '"1:0000000000:web:674cde32020e16fbce9dbd"' + "location": '"us-central1"' + "serving_locality": '"GLOBAL_ACCESS"' + "app_id": '"1:0000000000:web:674cde32020e16fbce9dbd"' - name: firebase_app_hosting_backend_github primary_resource_id: example + min_version: beta vars: - location: 'us-central1' - backend_id: 'my-backend-gh' - app_id: 'firebase:app:id' - display_name: 'My Backend' - serving_locality: 'GLOBAL_ACCESS' + location: "us-central1" + backend_id: "my-backend-gh" + app_id: "firebase:app:id" + display_name: "My Backend" + serving_locality: "GLOBAL_ACCESS" test_env_vars: - project_id: 'PROJECT_NAME' + project_id: "PROJECT_NAME" test_vars_overrides: - 'location': '"us-central1"' - 'serving_locality': '"GLOBAL_ACCESS"' - skip_test: true # Can't establish a Github connection in automated tests. + "location": '"us-central1"' + "serving_locality": '"GLOBAL_ACCESS"' + skip_test: true # Can't establish a Github connection in automated tests. autogen_async: true async: operation: diff --git a/mmv1/products/firebaseapphosting/product.yaml b/mmv1/products/firebaseapphosting/product.yaml index dba6d56e21ba..a4c27205262d 100644 --- a/mmv1/products/firebaseapphosting/product.yaml +++ b/mmv1/products/firebaseapphosting/product.yaml @@ -19,6 +19,6 @@ scopes: versions: - base_url: https://firebaseapphosting.googleapis.com/v1beta/ name: beta - # GA not available yet - # - base_url: https://firebaseapphosting.googleapis.com/v1main/ - # name: ga +# GA not available yet +# - base_url: https://firebaseapphosting.googleapis.com/v1main/ +# name: ga diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl index 9d792e7517b0..a81b0e0fae6c 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl @@ -1,11 +1,57 @@ +# Service account setup only required once per project. +resource "google_service_account" "service_account" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + + # Must be firebase-app-hosting-compute + account_id = "firebase-app-hosting-compute" + display_name = "Firebase App Hosting compute service account" + + # Do not throw if already exists + create_ignore_already_exists = true +} + +resource "google_project_iam_member" "app_hosting_sa_developerconnect" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + + # For reading connected Github repos + role = "roles/developerconnect.readTokenAccessor" + member = google_service_account.service_account.member +} + +resource "google_project_iam_member" "app_hosting_sa_adminsdk" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + + # For Firebase Admin SDK + role = "roles/firebase.sdkAdminServiceAgent" + member = google_service_account.service_account.member +} + +resource "google_project_iam_member" "app_hosting_sa_runner" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + + # For App Hosting + role = "roles/firebaseapphosting.computeRunner" + member = google_service_account.service_account.member +} + resource "google_firebase_app_hosting_backend" "example" { + provider = google-beta + project = "{{index $.TestEnvVars "project_id"}}" location = "{{index $.Vars "location"}}" backend_id = "{{index $.Vars "backend_id"}}" app_id = "{{index $.Vars "app_id"}}" display_name = "{{index $.Vars "display_name"}}" serving_locality = "{{index $.Vars "serving_locality"}}" - service_account = "firebase-app-hosting-compute@{{index $.TestEnvVars "project_id"}}.iam.gserviceaccount.com" + service_account = google_service_account.service_account.email environment = "prod" annotations = { diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl index 47a76efe0caf..26bcf1040e99 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl @@ -1,4 +1,6 @@ resource "google_firebase_app_hosting_backend" "example" { + provider = google-beta + project = "{{index $.TestEnvVars "project_id"}}" location = "{{index $.Vars "location"}}" backend_id = "{{index $.Vars "backend_id"}}" @@ -23,6 +25,8 @@ resource "google_firebase_app_hosting_backend" "example" { } resource "google_developer_connect_connection" "my-connection" { + provider = google-beta + project = "{{index $.TestEnvVars "project_id"}}" location = "{{index $.Vars "location"}}" connection_id = "tf-test-connection-new" @@ -33,6 +37,8 @@ resource "google_developer_connect_connection" "my-connection" { } resource "google_developer_connect_git_repository_link" "my-repository" { + provider = google-beta + project = "{{index $.TestEnvVars "project_id"}}" location = "{{index $.Vars "location"}}" @@ -48,12 +54,16 @@ output "next_steps" { # Setup permissions. Only needed once per project resource "google_project_service_identity" "devconnect-p4sa" { + provider = google-beta + provider = google-beta project = "{{index $.TestEnvVars "project_id"}}" service = "developerconnect.googleapis.com" } resource "google_project_iam_member" "devconnect-secret" { + provider = google-beta + project = "{{index $.TestEnvVars "project_id"}}" role = "roles/secretmanager.admin" member = google_project_service_identity.devconnect-p4sa.member From 74d24568f14da11550f13f0451fcaa1c2049045f Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Tue, 11 Feb 2025 10:19:03 -0500 Subject: [PATCH 3/8] Add firebaseapphosting to teamcity --- .../terraform/.teamcity/components/inputs/services_beta.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt b/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt index 26f4aac41e5e..197b7202c617 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt @@ -401,6 +401,11 @@ var ServicesListBeta = mapOf( "displayName" to "Firebaseappcheck", "path" to "./google-beta/services/firebaseappcheck" ), + "firebaseapphosting" to mapOf( + "name" to "firebaseapphosting", + "displayName" to "Firebase App Hosting", + "path" to "./google-beta/services/firebaseapphosting" + ), "firebasedatabase" to mapOf( "name" to "firebasedatabase", "displayName" to "Firebasedatabase", From 25c490e2831ce546890369a27818b93c2a8b90ab Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Tue, 11 Feb 2025 10:45:58 -0500 Subject: [PATCH 4/8] Mark managetResources as output --- mmv1/products/firebaseapphosting/Backend.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mmv1/products/firebaseapphosting/Backend.yaml b/mmv1/products/firebaseapphosting/Backend.yaml index 3fc37b15b596..6c60f9d151aa 100644 --- a/mmv1/products/firebaseapphosting/Backend.yaml +++ b/mmv1/products/firebaseapphosting/Backend.yaml @@ -199,12 +199,14 @@ properties: properties: - name: runService type: NestedObject + output: true description: |- A managed Cloud Run [`service`](https://cloud.google.com/run/docs/reference/rest/v2/projects.locations.services#resource:-service). properties: - name: service type: String + output: true description: |- The name of the Cloud Run [`service`](https://cloud.google.com/run/docs/reference/rest/v2/projects.locations.services#resource:-service), From e4857b9273719900d0780687e96fd912e2133803 Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Thu, 13 Feb 2025 10:11:47 -0500 Subject: [PATCH 5/8] Add API enablement for firebaseapphosting --- .../firebase_app_hosting_backend_basic.tf.tmpl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl index a81b0e0fae6c..eea4e5dedc86 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl @@ -42,6 +42,16 @@ resource "google_project_iam_member" "app_hosting_sa_runner" { member = google_service_account.service_account.member } +# Service enablement only required once per project. +resource "google_project_service" "fah" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + service = "firebaseapphosting.googleapis.com" + + disable_on_destroy = false +} + resource "google_firebase_app_hosting_backend" "example" { provider = google-beta @@ -61,4 +71,6 @@ resource "google_firebase_app_hosting_backend" "example" { labels = { "key" = "value" } + + depends_on = [google_project_service.fah] } From 1cad455f69a1e99d555cfbffcb6a6f2b10f7103e Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Thu, 27 Feb 2025 21:47:59 -0500 Subject: [PATCH 6/8] Add more tests & hard-code unimportant fields --- mmv1/products/firebaseapphosting/Backend.yaml | 28 ++-- ...firebase_app_hosting_backend_full.tf.tmpl} | 14 +- ...irebase_app_hosting_backend_github.tf.tmpl | 58 ++++---- ...rebase_app_hosting_backend_minimal.tf.tmpl | 48 +++++++ ...ource_firebase_app_hosting_backend_test.go | 126 ++++++++++++++++++ 5 files changed, 222 insertions(+), 52 deletions(-) rename mmv1/templates/terraform/examples/{firebase_app_hosting_backend_basic.tf.tmpl => firebase_app_hosting_backend_full.tf.tmpl} (85%) create mode 100644 mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl create mode 100644 mmv1/third_party/terraform/services/firebaseapphosting/resource_firebase_app_hosting_backend_test.go diff --git a/mmv1/products/firebaseapphosting/Backend.yaml b/mmv1/products/firebaseapphosting/Backend.yaml index 6c60f9d151aa..b3cda10f5185 100644 --- a/mmv1/products/firebaseapphosting/Backend.yaml +++ b/mmv1/products/firebaseapphosting/Backend.yaml @@ -28,36 +28,28 @@ import_format: - "{{location}}/{{backend_id}}" min_version: beta examples: - - name: firebase_app_hosting_backend_basic + - name: firebase_app_hosting_backend_minimal primary_resource_id: example min_version: beta vars: - location: "us-central1" - backend_id: "my-backend" - app_id: "1:0000000000:web:674cde32020e16fbce9dbd" - display_name: "My Backend" - serving_locality: "GLOBAL_ACCESS" + backend_id: "mini" + test_env_vars: + project_id: "PROJECT_NAME" + - name: firebase_app_hosting_backend_full + primary_resource_id: example + min_version: beta + vars: + backend_id: "full" test_env_vars: project_id: "PROJECT_NAME" - test_vars_overrides: - "location": '"us-central1"' - "serving_locality": '"GLOBAL_ACCESS"' - "app_id": '"1:0000000000:web:674cde32020e16fbce9dbd"' - name: firebase_app_hosting_backend_github primary_resource_id: example min_version: beta vars: - location: "us-central1" backend_id: "my-backend-gh" - app_id: "firebase:app:id" - display_name: "My Backend" - serving_locality: "GLOBAL_ACCESS" test_env_vars: project_id: "PROJECT_NAME" - test_vars_overrides: - "location": '"us-central1"' - "serving_locality": '"GLOBAL_ACCESS"' - skip_test: true # Can't establish a Github connection in automated tests. + exclude_test: true # Can't establish a Github connection in automated tests. autogen_async: true async: operation: diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl similarity index 85% rename from mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl rename to mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl index eea4e5dedc86..200796f7450d 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_basic.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl @@ -1,4 +1,4 @@ -# Service account setup only required once per project. +### Include these blocks only once per project if you are starting from scratch ### resource "google_service_account" "service_account" { provider = google-beta @@ -42,7 +42,6 @@ resource "google_project_iam_member" "app_hosting_sa_runner" { member = google_service_account.service_account.member } -# Service enablement only required once per project. resource "google_project_service" "fah" { provider = google-beta @@ -51,16 +50,19 @@ resource "google_project_service" "fah" { disable_on_destroy = false } +### resource "google_firebase_app_hosting_backend" "example" { provider = google-beta project = "{{index $.TestEnvVars "project_id"}}" - location = "{{index $.Vars "location"}}" + + # Choose the region closest to your users + location = "us-central1" backend_id = "{{index $.Vars "backend_id"}}" - app_id = "{{index $.Vars "app_id"}}" - display_name = "{{index $.Vars "display_name"}}" - serving_locality = "{{index $.Vars "serving_locality"}}" + app_id = "1:0000000000:web:674cde32020e16fbce9dbd" + display_name = "My Backend" + serving_locality = "GLOBAL_ACCESS" service_account = google_service_account.service_account.email environment = "prod" diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl index 26bcf1040e99..8622a1fed518 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl @@ -1,34 +1,8 @@ -resource "google_firebase_app_hosting_backend" "example" { - provider = google-beta - - project = "{{index $.TestEnvVars "project_id"}}" - location = "{{index $.Vars "location"}}" - backend_id = "{{index $.Vars "backend_id"}}" - app_id = "{{index $.Vars "app_id"}}" - display_name = "{{index $.Vars "display_name"}}" - serving_locality = "{{index $.Vars "serving_locality"}}" - service_account = "firebase-app-hosting-compute@{{index $.TestEnvVars "project_id"}}.iam.gserviceaccount.com" - environment = "prod" - - annotations = { - "key" = "value" - } - - labels = { - "key" = "value" - } - - codebase { - repository = google_developer_connect_git_repository_link.my-repository.name - root_directory = "/" - } -} - resource "google_developer_connect_connection" "my-connection" { provider = google-beta project = "{{index $.TestEnvVars "project_id"}}" - location = "{{index $.Vars "location"}}" + location = "us-central1" connection_id = "tf-test-connection-new" github_config { github_app = "FIREBASE" @@ -40,7 +14,7 @@ resource "google_developer_connect_git_repository_link" "my-repository" { provider = google-beta project = "{{index $.TestEnvVars "project_id"}}" - location = "{{index $.Vars "location"}}" + location = "us-central1" git_repository_link_id = "my-repo" parent_connection = google_developer_connect_connection.my-connection.connection_id @@ -68,3 +42,31 @@ resource "google_project_iam_member" "devconnect-secret" { role = "roles/secretmanager.admin" member = google_project_service_identity.devconnect-p4sa.member } + +resource "google_firebase_app_hosting_backend" "example" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + + # Choose the region closest to your users + location = "us-central1" + backend_id = "{{index $.Vars "backend_id"}}" + app_id = "1:0000000000:web:674cde32020e16fbce9dbd" + display_name = "My Backend" + serving_locality = "GLOBAL_ACCESS" + service_account = "firebase-app-hosting-compute@{{index $.TestEnvVars "project_id"}}.iam.gserviceaccount.com" + environment = "prod" + + annotations = { + "key" = "value" + } + + labels = { + "key" = "value" + } + + codebase { + repository = google_developer_connect_git_repository_link.my-repository.name + root_directory = "/" + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl new file mode 100644 index 000000000000..60134bd331c5 --- /dev/null +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl @@ -0,0 +1,48 @@ +### Include these blocks only once per project if you are starting from scratch ### +resource "google_service_account" "service_account" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + + # Must be firebase-app-hosting-compute + account_id = "firebase-app-hosting-compute" + display_name = "Firebase App Hosting compute service account" + + # Do not throw if already exists + create_ignore_already_exists = true +} + +resource "google_project_iam_member" "app_hosting_sa_runner" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + + # For App Hosting + role = "roles/firebaseapphosting.computeRunner" + member = google_service_account.service_account.member +} + +resource "google_project_service" "fah" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + service = "firebaseapphosting.googleapis.com" + + disable_on_destroy = false +} +### + +resource "google_firebase_app_hosting_backend" "example" { + provider = google-beta + + project = "{{index $.TestEnvVars "project_id"}}" + # Choose the region closest to your users + + location = "us-central1" + backend_id = "{{index $.Vars "backend_id"}}" + app_id = "1:0000000000:web:674cde32020e16fbce9dbd" + serving_locality = "GLOBAL_ACCESS" + service_account = google_service_account.service_account.email + + depends_on = [google_project_service.fah] +} diff --git a/mmv1/third_party/terraform/services/firebaseapphosting/resource_firebase_app_hosting_backend_test.go b/mmv1/third_party/terraform/services/firebaseapphosting/resource_firebase_app_hosting_backend_test.go new file mode 100644 index 000000000000..f5e8cf3c3097 --- /dev/null +++ b/mmv1/third_party/terraform/services/firebaseapphosting/resource_firebase_app_hosting_backend_test.go @@ -0,0 +1,126 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package firebaseapphosting_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + "github.com/hashicorp/terraform-provider-google/google/acctest" + "github.com/hashicorp/terraform-provider-google/google/envvar" +) + +func TestAccFirebaseAppHostingBackend_update(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_id": envvar.GetTestProjectFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + CheckDestroy: testAccCheckFirebaseAppHostingBackendDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccFirebaseAppHostingBackend_firebaseAppHostingBackendBefore(context), + }, + { + ResourceName: "google_firebase_app_hosting_backend.example", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations", "backend_id", "labels", "location", "terraform_labels"}, + }, + { + Config: testAccFirebaseAppHostingBackend_firebaseAppHostingBackendAfter(context), + }, + { + ResourceName: "google_firebase_app_hosting_backend.example", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations", "backend_id", "labels", "location", "terraform_labels"}, + }, + }, + }) +} + +func testAccFirebaseAppHostingBackend_firebaseAppHostingBackendBefore(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_service_account" "service_account" { + provider = google-beta + + project = "%{project_id}" + + # Must be firebase-app-hosting-compute + account_id = "firebase-app-hosting-compute" + display_name = "Firebase App Hosting compute service account" + + # Do not throw if already exists + create_ignore_already_exists = true +} + +resource "google_firebase_app_hosting_backend" "example" { + provider = google-beta + + project = "%{project_id}" + # Choose the region closest to your users + location = "us-central1" + backend_id = "tf-test-%{random_suffix}" + app_id = "1:0000000000:web:674cde32020e16fbce9dbe" + display_name = "My Backend After" + serving_locality = "GLOBAL_ACCESS" + service_account = google_service_account.service_account.email + environment = "staging" + + annotations = { + "key" = "before" + } + + labels = { + "key" = "before" + } +} +`, context) +} + +func testAccFirebaseAppHostingBackend_firebaseAppHostingBackendAfter(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_service_account" "service_account" { + provider = google-beta + + project = "%{project_id}" + + # Must be firebase-app-hosting-compute + account_id = "firebase-app-hosting-compute" + display_name = "Firebase App Hosting compute service account" + + # Do not throw if already exists + create_ignore_already_exists = true +} + +resource "google_firebase_app_hosting_backend" "example" { + provider = google-beta + + project = "%{project_id}" + # Choose the region closest to your users + location = "us-central1" + backend_id = "tf-test-%{random_suffix}" + app_id = "1:0000000000:web:674cde32020e16fbce9dbd" + display_name = "My Backend After" + serving_locality = "GLOBAL_ACCESS" + service_account = google_service_account.service_account.email + environment = "prod" + + annotations = { + "key" = "after" + } + + labels = { + "key" = "after" + } +} +`, context) +} From 5ac6ba8afcbdaa1ca35ce17843c31c54df894bf6 Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Fri, 28 Feb 2025 10:45:45 -0500 Subject: [PATCH 7/8] Add ga tests --- mmv1/products/firebaseapphosting/Backend.yaml | 4 ---- mmv1/products/firebaseapphosting/product.yaml | 5 ++--- .../firebase_app_hosting_backend_full.tf.tmpl | 12 ------------ .../firebase_app_hosting_backend_github.tf.tmpl | 8 -------- .../firebase_app_hosting_backend_minimal.tf.tmpl | 8 -------- .../.teamcity/components/inputs/services_ga.kt | 5 +++++ .../resource_firebase_app_hosting_backend_test.go | 10 +--------- 7 files changed, 8 insertions(+), 44 deletions(-) diff --git a/mmv1/products/firebaseapphosting/Backend.yaml b/mmv1/products/firebaseapphosting/Backend.yaml index b3cda10f5185..46144847f68f 100644 --- a/mmv1/products/firebaseapphosting/Backend.yaml +++ b/mmv1/products/firebaseapphosting/Backend.yaml @@ -26,25 +26,21 @@ import_format: - "projects/{{project}}/locations/{{location}}/backends/{{backend_id}}" - "{{project}}/{{location}}/{{backend_id}}" - "{{location}}/{{backend_id}}" -min_version: beta examples: - name: firebase_app_hosting_backend_minimal primary_resource_id: example - min_version: beta vars: backend_id: "mini" test_env_vars: project_id: "PROJECT_NAME" - name: firebase_app_hosting_backend_full primary_resource_id: example - min_version: beta vars: backend_id: "full" test_env_vars: project_id: "PROJECT_NAME" - name: firebase_app_hosting_backend_github primary_resource_id: example - min_version: beta vars: backend_id: "my-backend-gh" test_env_vars: diff --git a/mmv1/products/firebaseapphosting/product.yaml b/mmv1/products/firebaseapphosting/product.yaml index a4c27205262d..db8a266d1c7b 100644 --- a/mmv1/products/firebaseapphosting/product.yaml +++ b/mmv1/products/firebaseapphosting/product.yaml @@ -19,6 +19,5 @@ scopes: versions: - base_url: https://firebaseapphosting.googleapis.com/v1beta/ name: beta -# GA not available yet -# - base_url: https://firebaseapphosting.googleapis.com/v1main/ -# name: ga + - base_url: https://firebaseapphosting.googleapis.com/v1main/ + name: ga diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl index 200796f7450d..d1acbed8ae17 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl @@ -1,7 +1,5 @@ ### Include these blocks only once per project if you are starting from scratch ### resource "google_service_account" "service_account" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" # Must be firebase-app-hosting-compute @@ -13,8 +11,6 @@ resource "google_service_account" "service_account" { } resource "google_project_iam_member" "app_hosting_sa_developerconnect" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" # For reading connected Github repos @@ -23,8 +19,6 @@ resource "google_project_iam_member" "app_hosting_sa_developerconnect" { } resource "google_project_iam_member" "app_hosting_sa_adminsdk" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" # For Firebase Admin SDK @@ -33,8 +27,6 @@ resource "google_project_iam_member" "app_hosting_sa_adminsdk" { } resource "google_project_iam_member" "app_hosting_sa_runner" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" # For App Hosting @@ -43,8 +35,6 @@ resource "google_project_iam_member" "app_hosting_sa_runner" { } resource "google_project_service" "fah" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" service = "firebaseapphosting.googleapis.com" @@ -53,8 +43,6 @@ resource "google_project_service" "fah" { ### resource "google_firebase_app_hosting_backend" "example" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" # Choose the region closest to your users diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl index 8622a1fed518..b2c1132a0937 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl @@ -1,6 +1,4 @@ resource "google_developer_connect_connection" "my-connection" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" location = "us-central1" connection_id = "tf-test-connection-new" @@ -11,8 +9,6 @@ resource "google_developer_connect_connection" "my-connection" { } resource "google_developer_connect_git_repository_link" "my-repository" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" location = "us-central1" @@ -36,16 +32,12 @@ resource "google_project_service_identity" "devconnect-p4sa" { } resource "google_project_iam_member" "devconnect-secret" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" role = "roles/secretmanager.admin" member = google_project_service_identity.devconnect-p4sa.member } resource "google_firebase_app_hosting_backend" "example" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" # Choose the region closest to your users diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl index 60134bd331c5..d5f9b6d76aaa 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl @@ -1,7 +1,5 @@ ### Include these blocks only once per project if you are starting from scratch ### resource "google_service_account" "service_account" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" # Must be firebase-app-hosting-compute @@ -13,8 +11,6 @@ resource "google_service_account" "service_account" { } resource "google_project_iam_member" "app_hosting_sa_runner" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" # For App Hosting @@ -23,8 +19,6 @@ resource "google_project_iam_member" "app_hosting_sa_runner" { } resource "google_project_service" "fah" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" service = "firebaseapphosting.googleapis.com" @@ -33,8 +27,6 @@ resource "google_project_service" "fah" { ### resource "google_firebase_app_hosting_backend" "example" { - provider = google-beta - project = "{{index $.TestEnvVars "project_id"}}" # Choose the region closest to your users diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt index e49a10340d40..0732a8c5f74e 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt @@ -401,6 +401,11 @@ var ServicesListGa = mapOf( "displayName" to "Firebaseappcheck", "path" to "./google/services/firebaseappcheck" ), + "firebaseapphosting" to mapOf( + "name" to "firebaseapphosting", + "displayName" to "Firebase App Hosting", + "path" to "./google/services/firebaseapphosting" + ), "firebasedatabase" to mapOf( "name" to "firebasedatabase", "displayName" to "Firebasedatabase", diff --git a/mmv1/third_party/terraform/services/firebaseapphosting/resource_firebase_app_hosting_backend_test.go b/mmv1/third_party/terraform/services/firebaseapphosting/resource_firebase_app_hosting_backend_test.go index f5e8cf3c3097..d1948d3d3770 100644 --- a/mmv1/third_party/terraform/services/firebaseapphosting/resource_firebase_app_hosting_backend_test.go +++ b/mmv1/third_party/terraform/services/firebaseapphosting/resource_firebase_app_hosting_backend_test.go @@ -22,7 +22,7 @@ func TestAccFirebaseAppHostingBackend_update(t *testing.T) { acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), CheckDestroy: testAccCheckFirebaseAppHostingBackendDestroyProducer(t), Steps: []resource.TestStep{ { @@ -50,8 +50,6 @@ func TestAccFirebaseAppHostingBackend_update(t *testing.T) { func testAccFirebaseAppHostingBackend_firebaseAppHostingBackendBefore(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_service_account" "service_account" { - provider = google-beta - project = "%{project_id}" # Must be firebase-app-hosting-compute @@ -63,8 +61,6 @@ resource "google_service_account" "service_account" { } resource "google_firebase_app_hosting_backend" "example" { - provider = google-beta - project = "%{project_id}" # Choose the region closest to your users location = "us-central1" @@ -89,8 +85,6 @@ resource "google_firebase_app_hosting_backend" "example" { func testAccFirebaseAppHostingBackend_firebaseAppHostingBackendAfter(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_service_account" "service_account" { - provider = google-beta - project = "%{project_id}" # Must be firebase-app-hosting-compute @@ -102,8 +96,6 @@ resource "google_service_account" "service_account" { } resource "google_firebase_app_hosting_backend" "example" { - provider = google-beta - project = "%{project_id}" # Choose the region closest to your users location = "us-central1" From d7e783175d308705acb866edcb43ccab6b913e9f Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Mon, 3 Mar 2025 10:09:17 -0500 Subject: [PATCH 8/8] Reorder example to be dependencies last --- .../firebase_app_hosting_backend_full.tf.tmpl | 46 ++++++------ ...irebase_app_hosting_backend_github.tf.tmpl | 75 ++++++++++--------- ...rebase_app_hosting_backend_minimal.tf.tmpl | 26 +++---- 3 files changed, 75 insertions(+), 72 deletions(-) diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl index d1acbed8ae17..969cb145a126 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_full.tf.tmpl @@ -1,3 +1,26 @@ +resource "google_firebase_app_hosting_backend" "example" { + project = "{{index $.TestEnvVars "project_id"}}" + + # Choose the region closest to your users + location = "us-central1" + backend_id = "{{index $.Vars "backend_id"}}" + app_id = "1:0000000000:web:674cde32020e16fbce9dbd" + display_name = "My Backend" + serving_locality = "GLOBAL_ACCESS" + service_account = google_service_account.service_account.email + environment = "prod" + + annotations = { + "key" = "value" + } + + labels = { + "key" = "value" + } + + depends_on = [google_project_service.fah] +} + ### Include these blocks only once per project if you are starting from scratch ### resource "google_service_account" "service_account" { project = "{{index $.TestEnvVars "project_id"}}" @@ -41,26 +64,3 @@ resource "google_project_service" "fah" { disable_on_destroy = false } ### - -resource "google_firebase_app_hosting_backend" "example" { - project = "{{index $.TestEnvVars "project_id"}}" - - # Choose the region closest to your users - location = "us-central1" - backend_id = "{{index $.Vars "backend_id"}}" - app_id = "1:0000000000:web:674cde32020e16fbce9dbd" - display_name = "My Backend" - serving_locality = "GLOBAL_ACCESS" - service_account = google_service_account.service_account.email - environment = "prod" - - annotations = { - "key" = "value" - } - - labels = { - "key" = "value" - } - - depends_on = [google_project_service.fah] -} diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl index b2c1132a0937..d167fca53ef5 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_github.tf.tmpl @@ -1,11 +1,27 @@ -resource "google_developer_connect_connection" "my-connection" { - project = "{{index $.TestEnvVars "project_id"}}" - location = "us-central1" - connection_id = "tf-test-connection-new" - github_config { - github_app = "FIREBASE" +resource "google_firebase_app_hosting_backend" "example" { + project = "{{index $.TestEnvVars "project_id"}}" + + # Choose the region closest to your users + location = "us-central1" + backend_id = "{{index $.Vars "backend_id"}}" + app_id = "1:0000000000:web:674cde32020e16fbce9dbd" + display_name = "My Backend" + serving_locality = "GLOBAL_ACCESS" + service_account = "firebase-app-hosting-compute@{{index $.TestEnvVars "project_id"}}.iam.gserviceaccount.com" + environment = "prod" + + annotations = { + "key" = "value" + } + + labels = { + "key" = "value" + } + + codebase { + repository = google_developer_connect_git_repository_link.my-repository.name + root_directory = "/" } - depends_on = [google_project_iam_member.devconnect-secret] } resource "google_developer_connect_git_repository_link" "my-repository" { @@ -17,12 +33,7 @@ resource "google_developer_connect_git_repository_link" "my-repository" { clone_uri = "https://github.com/myuser/myrepo.git" } -output "next_steps" { - description = "Follow the action_uri if present to continue setup" - value = google_developer_connect_connection.my-connection.installation_state -} - -# Setup permissions. Only needed once per project +### Include these blocks only once per project if you are starting from scratch ### resource "google_project_service_identity" "devconnect-p4sa" { provider = google-beta @@ -36,29 +47,21 @@ resource "google_project_iam_member" "devconnect-secret" { role = "roles/secretmanager.admin" member = google_project_service_identity.devconnect-p4sa.member } +### -resource "google_firebase_app_hosting_backend" "example" { - project = "{{index $.TestEnvVars "project_id"}}" - - # Choose the region closest to your users - location = "us-central1" - backend_id = "{{index $.Vars "backend_id"}}" - app_id = "1:0000000000:web:674cde32020e16fbce9dbd" - display_name = "My Backend" - serving_locality = "GLOBAL_ACCESS" - service_account = "firebase-app-hosting-compute@{{index $.TestEnvVars "project_id"}}.iam.gserviceaccount.com" - environment = "prod" - - annotations = { - "key" = "value" - } - - labels = { - "key" = "value" +### Include these blocks only once per Github account ### +resource "google_developer_connect_connection" "my-connection" { + project = "{{index $.TestEnvVars "project_id"}}" + location = "us-central1" + connection_id = "tf-test-connection-new" + github_config { + github_app = "FIREBASE" } + depends_on = [google_project_iam_member.devconnect-secret] +} - codebase { - repository = google_developer_connect_git_repository_link.my-repository.name - root_directory = "/" - } -} \ No newline at end of file +output "next_steps" { + description = "Follow the action_uri if present to continue setup" + value = google_developer_connect_connection.my-connection.installation_state +} +### diff --git a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl index d5f9b6d76aaa..78ae1f469844 100644 --- a/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl +++ b/mmv1/templates/terraform/examples/firebase_app_hosting_backend_minimal.tf.tmpl @@ -1,3 +1,16 @@ +resource "google_firebase_app_hosting_backend" "example" { + project = "{{index $.TestEnvVars "project_id"}}" + # Choose the region closest to your users + + location = "us-central1" + backend_id = "{{index $.Vars "backend_id"}}" + app_id = "1:0000000000:web:674cde32020e16fbce9dbd" + serving_locality = "GLOBAL_ACCESS" + service_account = google_service_account.service_account.email + + depends_on = [google_project_service.fah] +} + ### Include these blocks only once per project if you are starting from scratch ### resource "google_service_account" "service_account" { project = "{{index $.TestEnvVars "project_id"}}" @@ -25,16 +38,3 @@ resource "google_project_service" "fah" { disable_on_destroy = false } ### - -resource "google_firebase_app_hosting_backend" "example" { - project = "{{index $.TestEnvVars "project_id"}}" - # Choose the region closest to your users - - location = "us-central1" - backend_id = "{{index $.Vars "backend_id"}}" - app_id = "1:0000000000:web:674cde32020e16fbce9dbd" - serving_locality = "GLOBAL_ACCESS" - service_account = google_service_account.service_account.email - - depends_on = [google_project_service.fah] -}