【问题标题】:Terraform - GCP - connect: connection refusedTerraform - GCP - 连接:连接被拒绝
【发布时间】:2021-08-27 12:41:27
【问题描述】:

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

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

我必须:

  • 创建 BigQuery 数据集和表。

  • 创建存储桶

我尝试“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-platform terraform gcloud


    【解决方案1】:

    除非您非常熟悉 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 自己的服务帐户。见Authenticating as a service account

    【讨论】:

      【解决方案2】:

      这个答案补充了@DazWilkin 的答案。

      您的应用程序已使用来自的最终用户凭据进行身份验证 没有配额项目的 Google Cloud SDK

      此警告消息表示您使用 Google 用户凭据(Gmail、Workplace 等)而不是服务帐户来访问 Google Cloud API。由于您使用的是用户凭据,因此 Google Cloud 不知道如何管理各种配额,因为未设置默认项目。这些配额是特定于项目的。

      设置配额项目:

      gcloud auth application-default set-quota-project PROJECT_ID
      

      PROJECT_ID 是要检查配额和授予/拒绝权限的项目。

      注意:在运行 set-quota-project 命令之前,必须初始化应用程序默认凭据。

      gcloud auth application-default login
      

      【讨论】:

        猜你喜欢
        • 2017-08-08
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 2018-08-26
        • 2017-08-10
        • 2015-01-30
        • 1970-01-01
        相关资源
        最近更新 更多