mitchellh/vagrant-google

Use GOOGLE_APPLICATION_CREDENTIALS environment file

jameswthorne opened this issue · 3 comments

The vagrant-google plugin should support gcloud Application Default Credentials so end users can use their Google User Accounts for authentication instead of only allowing a GCP Service Account and JSON Key.

Currently, vagrant up --provider=google will throw errors if parameters google.google_client_email and google.google_json_key_location are not present or set in the Vagrantfile.

I attempted to point those parameters at my Google User Account email address and the JSON file generated after running gcloud auth application-default login, but Vagrant will throw the error output below. This was attempted with Vagrant version 2.0.3 and vagrant-google plugin 2.0.0.

/Users/example-user/.vagrant.d/gems/2.4.3/gems/fog-google-1.3.3/lib/fog/google/shared.rb:93:in `initialize_google_client': Invalid Google JSON key (ArgumentError)
    from /Users/example-user/.vagrant.d/gems/2.4.3/gems/fog-google-1.3.3/lib/fog/compute/google/real.rb:14:in `initialize'
    from /Users/example-user/.vagrant.d/gems/2.4.3/gems/fog-core-2.1.0/lib/fog/core/service.rb:115:in `new'
    from /Users/example-user/.vagrant.d/gems/2.4.3/gems/fog-core-2.1.0/lib/fog/core/service.rb:115:in `new'
    from /Users/example-user/.vagrant.d/gems/2.4.3/gems/fog-core-2.1.0/lib/fog/core/services_mixin.rb:16:in `new'
    from /Users/example-user/.vagrant.d/gems/2.4.3/gems/fog-core-2.1.0/lib/fog/compute.rb:54:in `new'
    from /Users/example-user/.vagrant.d/gems/2.4.3/gems/vagrant-google-2.0.0/lib/vagrant-google/action/connect_google.rb:42:in `call'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/warden.rb:34:in `call'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/warden.rb:34:in `call'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builder.rb:116:in `call'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/runner.rb:66:in `block in run'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/util/busy.rb:19:in `busy'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/runner.rb:66:in `run'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/machine.rb:227:in `action_raw'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/machine.rb:202:in `block in action'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/environment.rb:592:in `lock'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/machine.rb:188:in `call'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/machine.rb:188:in `action'
    from /Users/example-user/.vagrant.d/gems/2.4.3/gems/vagrant-google-2.0.0/lib/vagrant-google/provider.rb:50:in `state'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/machine.rb:514:in `state'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/machine.rb:145:in `initialize'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/vagrantfile.rb:79:in `new'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/vagrantfile.rb:79:in `machine'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/environment.rb:694:in `machine'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/plugin/v2/command.rb:180:in `block in with_target_vms'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/plugin/v2/command.rb:204:in `block in with_target_vms'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/plugin/v2/command.rb:186:in `each'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/plugin/v2/command.rb:186:in `with_target_vms'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/plugins/commands/up/command.rb:87:in `execute'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/cli.rb:46:in `execute'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/environment.rb:269:in `cli'
    from /opt/vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/bin/vagrant:151:in `<main>'

Hmmm, this is the issue in fog-google I think. Once it's there it should automagically work in vagrant.

I see if this can be done.

depends on fog/fog-google#202

This is a pretty common feature in GCP libs; I'll see if I can open a PR on fog-google so it can be picked up downstream

fog/fog-google#442

It won't fix everything this issue is asking for but it's a start