Skip to content

Commit f2c31b9

Browse files
rainshen49Dawid212
authored andcommitted
Terraform config for Firebase App Hosting Backend resource (GoogleCloudPlatform#13040)
1 parent 30909ec commit f2c31b9

File tree

8 files changed

+527
-0
lines changed

8 files changed

+527
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
# Copyright 2025 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: Backend
16+
description: A Backend is the primary resource of App Hosting.
17+
base_url: projects/{{project}}/locations/{{location}}/backends
18+
update_mask: true
19+
self_link: projects/{{project}}/locations/{{location}}/backends/{{backend_id}}
20+
create_url: projects/{{project}}/locations/{{location}}/backends?backendId={{backend_id}}
21+
# Always forces deletion because the child resource default `Domain` is always present.
22+
delete_url: projects/{{project}}/locations/{{location}}/backends/{{backend_id}}?force=true
23+
update_verb: PATCH
24+
id_format: projects/{{project}}/locations/{{location}}/backends/{{backend_id}}
25+
import_format:
26+
- "projects/{{project}}/locations/{{location}}/backends/{{backend_id}}"
27+
- "{{project}}/{{location}}/{{backend_id}}"
28+
- "{{location}}/{{backend_id}}"
29+
examples:
30+
- name: firebase_app_hosting_backend_minimal
31+
primary_resource_id: example
32+
vars:
33+
backend_id: "mini"
34+
test_env_vars:
35+
project_id: "PROJECT_NAME"
36+
- name: firebase_app_hosting_backend_full
37+
primary_resource_id: example
38+
vars:
39+
backend_id: "full"
40+
test_env_vars:
41+
project_id: "PROJECT_NAME"
42+
- name: firebase_app_hosting_backend_github
43+
primary_resource_id: example
44+
vars:
45+
backend_id: "my-backend-gh"
46+
test_env_vars:
47+
project_id: "PROJECT_NAME"
48+
exclude_test: true # Can't establish a Github connection in automated tests.
49+
autogen_async: true
50+
async:
51+
operation:
52+
timeouts:
53+
insert_minutes: 20
54+
update_minutes: 20
55+
delete_minutes: 20
56+
base_url: "{{op_id}}"
57+
actions:
58+
- create
59+
- delete
60+
- update
61+
type: OpAsync
62+
result:
63+
resource_inside_response: true
64+
include_project: false
65+
autogen_status: QmFja2VuZA==
66+
parameters:
67+
- name: location
68+
type: String
69+
description: The canonical IDs of a Google Cloud location such as "us-east1".
70+
immutable: true
71+
url_param_only: true
72+
required: true
73+
- name: backendId
74+
type: String
75+
description: |-
76+
Id of the backend. Also used as the service ID for Cloud Run, and as part
77+
of the default domain name.
78+
immutable: true
79+
url_param_only: true
80+
required: true
81+
properties:
82+
- name: servingLocality
83+
type: Enum
84+
description: |-
85+
Immutable. Specifies how App Hosting will serve the content for this backend. It will
86+
either be contained to a single region (REGIONAL_STRICT) or allowed to use
87+
App Hosting's global-replicated serving infrastructure (GLOBAL_ACCESS).
88+
enum_values:
89+
- "REGIONAL_STRICT"
90+
- "GLOBAL_ACCESS"
91+
immutable: true
92+
required: true
93+
- name: appId
94+
type: String
95+
description: |-
96+
The [ID of a Web
97+
App](https://firebase.google.com/docs/reference/firebase-management/rest/v1beta1/projects.webApps#WebApp.FIELDS.app_id)
98+
associated with the backend.
99+
required: true
100+
- name: serviceAccount
101+
type: String
102+
description: |-
103+
The name of the service account used for Cloud Build and Cloud Run.
104+
Should have the role roles/firebaseapphosting.computeRunner
105+
or equivalent permissions.
106+
required: true
107+
- name: annotations
108+
type: KeyValueAnnotations
109+
description: |-
110+
Unstructured key value map that may be set by external tools to
111+
store and arbitrary metadata. They are not queryable and should be
112+
preserved when modifying objects.
113+
- name: displayName
114+
type: String
115+
description: Human-readable name. 63 character limit.
116+
- name: environment
117+
type: String
118+
description: |-
119+
The environment name of the backend, used to load environment variables
120+
from environment specific configuration.
121+
- name: labels
122+
type: KeyValueLabels
123+
description: |-
124+
Unstructured key value map that can be used to organize and categorize
125+
objects.
126+
- name: etag
127+
type: Fingerprint
128+
description: |-
129+
Server-computed checksum based on other values; may be sent
130+
on update or delete to ensure operation is done on expected resource.
131+
output: true
132+
- name: name
133+
type: String
134+
description: |-
135+
Identifier. The resource name of the backend.
136+
137+
Format:
138+
139+
`projects/{project}/locations/{locationId}/backends/{backendId}`.
140+
output: true
141+
- name: createTime
142+
type: Time
143+
description: Time at which the backend was created.
144+
output: true
145+
- name: deleteTime
146+
type: Time
147+
description: Time at which the backend was deleted.
148+
output: true
149+
- name: updateTime
150+
type: Time
151+
description: Time at which the backend was last updated.
152+
output: true
153+
- name: uid
154+
type: String
155+
description: System-assigned, unique identifier.
156+
output: true
157+
- name: uri
158+
type: String
159+
description: The primary URI to communicate with the backend.
160+
output: true
161+
- name: codebase
162+
type: NestedObject
163+
description: |-
164+
The connection to an external source repository to watch for event-driven
165+
updates to the backend.
166+
properties:
167+
- name: repository
168+
type: String
169+
description: |-
170+
The resource name for the Developer Connect
171+
[`gitRepositoryLink`](https://cloud.google.com/developer-connect/docs/api/reference/rest/v1/projects.locations.connections.gitRepositoryLinks)
172+
connected to this backend, in the format:
173+
174+
projects/{project}/locations/{location}/connections/{connection}/gitRepositoryLinks/{repositoryLink}
175+
required: true
176+
- name: rootDirectory
177+
type: String
178+
description: |-
179+
If `repository` is provided, the directory relative to the root of the
180+
repository to use as the root for the deployed web app.
181+
- name: managedResources
182+
type: Array
183+
description: A list of the resources managed by this backend.
184+
output: true
185+
item_type:
186+
type: NestedObject
187+
properties:
188+
- name: runService
189+
type: NestedObject
190+
output: true
191+
description: |-
192+
A managed Cloud Run
193+
[`service`](https://cloud.google.com/run/docs/reference/rest/v2/projects.locations.services#resource:-service).
194+
properties:
195+
- name: service
196+
type: String
197+
output: true
198+
description: |-
199+
The name of the Cloud Run
200+
[`service`](https://cloud.google.com/run/docs/reference/rest/v2/projects.locations.services#resource:-service),
201+
in the format:
202+
203+
projects/{project}/locations/{location}/services/{serviceId}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: FirebaseAppHosting
16+
display_name: Firebase App Hosting
17+
scopes:
18+
- https://www.googleapis.com/auth/cloud-platform
19+
versions:
20+
- base_url: https://firebaseapphosting.googleapis.com/v1beta/
21+
name: beta
22+
- base_url: https://firebaseapphosting.googleapis.com/v1main/
23+
name: ga
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
resource "google_firebase_app_hosting_backend" "example" {
2+
project = "{{index $.TestEnvVars "project_id"}}"
3+
4+
# Choose the region closest to your users
5+
location = "us-central1"
6+
backend_id = "{{index $.Vars "backend_id"}}"
7+
app_id = "1:0000000000:web:674cde32020e16fbce9dbd"
8+
display_name = "My Backend"
9+
serving_locality = "GLOBAL_ACCESS"
10+
service_account = google_service_account.service_account.email
11+
environment = "prod"
12+
13+
annotations = {
14+
"key" = "value"
15+
}
16+
17+
labels = {
18+
"key" = "value"
19+
}
20+
21+
depends_on = [google_project_service.fah]
22+
}
23+
24+
### Include these blocks only once per project if you are starting from scratch ###
25+
resource "google_service_account" "service_account" {
26+
project = "{{index $.TestEnvVars "project_id"}}"
27+
28+
# Must be firebase-app-hosting-compute
29+
account_id = "firebase-app-hosting-compute"
30+
display_name = "Firebase App Hosting compute service account"
31+
32+
# Do not throw if already exists
33+
create_ignore_already_exists = true
34+
}
35+
36+
resource "google_project_iam_member" "app_hosting_sa_developerconnect" {
37+
project = "{{index $.TestEnvVars "project_id"}}"
38+
39+
# For reading connected Github repos
40+
role = "roles/developerconnect.readTokenAccessor"
41+
member = google_service_account.service_account.member
42+
}
43+
44+
resource "google_project_iam_member" "app_hosting_sa_adminsdk" {
45+
project = "{{index $.TestEnvVars "project_id"}}"
46+
47+
# For Firebase Admin SDK
48+
role = "roles/firebase.sdkAdminServiceAgent"
49+
member = google_service_account.service_account.member
50+
}
51+
52+
resource "google_project_iam_member" "app_hosting_sa_runner" {
53+
project = "{{index $.TestEnvVars "project_id"}}"
54+
55+
# For App Hosting
56+
role = "roles/firebaseapphosting.computeRunner"
57+
member = google_service_account.service_account.member
58+
}
59+
60+
resource "google_project_service" "fah" {
61+
project = "{{index $.TestEnvVars "project_id"}}"
62+
service = "firebaseapphosting.googleapis.com"
63+
64+
disable_on_destroy = false
65+
}
66+
###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
resource "google_firebase_app_hosting_backend" "example" {
2+
project = "{{index $.TestEnvVars "project_id"}}"
3+
4+
# Choose the region closest to your users
5+
location = "us-central1"
6+
backend_id = "{{index $.Vars "backend_id"}}"
7+
app_id = "1:0000000000:web:674cde32020e16fbce9dbd"
8+
display_name = "My Backend"
9+
serving_locality = "GLOBAL_ACCESS"
10+
service_account = "firebase-app-hosting-compute@{{index $.TestEnvVars "project_id"}}.iam.gserviceaccount.com"
11+
environment = "prod"
12+
13+
annotations = {
14+
"key" = "value"
15+
}
16+
17+
labels = {
18+
"key" = "value"
19+
}
20+
21+
codebase {
22+
repository = google_developer_connect_git_repository_link.my-repository.name
23+
root_directory = "/"
24+
}
25+
}
26+
27+
resource "google_developer_connect_git_repository_link" "my-repository" {
28+
project = "{{index $.TestEnvVars "project_id"}}"
29+
location = "us-central1"
30+
31+
git_repository_link_id = "my-repo"
32+
parent_connection = google_developer_connect_connection.my-connection.connection_id
33+
clone_uri = "https://github.com/myuser/myrepo.git"
34+
}
35+
36+
### Include these blocks only once per project if you are starting from scratch ###
37+
resource "google_project_service_identity" "devconnect-p4sa" {
38+
provider = google-beta
39+
40+
provider = google-beta
41+
project = "{{index $.TestEnvVars "project_id"}}"
42+
service = "developerconnect.googleapis.com"
43+
}
44+
45+
resource "google_project_iam_member" "devconnect-secret" {
46+
project = "{{index $.TestEnvVars "project_id"}}"
47+
role = "roles/secretmanager.admin"
48+
member = google_project_service_identity.devconnect-p4sa.member
49+
}
50+
###
51+
52+
### Include these blocks only once per Github account ###
53+
resource "google_developer_connect_connection" "my-connection" {
54+
project = "{{index $.TestEnvVars "project_id"}}"
55+
location = "us-central1"
56+
connection_id = "tf-test-connection-new"
57+
github_config {
58+
github_app = "FIREBASE"
59+
}
60+
depends_on = [google_project_iam_member.devconnect-secret]
61+
}
62+
63+
output "next_steps" {
64+
description = "Follow the action_uri if present to continue setup"
65+
value = google_developer_connect_connection.my-connection.installation_state
66+
}
67+
###

0 commit comments

Comments
 (0)