Unverified Commit fb59f089 authored by David Gageot's avatar David Gageot Committed by GitHub

Merge pull request #4527 from classmarkets/google-service-account

drivers/google: Add support for non-default service account
parents 621d44c1 bfa0cf67
......@@ -265,7 +265,7 @@ func (c *ComputeUtil) createInstance(d *Driver) error {
},
ServiceAccounts: []*raw.ServiceAccount{
{
Email: "default",
Email: d.ServiceAccount,
Scopes: strings.Split(d.Scopes, ","),
},
},
......
......@@ -26,6 +26,7 @@ type Driver struct {
Preemptible bool
UseInternalIP bool
UseInternalIPOnly bool
ServiceAccount string
Scopes string
DiskSize int
Project string
......@@ -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
......@@ -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)",
......@@ -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,
......@@ -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")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment