2018-02-21 21:37:23 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func dataSourceGoogleStorageProjectServiceAccount() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Read: dataSourceGoogleStorageProjectServiceAccountRead,
|
2018-06-19 17:30:20 +00:00
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"project": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
2018-02-21 21:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func dataSourceGoogleStorageProjectServiceAccountRead(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceAccount, err := config.clientStorage.Projects.ServiceAccount.Get(project).Do()
|
|
|
|
if err != nil {
|
|
|
|
return handleNotFoundError(err, d, "GCS service account not found")
|
|
|
|
}
|
|
|
|
|
2018-06-19 17:30:20 +00:00
|
|
|
d.Set("project", project)
|
|
|
|
|
2018-02-21 21:37:23 +00:00
|
|
|
d.SetId(serviceAccount.EmailAddress)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|