首页 > 解决方案 > Terraform - GCP - 连接:连接被拒绝

问题描述

上周,一切正常。但是今天当我再次运行 terraform apply 时,我的所有资源都出现以下错误:

错误:发布“https://storage.googleapis.com/storage/v1/b?alt=json&prettyPrint=false&project=PROJECTID”:拨打 tcp SOMEIPTHATCANTSHARE:443:连接:连接被拒绝

我必须:

我尝试“gcloud auth login”和“gcloud auth application-default login”

我必须以下消息:

UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK without a quota project. You might receive a "quota exceeded" or "API not enabled" error. We recommend you rerun \gcloud auth application-default login` and make sure a quota project is added. Or you can use service accounts instead. For more information about service accounts, see[https://cloud.google.com/docs/authentication/](https://cloud.google.com/docs/authentication/).. warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)`

Cannot add the project "A PROJECT FROM ANOTHER GOOGLE CLOUD ACCOUNT" to ADC as the quota project because the account in ADC does not have the "serviceusage.services.use" permission on this project. You might receive a "quota_exceeded" or "API not enabled" error. Run $ gcloud auth application-default set-quota-project to add a quota project.```

标签: google-cloud-platformterraformgcloud

解决方案


除非您非常熟悉 Google 应用程序默认凭据和配额,否则该错误确实没有帮助。

Google 不鼓励将最终用户凭据(在本例中为您使用的gcloud auth list凭据)用作应用程序默认凭据。当然,该设施存在,但只能谨慎使用。

我不清楚所有原因,但一个重要的原因application_default_credentials.json是创建的文件具有与您的最终用户帐户匹配的权限并且是不记名令牌;任何其他获得它的人都可以像您一样行事(r 帐户)。

每当您以这种方式运行软件时,强烈建议您创建一个具有必要权限的服务帐户。

您的问题不清楚您是更喜欢使用Cloud Console还是 Cloud SDK(又名gcloud)。

您将需要:

  1. 创建一个服务帐户(例如Console
  2. 授予它足够的权限(例如Console):
  • BigQuery 创建数据集|表(也许roles/bigquery.dataEditor?);
  • Cloud Storage 创建存储分区(也许roles/storage.admin?)
  1. 可选的*
  • 为服务帐号创建密钥
  • export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json
  1. 再次运行 terraform 脚本

可选* - 如果您从例如 Compute Engine 运行脚本,则无需创建密钥,因为您可以使用 VM 自己的服务帐户。请参阅作为服务帐户进行身份验证


推荐阅读