首页 文章

由于服务帐户错误,无法在Google Cloud中使用打包程序创建图像

提问于
浏览
1
  • 我在Gcloud中创建了一个服务帐户 .

  • 在我的Mac上安装了Gcloud .

当我运行我的包装工模板时,它抱怨这个帐户,我不知道它来自哪里 .

包装工模板:

{
  "builders": [
    {
      "type": "googlecompute",
      "account_file": "/Users/Joe/Downloads/account.json",
      "project_id": "rare-truck-123456",
      "source_image": "centos-7-v20180129",
      "zone": "us-west1-a",
      "ssh_username": "centos"
    }
  ]
}

错误:

➜  packer git:(master) ✗ packer build release_google_image.json
googlecompute output will be in this color.

==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Using image: centos-7-v20180129
==> googlecompute: Creating instance...
    googlecompute: Loading zone: us-west1-a
    googlecompute: Loading machine type: n1-standard-1
    googlecompute: Loading network: default
    googlecompute: Requesting instance creation...
    googlecompute: Waiting for creation operation to complete...
==> googlecompute: Error creating instance: 1 error(s) occurred:
==> googlecompute: 
==> googlecompute: * The resource '123412341234-compute@developer.gserviceaccount.com' of type 'serviceAccount' was not found.
Build 'googlecompute' errored: Error creating instance: 1 error(s) occurred:

* The resource '123412341234-compute@developer.gserviceaccount.com' of type 'serviceAccount' was not found.

==> Some builds didn't complete successfully and had errors:
--> googlecompute: Error creating instance: 1 error(s) occurred:

* The resource '123412341234-compute@developer.gserviceaccount.com' of type 'serviceAccount' was not found.

==> Builds finished but no artifacts were created.

为什么要尝试使用 123412341234-compute@developer.gserviceaccount.com

我在谷歌 Cloud 中的项目下创建了一个具有计算管理员v1权限的服务帐户,我下载了我的json文件并将其重命名为accounts.json . 该服务帐户的名称是不同的( release-builder@rare-truck-123456.iam.gserviceaccount.com ),但是打包器似乎忽略它并追踪一些奇怪的帐户 .

甚至我的cli命令 gcloud info 也会返回正确的服务帐户:

Google Cloud SDK [188.0.1]

Platform: [Mac OS X, x86_64] ('Darwin', 'Alexs-MacBook-Pro.local', '16.7.0', 'Darwin Kernel Version 16.7.0: Thu Jan 11 22:59:40 PST 2018; root:xnu-3789.73.8~1/RELEASE_X86_64', 'x86_64', 'i386')
Python Version: [2.7.14 (default, Sep 25 2017, 09:53:22)  [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]]
Python Location: [/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python]
Site Packages: [Disabled]

Installation Root: [/Users/Joe/Downloads/google-cloud-sdk]
Installed Components:
  core: [2018.02.08]
  gsutil: [4.28]
  bq: [2.0.28]
System PATH: [/Users/Joe/Downloads/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
Python PATH: [/Users/Joe/Downloads/google-cloud-sdk/lib/third_party:/Users/Joe/Downloads/google-cloud-sdk/lib:/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python27.zip:/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7:/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin:/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac:/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages:/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk:/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old:/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload]
Cloud SDK on PATH: [True]
Kubectl on PATH: [False]

Installation Properties: [/Users/Joe/Downloads/google-cloud-sdk/properties]
User Config Directory: [/Users/Joe/.config/gcloud]
Active Configuration Name: [default]
Active Configuration Path: [/Users/Joe/.config/gcloud/configurations/config_default]

Account: [release-builder@rare-truck-123456.iam.gserviceaccount.com]
Project: [rare-truck-123456]

Current Properties:
  [core]
    project: [rare-truck-123456]
    account: [release-builder@rare-truck-123456.iam.gserviceaccount.com]
    disable_usage_reporting: [True]
  [compute]
    region: [us-west1]
    zone: [us-west1-a]

Logs Directory: [/Users/Joe/.config/gcloud/logs]
Last Log File: [/Users/Joe/.config/gcloud/logs/2018.02.09/15.51.18.911677.log]

git: [git version 2.14.3 (Apple Git-98)]
ssh: [OpenSSH_7.4p1, LibreSSL 2.5.0]

1 回答

  • 2

    Google Compute Engine实例使用默认服务帐户与Google平台进行更好的集成 .

    正如您可以阅读文档[1]:“(...)如果用户将管理配置为作为服务帐户运行的虚拟机实例,您还必须授予roles / iam.serviceAccountActor角色 . ”

    您需要将“服务帐户用户”角色添加到您的服务帐户,才能创建Google Compute Engine实例 .

    [1] https://cloud.google.com/iam/docs/understanding-roles#compute_name_short_roles

相关问题