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
This commit is contained in:
Evan Brown 2016-08-04 14:12:52 -07:00
parent e761259876
commit ace4cf2831

View File

@ -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,
}