【问题标题】:Terraform permissions issue when deploying from GCP gcloud从 GCP gcloud 部署时的 Terraform 权限问题
【发布时间】:2022-01-25 08:07:11
【问题描述】:

我正在尝试使用 terraform 部署一些 GCP 资源。

  1. 已执行 gcloud auth 登录(使用我的 gcp 进行身份验证 帐户,分配的 gcp 项目)。
  2. 已执行 gcloud auth application-default login。
  3. 在项目级别为我的用户帐户 (user99@gmail.com) 和组织级别的 Terraform 服务帐户分配了角色。

现在,当我在本地计算机上从 CLI 运行 terraform 脚本时,我收到“错误 403:调用者没有权限”错误。

我的问题是:

  1. 从我的本地计算机 CLI 运行 terraform 命令时,terraform 使用哪个帐户来部署资源(user99@gmail.com 或 Terraform 服务帐户)?
  2. Terraform 是否抱怨缺少我的 user99@gmail.com 或 Terraform 服务帐户的权限?
  3. 有没有办法检查正在使用哪个帐户在 GCP 上部署资源?
  4. 在 gcloud auth login 不改变项目的情况下,我们可以在其他 GCP 项目中部署资源吗?

【问题讨论】:

    标签: google-cloud-platform terraform


    【解决方案1】:

    如果您在(例如本地)主机上运行(即不在 GCP 上):

    1. 使用gcloud 并且您已经拥有gcloud auth application-default-login,那么 (!) Terraform 应该使用该用户的凭据 (gcloud config get-value account)。
    2. 并且环境导出GOOGLE_APPLICATION_CREDENTIALS(这正确地指向服务帐户的密钥),然后将使用服务帐户。

    如果您在 GCP 上(例如在 Compute Engine 上)运行 Terraform,则 Compute Engine 的服务帐号将由 ADC 自动确定(见下文)。

    Google 提供商配置Authentication

    应用默认凭据 (ADC) Finding Credentials Automatically

    【讨论】:

    • 感谢@DazWilkin 的回复和链接。
    • 不客气!
    猜你喜欢
    • 2020-10-21
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    • 2021-02-25
    • 2013-08-29
    • 1970-01-01
    • 2023-03-27
    • 2017-09-08
    相关资源
    最近更新 更多