From 590863642c4134948f3e9ad72ddfa9069c44de34 Mon Sep 17 00:00:00 2001 From: Chase Date: Mon, 23 Jul 2018 12:23:11 +0200 Subject: [PATCH] Upper/Lower case (#27) * Upper/Lower case * up version to 0.1.8 * Release v0.1.8 Signed-off-by: Chase Sillevis --- Makefile | 2 +- gsuite/resource_group.go | 5 +++-- gsuite/resource_group_member.go | 16 ++++++++-------- gsuite/resource_group_members.go | 19 ++++++++++--------- gsuite/resource_user.go | 3 ++- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index d1904351..655ee538 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ GOVERSION := 1.9.3 PROJECT := $(CURRENT_DIR:$(GOPATH)/src/%=%) OWNER := $(notdir $(patsubst %/,%,$(dir $(PROJECT)))) NAME := $(notdir $(PROJECT)) -VERSION := 0.1.7 +VERSION := 0.1.8 EXTERNAL_TOOLS = \ github.com/golang/dep/cmd/dep diff --git a/gsuite/resource_group.go b/gsuite/resource_group.go index b8c7b801..5660c293 100644 --- a/gsuite/resource_group.go +++ b/gsuite/resource_group.go @@ -3,6 +3,7 @@ package gsuite import ( "fmt" "log" + "strings" "github.com/hashicorp/terraform/helper/schema" @@ -64,7 +65,7 @@ func resourceGroupCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) group := &directory.Group{ - Email: d.Get("email").(string), + Email: strings.ToLower(d.Get("email").(string)), } if v, ok := d.GetOk("name"); ok { @@ -101,7 +102,7 @@ func resourceGroupUpdate(d *schema.ResourceData, meta interface{}) error { if d.HasChange("email") { log.Printf("[DEBUG] Updating group email: %s", d.Get("email").(string)) - group.Email = d.Get("email").(string) + group.Email = strings.ToLower(d.Get("email").(string)) } if d.HasChange("name") { diff --git a/gsuite/resource_group_member.go b/gsuite/resource_group_member.go index f90cacc0..a9b686a6 100644 --- a/gsuite/resource_group_member.go +++ b/gsuite/resource_group_member.go @@ -73,8 +73,8 @@ func resourceGroupMemberCreate(d *schema.ResourceData, meta interface{}) error { group := d.Get("group").(string) groupMember := &directory.Member{ - Role: d.Get("role").(string), - Email: d.Get("email").(string), + Role: strings.ToUpper(d.Get("role").(string)), + Email: strings.ToLower(d.Get("email").(string)), } var createdGroupMember *directory.Member @@ -101,7 +101,7 @@ func resourceGroupMemberUpdate(d *schema.ResourceData, meta interface{}) error { if d.HasChange("email") { log.Printf("[DEBUG] Updating groupMember email: %s", d.Get("email").(string)) - groupMember.Email = d.Get("email").(string) + groupMember.Email = strings.ToLower(d.Get("email").(string)) } if len(nullFields) > 0 { @@ -111,7 +111,7 @@ func resourceGroupMemberUpdate(d *schema.ResourceData, meta interface{}) error { var updatedGroupMember *directory.Member var err error err = retry(func() error { - updatedGroupMember, err = config.directory.Members.Patch(d.Get("group").(string), d.Id(), groupMember).Do() + updatedGroupMember, err = config.directory.Members.Patch(strings.ToLower(d.Get("group").(string)), d.Id(), groupMember).Do() return err }) @@ -129,7 +129,7 @@ func resourceGroupMemberRead(d *schema.ResourceData, meta interface{}) error { var groupMember *directory.Member var err error err = retry(func() error { - groupMember, err = config.directory.Members.Get(d.Get("group").(string), d.Id()).Do() + groupMember, err = config.directory.Members.Get(strings.ToLower(d.Get("group").(string)), d.Id()).Do() return err }) @@ -138,7 +138,7 @@ func resourceGroupMemberRead(d *schema.ResourceData, meta interface{}) error { } d.SetId(groupMember.Id) - d.Set("email", groupMember.Email) + d.Set("email", strings.ToLower(groupMember.Email)) d.Set("etag", groupMember.Etag) d.Set("kind", groupMember.Kind) d.Set("status", groupMember.Status) @@ -152,7 +152,7 @@ func resourceGroupMemberDelete(d *schema.ResourceData, meta interface{}) error { var err error err = retry(func() error { - err = config.directory.Members.Delete(d.Get("group").(string), d.Id()).Do() + err = config.directory.Members.Delete(strings.ToLower(d.Get("group").(string)), d.Id()).Do() return err }) if err != nil { @@ -175,7 +175,7 @@ func resourceGroupMemberImporter(d *schema.ResourceData, meta interface{}) ([]*s if len(s) < 2 { return nil, fmt.Errorf("Import via [group]:[member email] or [group]/[member email]!") } - group, member := s[0], s[1] + group, member := strings.ToLower(s[0]), strings.ToLower(s[1]) id, err := config.directory.Members.Get(group, member).Do() diff --git a/gsuite/resource_group_members.go b/gsuite/resource_group_members.go index 5b4958cf..0fe3ac83 100644 --- a/gsuite/resource_group_members.go +++ b/gsuite/resource_group_members.go @@ -3,6 +3,7 @@ package gsuite import ( "fmt" "log" + "strings" "github.com/hashicorp/terraform/helper/schema" directory "google.golang.org/api/admin/directory/v1" @@ -47,7 +48,7 @@ func resourceGroupMembersRead(d *schema.ResourceData, meta interface{}) error { return err } - d.Set("group_email", groupEmail) + d.Set("group_email", strings.ToLower(groupEmail)) d.Set("member", membersToCfg(members)) return nil } @@ -118,7 +119,7 @@ func resourceMembers(d *schema.ResourceData) (members []map[string]interface{}) func createOrUpdateGroupMembers(d *schema.ResourceData, meta interface{}) (string, error) { config := meta.(*Config) - groupEmail := d.Get("group_email").(string) + groupEmail := strings.ToLower(d.Get("group_email").(string)) // Get members from config cfgMembers := resourceMembers(d) @@ -168,8 +169,8 @@ func reconcileMembers(d *schema.ResourceData, cfgMembers, apiMembers []map[strin } else { // The member exists in the config and the API // If role has changed update, otherwise do nothing - cfgRole = cfgMember["role"].(string) - apiRole = apiMember["role"].(string) + cfgRole = strings.ToUpper(cfgMember["role"].(string)) + apiRole = strings.ToUpper(apiMember["role"].(string)) if cfgRole != apiRole { groupMember := &directory.Member{ Role: cfgRole, @@ -183,8 +184,8 @@ func reconcileMembers(d *schema.ResourceData, cfgMembers, apiMembers []map[strin var err error err = retry(func() error { updatedGroupMember, err = config.directory.Members.Patch( - d.Get("group_email").(string), - cfgMember["email"].(string), + strings.ToLower(d.Get("group_email").(string)), + strings.ToLower(cfgMember["email"].(string)), groupMember).Do() return err }) @@ -239,8 +240,8 @@ func getApiMembers(groupEmail string, config *Config) ([]*directory.Member, erro func upsertMember(email, groupEmail, role string, config *Config) error { groupMember := &directory.Member{ - Role: role, - Email: email, + Role: strings.ToUpper(role), + Email: strings.ToLower(email), } // Check if the email address belongs to a user, or to a group @@ -367,7 +368,7 @@ func resourceGroupMembersImporter(d *schema.ResourceData, meta interface{}) ([]* var group *directory.Group var err error err = retry(func() error { - group, err = config.directory.Groups.Get(d.Id()).Do() + group, err = config.directory.Groups.Get(strings.ToLower(d.Id())).Do() return err }) diff --git a/gsuite/resource_user.go b/gsuite/resource_user.go index f65bd14e..7a233cbf 100644 --- a/gsuite/resource_user.go +++ b/gsuite/resource_user.go @@ -3,6 +3,7 @@ package gsuite import ( "fmt" "log" + "strings" "github.com/hashicorp/terraform/helper/schema" @@ -289,7 +290,7 @@ func resourceUserCreate(d *schema.ResourceData, meta interface{}) error { } if v, ok := d.GetOk("primary_email"); ok { log.Printf("[DEBUG] Setting %s: %s", "primary_email", v.(string)) - user.PrimaryEmail = v.(string) + user.PrimaryEmail = strings.ToLower(v.(string)) } if v, ok := d.GetOk("password"); ok { log.Printf("[DEBUG] Setting %s: %s", "password", v.(string))