From ace4cf2831fe113b1a801721ab02241f8ac1073a Mon Sep 17 00:00:00 2001 From: Evan Brown Date: Thu, 4 Aug 2016 14:12:52 -0700 Subject: [PATCH] providers/google: Allow custom Compute Engine service account This commit allows an operator to specify the e-mail address of a service account to use with a Google Compute Engine instance. If no service account e-mail is provided, the default service account is used. Closes #7985 --- resource_compute_instance.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/resource_compute_instance.go b/resource_compute_instance.go index 11aa864d..cb06822f 100644 --- a/resource_compute_instance.go +++ b/resource_compute_instance.go @@ -250,14 +250,16 @@ func resourceComputeInstance() *schema.Resource { "service_account": &schema.Schema{ Type: schema.TypeList, + MaxItems: 1, Optional: true, ForceNew: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "email": &schema.Schema{ Type: schema.TypeString, - Computed: true, ForceNew: true, + Optional: true, + Computed: true, }, "scopes": &schema.Schema{ @@ -524,8 +526,13 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err scopes[i] = canonicalizeServiceScope(v.(string)) } + email := "default" + if v := d.Get(prefix + ".email"); v != nil { + email = v.(string) + } + serviceAccount := &compute.ServiceAccount{ - Email: "default", + Email: email, Scopes: scopes, }