ERROR: (gcloud.composer.environments.update) Failed to impersonate when terraform runs impersonating as a second account

ERROR: (gcloud.composer.environments.update) Failed to impersonate when terraform runs impersonating as a second account

当我 运行 我的 terraform 应用时,我收到以下错误(请参阅下文)。

我是 运行ning Terraform 12.x。

GCP Cloud Build 运行 在不同于 project-abcd 的不同项目中(这些帐户所在的位置)

我的 Terraform 代码尝试在 GCP 云构建容器中执行 gcloud 命令。它通过冒充 composer-bq-sa@prj-abcd.iam.gserviceaccount.com

来实现

terraform 运行s 的服务帐户是: terraform_service_account = "org-terraform@abcd.iam.gserviceaccount.com" (模拟前)

此 IAM 帐户 (org-terraform@abcd.iam.gserviceaccount.com)(非服务帐户)具有以下角色绑定(总共 9 个): (该电子邮件没有服务帐户)

Composer Administrator
Compute Network Admin
Service Account Token Creator
Owner
Access Context Manager Admin
Security Admin
Service Account Admin
Logs Configuration Writer
Security Center Notification Configurations Editor

服务帐户 (composer-bq-sa@prj-abcd.iam.gserviceaccount.com) 的成员之一:org-terraform@abcd.iam.gserviceaccount.com 当我查看标题为“有权访问此服务帐户的成员”的屏幕并查看 org-terraform@abcd.iam.gserviceaccount.com 时,我看到它具有以下内容role-bindings(只有 4 个):

Service Account Token Creator
Owner
Security Admin
Service Account Admin

为什么我会收到以下错误,即使 IAM 帐户显然具有正确的角色并且它是它所模拟的服务帐户的成员之一?

错误

module.gcloud_composer_bucket_env_var.null_resource.run_command[0] (local-exec): WARNING: This command 
is using service account impersonation. All API calls will be executed as [**composer-bq-sa@prj-abcd.iam.gserviceaccount.com**].
module.gcloud_composer_bucket_env_var.null_resource.run_command[0] (local-exec): ERROR: 
(gcloud.composer.environments.update) Failed to impersonate [**composer-bq-sa@prj-abcd.iam.gserviceaccount.com**]. Make sure the account that's trying to impersonate it has access to the service account itself and the "roles/iam.serviceAccountTokenCreator" role.

回顾:
为了授予用户模拟服务帐户的权限,请按照 this 文档中列出的说明进行操作。
根据用例,您可以授予用户以下角色:

  • roles/iam.serviceAccountUser
  • roles/iam.serviceAccountTokenCreator
  • roles/iam.workloadIdentityUser