我已经导入了我的firebase项目作为地形资源,但是在运行terraform plan
时得到了这个:
│ Error: Error when reading or editing FirebaseProject "projects/myproject": googleapi: Error 403: Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the firebase.googleapis.com. We recommend configuring the billing/quota_project setting in gcloud or using a service account through the auth/impersonate_service_account setting. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/. If you are getting this error with curl or similar tools, you may need to specify 'X-Goog-User-Project' HTTP header for quota and billing purposes. For more information regarding 'X-Goog-User-Project' header, please check https://cloud.google.com/apis/docs/system-parameters.
│ Details:
│ [
│ {
│ "@type": "type.googleapis.com/google.rpc.ErrorInfo",
│ "domain": "googleapis.com",
│ "metadata": {
│ "consumer": "projects/774686551450",
│ "service": "firebase.googleapis.com"
│ },
│ "reason": "SERVICE_DISABLED"
│ }
│ ]
│
│ with google_firebase_project.default,
│ on main.tf line 27, in resource "google_firebase_project" "default":
│ 27: resource "google_firebase_project" "default" {
如果我将GOOGLE_APPLICATION_CREDENTIALS
env变量设置为该项目的服务帐户,它似乎有效,但我想避免它,因为每次我更改环境时都需要重新导出该变量。
我已经通过我的用户认证到gcloud
,该用户是所有相关项目的admin。
作为一个外部工具,terraform需要一些使用GCP进行身份验证的方法。你只有两个选择:
- 具有所需权限的服务帐户。
- 具有所需权限的GSuite用户或组。
一个服务或组或用户帐户可以被授予多个项目的权限,尽管这有安全隐患(主要是爆炸半径),我不建议这样做。
在处理不同的项目时切换帐户可能很烦人,但这是目前最好的方法。
如果您正在使用GKE,您可能能够利用它们的工作负载标识特性。我不太确定这是如何工作的,但我相信它可以根据工作负载自动切换到正确的服务帐户。最终,仍然需要单独的服务帐户。