diff --git a/google/data_source_google_storage_project_service_account.go b/google/data_source_google_storage_project_service_account.go new file mode 100644 index 00000000..92cfac9d --- /dev/null +++ b/google/data_source_google_storage_project_service_account.go @@ -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 +} diff --git a/google/data_source_google_storage_project_service_account_test.go b/google/data_source_google_storage_project_service_account_test.go new file mode 100644 index 00000000..57445531 --- /dev/null +++ b/google/data_source_google_storage_project_service_account_test.go @@ -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" { } +` diff --git a/google/provider.go b/google/provider.go index 2ebf98f5..d85cecc5 100644 --- a/google/provider.go +++ b/google/provider.go @@ -60,30 +60,31 @@ func Provider() terraform.ResourceProvider { }, DataSourcesMap: map[string]*schema.Resource{ - "google_active_folder": dataSourceGoogleActiveFolder(), - "google_billing_account": dataSourceGoogleBillingAccount(), - "google_dns_managed_zone": dataSourceDnsManagedZone(), - "google_client_config": dataSourceGoogleClientConfig(), - "google_cloudfunctions_function": dataSourceGoogleCloudFunctionsFunction(), - "google_compute_address": dataSourceGoogleComputeAddress(), - "google_compute_image": dataSourceGoogleComputeImage(), - "google_compute_global_address": dataSourceGoogleComputeGlobalAddress(), - "google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(), - "google_compute_network": dataSourceGoogleComputeNetwork(), - "google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(), - "google_compute_zones": dataSourceGoogleComputeZones(), - "google_compute_instance_group": dataSourceGoogleComputeInstanceGroup(), - "google_compute_region_instance_group": dataSourceGoogleComputeRegionInstanceGroup(), - "google_compute_vpn_gateway": dataSourceGoogleComputeVpnGateway(), - "google_compute_forwarding_rule": dataSourceGoogleComputeForwardingRule(), - "google_container_cluster": dataSourceGoogleContainerCluster(), - "google_container_engine_versions": dataSourceGoogleContainerEngineVersions(), - "google_container_registry_repository": dataSourceGoogleContainerRepo(), - "google_container_registry_image": dataSourceGoogleContainerImage(), - "google_iam_policy": dataSourceGoogleIamPolicy(), - "google_kms_secret": dataSourceGoogleKmsSecret(), - "google_organization": dataSourceGoogleOrganization(), - "google_storage_object_signed_url": dataSourceGoogleSignedUrl(), + "google_active_folder": dataSourceGoogleActiveFolder(), + "google_billing_account": dataSourceGoogleBillingAccount(), + "google_dns_managed_zone": dataSourceDnsManagedZone(), + "google_client_config": dataSourceGoogleClientConfig(), + "google_cloudfunctions_function": dataSourceGoogleCloudFunctionsFunction(), + "google_compute_address": dataSourceGoogleComputeAddress(), + "google_compute_image": dataSourceGoogleComputeImage(), + "google_compute_global_address": dataSourceGoogleComputeGlobalAddress(), + "google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(), + "google_compute_network": dataSourceGoogleComputeNetwork(), + "google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(), + "google_compute_zones": dataSourceGoogleComputeZones(), + "google_compute_instance_group": dataSourceGoogleComputeInstanceGroup(), + "google_compute_region_instance_group": dataSourceGoogleComputeRegionInstanceGroup(), + "google_compute_vpn_gateway": dataSourceGoogleComputeVpnGateway(), + "google_compute_forwarding_rule": dataSourceGoogleComputeForwardingRule(), + "google_container_cluster": dataSourceGoogleContainerCluster(), + "google_container_engine_versions": dataSourceGoogleContainerEngineVersions(), + "google_container_registry_repository": dataSourceGoogleContainerRepo(), + "google_container_registry_image": dataSourceGoogleContainerImage(), + "google_iam_policy": dataSourceGoogleIamPolicy(), + "google_kms_secret": dataSourceGoogleKmsSecret(), + "google_organization": dataSourceGoogleOrganization(), + "google_storage_object_signed_url": dataSourceGoogleSignedUrl(), + "google_storage_project_service_account": dataSourceGoogleStorageProjectServiceAccount(), }, ResourcesMap: map[string]*schema.Resource{ diff --git a/website/docs/d/google_storage_project_service_account.html.markdown b/website/docs/d/google_storage_project_service_account.html.markdown new file mode 100644 index 00000000..4a179b4f --- /dev/null +++ b/website/docs/d/google_storage_project_service_account.html.markdown @@ -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 diff --git a/website/google.erb b/website/google.erb index 4add0f88..9b2f95ab 100644 --- a/website/google.erb +++ b/website/google.erb @@ -85,6 +85,9 @@ > google_storage_object_signed_url + > + google_storage_project_service_account +