diff --git a/drivers/google/compute_util.go b/drivers/google/compute_util.go index c160c2ce02..6079dfdf32 100644 --- a/drivers/google/compute_util.go +++ b/drivers/google/compute_util.go @@ -177,8 +177,6 @@ func (c *ComputeUtil) createInstance(d *Driver) error { } } - tags := append(d.Tags, firewallTargetTag) - instance := &raw.Instance{ Name: c.instanceName, Description: "docker host vm", @@ -200,7 +198,7 @@ func (c *ComputeUtil) createInstance(d *Driver) error { }, }, Tags: &raw.Tags{ - Items: tags, + Items: parseTags(d), }, ServiceAccounts: []*raw.ServiceAccount{ { @@ -277,6 +275,17 @@ func (c *ComputeUtil) createInstance(d *Driver) error { return nil } +// parseTags computes the tags for the instance. +func parseTags(d *Driver) []string { + tags := []string{firewallTargetTag} + + if d.Tags != "" { + tags = append(tags, strings.Split(d.Tags, ",")...) + } + + return tags +} + // deleteInstance deletes the instance, leaving the persistent disk. func (c *ComputeUtil) deleteInstance() error { log.Infof("Deleting instance.") diff --git a/drivers/google/compute_util_test.go b/drivers/google/compute_util_test.go new file mode 100644 index 0000000000..3bebc3025c --- /dev/null +++ b/drivers/google/compute_util_test.go @@ -0,0 +1,25 @@ +package google + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDefaultTag(t *testing.T) { + tags := parseTags(&Driver{Tags: ""}) + + assert.Equal(t, []string{"docker-machine"}, tags) +} + +func TestAdditionalTag(t *testing.T) { + tags := parseTags(&Driver{Tags: "tag1"}) + + assert.Equal(t, []string{"docker-machine", "tag1"}, tags) +} + +func TestAdditionalTags(t *testing.T) { + tags := parseTags(&Driver{Tags: "tag1,tag2"}) + + assert.Equal(t, []string{"docker-machine", "tag1", "tag2"}, tags) +} diff --git a/drivers/google/google.go b/drivers/google/google.go index 3f7054ee3d..f210c9319b 100644 --- a/drivers/google/google.go +++ b/drivers/google/google.go @@ -23,7 +23,7 @@ type Driver struct { DiskSize int AuthTokenPath string Project string - Tags []string + Tags string } const ( @@ -154,7 +154,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { d.AuthTokenPath = flags.String("google-auth-token") d.Project = flags.String("google-project") d.Scopes = flags.String("google-scopes") - d.Tags = flags.StringSlice("google-tags") + d.Tags = flags.String("google-tags") d.SwarmMaster = flags.Bool("swarm-master") d.SwarmHost = flags.String("swarm-host") d.SwarmDiscovery = flags.String("swarm-discovery")