Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
drivers/google: Add support for non-default service account
Browse files Browse the repository at this point in the history
Add the --google-service-account flag to create VMs that are not
provisioned with the default service account.

Signed-off-by: Peter Schultz <peter.schultz@classmarkets.com>
  • Loading branch information
pschultz committed Jul 3, 2018
1 parent eae38c1 commit bfa0cf6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion drivers/google/compute_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (c *ComputeUtil) createInstance(d *Driver) error {
},
ServiceAccounts: []*raw.ServiceAccount{
{
Email: "default",
Email: d.ServiceAccount,
Scopes: strings.Split(d.Scopes, ","),
},
},
Expand Down
44 changes: 27 additions & 17 deletions drivers/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Driver struct {
Preemptible bool
UseInternalIP bool
UseInternalIPOnly bool
ServiceAccount string
Scopes string
DiskSize int
Project string
Expand All @@ -35,15 +36,16 @@ type Driver struct {
}

const (
defaultZone = "us-central1-a"
defaultUser = "docker-user"
defaultMachineType = "n1-standard-1"
defaultImageName = "ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20170721"
defaultScopes = "https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write"
defaultDiskType = "pd-standard"
defaultDiskSize = 10
defaultNetwork = "default"
defaultSubnetwork = ""
defaultZone = "us-central1-a"
defaultUser = "docker-user"
defaultMachineType = "n1-standard-1"
defaultImageName = "ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20170721"
defaultServiceAccount = "default"
defaultScopes = "https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write"
defaultDiskType = "pd-standard"
defaultDiskSize = 10
defaultNetwork = "default"
defaultSubnetwork = ""
)

// GetCreateFlags registers the flags this driver adds to
Expand Down Expand Up @@ -79,6 +81,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "GCE Project",
EnvVar: "GOOGLE_PROJECT",
},
mcnflag.StringFlag{
Name: "google-service-account",
Usage: "GCE Service Account for the VM (email address)",
Value: defaultServiceAccount,
EnvVar: "GOOGLE_SERVICE_ACCOUNT",
},
mcnflag.StringFlag{
Name: "google-scopes",
Usage: "GCE Scopes (comma-separated if multiple scopes)",
Expand Down Expand Up @@ -150,14 +158,15 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
// NewDriver creates a Driver with the specified storePath.
func NewDriver(machineName string, storePath string) *Driver {
return &Driver{
Zone: defaultZone,
DiskType: defaultDiskType,
DiskSize: defaultDiskSize,
MachineType: defaultMachineType,
MachineImage: defaultImageName,
Network: defaultNetwork,
Subnetwork: defaultSubnetwork,
Scopes: defaultScopes,
Zone: defaultZone,
DiskType: defaultDiskType,
DiskSize: defaultDiskSize,
MachineType: defaultMachineType,
MachineImage: defaultImageName,
Network: defaultNetwork,
Subnetwork: defaultSubnetwork,
ServiceAccount: defaultServiceAccount,
Scopes: defaultScopes,
BaseDriver: &drivers.BaseDriver{
SSHUser: defaultUser,
MachineName: machineName,
Expand Down Expand Up @@ -205,6 +214,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.Preemptible = flags.Bool("google-preemptible")
d.UseInternalIP = flags.Bool("google-use-internal-ip") || flags.Bool("google-use-internal-ip-only")
d.UseInternalIPOnly = flags.Bool("google-use-internal-ip-only")
d.ServiceAccount = flags.String("google-service-account")
d.Scopes = flags.String("google-scopes")
d.Tags = flags.String("google-tags")
d.OpenPorts = flags.StringSlice("google-open-port")
Expand Down

0 comments on commit bfa0cf6

Please sign in to comment.