hashicorp / packer-plugin-googlecompute

Packer plugin for Google Compute Builder
https://www.packer.io/docs/builders/googlecompute
Mozilla Public License 2.0
24 stars 54 forks source link

Infinite loop when a service account that doesn't exist is specified. #26

Open spenczar opened 3 years ago

spenczar commented 3 years ago

Overview of the Issue

When using the Google source, if a service_account is specified which does not exist, then instance creation times out. Logs make it look like it is infinitely retrying in spite of a non-retryable error state.

Reproduction Steps

Use the "googlecompute" source, with service_account set to an account that doesn't exist.

Plugin and Packer version

-> % packer version
Packer v1.7.3

Simplified Packer Buildfile

packer {
  required_plugins {
    googlecompute = {
      version = ">= 0.0.1"
      source  = "github.com/hashicorp/googlecompute"
    }
  }
}

source "googlecompute" "packer-bug-demo" {
  project_id = "..."

  image_name            = "packer-bug-demo"
  source_image_family   = "ubuntu-2004-lts"
  ssh_username          = "packer"
  zone                  = "us-west1-a"
  instance_name         = "packer-bug-demo-packerbuild"
  service_account_email = "notreal"
  machine_type          = "e2-medium"
}

build {
  sources = ["sources.googlecompute.packer-bug-demo"]
}

Operating system and Environment details

-> % uname -a
Linux swnelson-laptop 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Log Fragments and crash.log files

2021/07/07 21:35:43 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:35:43 [INFO] Requesting Google token via GCE API Default Client Token Source...
2021/07/07 21:35:43 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:35:43 [INFO] Instantiating GCE client...
2021/07/07 21:35:43 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:35:43 [INFO] Instantiating OS Login client...
==> googlecompute.packer-bug-demo: Checking image does not exist...
==> googlecompute.packer-bug-demo: Creating temporary RSA SSH key for instance...
==> googlecompute.packer-bug-demo: Using image: ubuntu-2004-focal-v20210702
2021/07/07 21:35:48 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:35:48 [DEBUG] Adding metadata during instance creation...
==> googlecompute.packer-bug-demo: Creating instance...
    googlecompute.packer-bug-demo: Loading zone: us-west1-a
    googlecompute.packer-bug-demo: Loading machine type: e2-medium
    googlecompute.packer-bug-demo: Requesting instance creation...
    googlecompute.packer-bug-demo: Waiting for creation operation to complete...
2021/07/07 21:35:50 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:35:50 Retryable error: retrying for state DONE, got RUNNING
2021/07/07 21:35:52 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:35:52 Retryable error: retrying for state DONE, got RUNNING
2021/07/07 21:35:54 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:35:54 Retryable error: retrying for state DONE, got RUNNING
2021/07/07 21:35:57 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:35:57 Retryable error: retrying for state DONE, got RUNNING
2021/07/07 21:35:59 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:35:59 Retryable error: 1 error(s) occurred:
2021/07/07 21:35:59 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 
2021/07/07 21:35:59 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: * The user does not have access to service account 'notreal'.  User: 'swnelson@uw.edu'.  Ask a project owner to grant you the iam.serviceAccountUser role on the service account
2021/07/07 21:36:01 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 2021/07/07 21:36:01 Retryable error: 1 error(s) occurred:
2021/07/07 21:36:01 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: 
2021/07/07 21:36:01 packer-plugin-googlecompute_v1.0.0_x5.0_linux_amd64 plugin: * The user does not have access to service account 'notreal'.  User: 'swnelson@uw.edu'.  Ask a project owner to grant you the iam.serviceAccountUser role on the service account