mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-03 01:01:06 +00:00
Datasource for retrieving GCS service account (#1110)
* Datasource for retrieving GCS service account * Removing duplicated argument * Gofmt post resolving conflicts * Addressing review comment
This commit is contained in:
parent
304c0aa6cb
commit
ef3ea881b1
29
google/data_source_google_storage_project_service_account.go
Normal file
29
google/data_source_google_storage_project_service_account.go
Normal file
@ -0,0 +1,29 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceGoogleStorageProjectServiceAccount() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Read: dataSourceGoogleStorageProjectServiceAccountRead,
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
d.SetId(serviceAccount.EmailAddress)
|
||||
|
||||
return nil
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccDataSourceGoogleStorageProjectServiceAccount_basic(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
resourceName := "data.google_storage_project_service_account.gcs_account"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccCheckGoogleStorageProjectServiceAccount_basic,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet(resourceName, "id"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const testAccCheckGoogleStorageProjectServiceAccount_basic = `
|
||||
data "google_storage_project_service_account" "gcs_account" { }
|
||||
`
|
@ -84,6 +84,7 @@ func Provider() terraform.ResourceProvider {
|
||||
"google_kms_secret": dataSourceGoogleKmsSecret(),
|
||||
"google_organization": dataSourceGoogleOrganization(),
|
||||
"google_storage_object_signed_url": dataSourceGoogleSignedUrl(),
|
||||
"google_storage_project_service_account": dataSourceGoogleStorageProjectServiceAccount(),
|
||||
},
|
||||
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
|
@ -0,0 +1,36 @@
|
||||
---
|
||||
layout: "google"
|
||||
page_title: "Google: google_storage_project_service_account"
|
||||
sidebar_current: "docs-google-datasource-storage-project-service-account"
|
||||
description: |-
|
||||
Get the email address of the project's Google Cloud Storage service account
|
||||
---
|
||||
|
||||
# google\_storage\_project\_service\_account
|
||||
|
||||
Use this data source to get the email address of the project's Google Cloud Storage service account.
|
||||
For more information see
|
||||
[API](https://cloud.google.com/storage/docs/json_api/v1/projects/serviceAccount).
|
||||
|
||||
## Example Usage
|
||||
|
||||
```hcl
|
||||
data "google_storage_project_service_account" "gcs_account" {}
|
||||
|
||||
resource "google_pubsub_topic_iam_binding" "binding" {
|
||||
topic = "${google_pubsub_topic.topic.name}"
|
||||
role = "roles/pubsub.publisher"
|
||||
|
||||
members = ["${data.google_storage_project_service_account.gcs_account.id}"]
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
There are no arguments available for this data source.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported:
|
||||
|
||||
* `id` - The ID of the service account, which is its email address
|
@ -85,6 +85,9 @@
|
||||
<li<%= sidebar_current("docs-google-datasource-signed_url") %>>
|
||||
<a href="/docs/providers/google/d/signed_url.html">google_storage_object_signed_url</a>
|
||||
</li>
|
||||
<li<%= sidebar_current("docs-google-datasource-storage-project-service-account") %>>
|
||||
<a href="/docs/providers/google/d/google_storage_project_service_account.html">google_storage_project_service_account</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user