-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Datasource for retrieving GCS service account #1110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
danawillow
merged 5 commits into
hashicorp:master
from
wayfair-archive:data_gcs_account
Feb 21, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5628707
Datasource for retrieving GCS service account
ishashchuk a141106
Removing duplicated argument
ishashchuk c3cddc8
Merge branch 'master' into data_gcs_account
ishashchuk 6e77467
Gofmt post resolving conflicts
ishashchuk 3d15c6d
Addressing review comment
ishashchuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
google/data_source_google_storage_project_service_account.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
30 changes: 30 additions & 0 deletions
30
google/data_source_google_storage_project_service_account_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" { } | ||
` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
website/docs/d/google_storage_project_service_account.html.markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block here can be replaced with:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be all set now