Skip to content
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

Add google_storage_transfer_project_service_account data_source #247

Merged
merged 1 commit into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions google-beta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"google.golang.org/api/spanner/v1"
"google.golang.org/api/sqladmin/v1beta4"
"google.golang.org/api/storage/v1"
"google.golang.org/api/storagetransfer/v1"
)

// Config is the configuration structure used to instantiate the Google
Expand Down Expand Up @@ -95,6 +96,7 @@ type Config struct {
clientCloudIoT *cloudiot.Service
clientAppEngine *appengine.APIService
clientServiceNetworking *servicenetworking.APIService
clientStorageTransfer *storagetransfer.Service

bigtableClientFactory *BigtableClientFactory
}
Expand Down Expand Up @@ -397,6 +399,13 @@ func (c *Config) loadAndValidate() error {
}
c.clientServiceNetworking.UserAgent = userAgent

log.Printf("[INFO] Instantiating Google Cloud Storage Transfer Client...")
c.clientStorageTransfer, err = storagetransfer.New(client)
if err != nil {
return err
}
c.clientStorageTransfer.UserAgent = userAgent

return nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package google

import (
"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceGoogleStorageTransferProjectServiceAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleStorageTransferProjectServiceAccountRead,
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Computed: true,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}

func dataSourceGoogleStorageTransferProjectServiceAccountRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

project, err := getProject(d, config)
if err != nil {
return err
}

serviceAccount, err := config.clientStorageTransfer.GoogleServiceAccounts.Get(project).Do()
if err != nil {
return handleNotFoundError(err, d, "Google Cloud Storage Transfer service account not found")
}

d.SetId(serviceAccount.AccountEmail)
d.Set("email", serviceAccount.AccountEmail)
d.Set("project", project)
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package google

import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceGoogleStorageTransferProjectServiceAccount_basic(t *testing.T) {
t.Parallel()

resourceName := "data.google_storage_transfer_project_service_account.default"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGoogleStorageTransferProjectServiceAccount_basic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttrSet(resourceName, "email"),
),
},
},
})
}

const testAccCheckGoogleStorageTransferProjectServiceAccount_basic = `
data "google_storage_transfer_project_service_account" "default" { }
`
77 changes: 39 additions & 38 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,45 @@ 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_backend_service": dataSourceGoogleComputeBackendService(),
"google_compute_default_service_account": dataSourceGoogleComputeDefaultServiceAccount(),
"google_compute_forwarding_rule": dataSourceGoogleComputeForwardingRule(),
"google_compute_image": dataSourceGoogleComputeImage(),
"google_compute_instance": dataSourceGoogleComputeInstance(),
"google_compute_global_address": dataSourceGoogleComputeGlobalAddress(),
"google_compute_instance_group": dataSourceGoogleComputeInstanceGroup(),
"google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(),
"google_compute_network": dataSourceGoogleComputeNetwork(),
"google_compute_regions": dataSourceGoogleComputeRegions(),
"google_compute_region_instance_group": dataSourceGoogleComputeRegionInstanceGroup(),
"google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(),
"google_compute_zones": dataSourceGoogleComputeZones(),
"google_compute_vpn_gateway": dataSourceGoogleComputeVpnGateway(),
"google_compute_ssl_policy": dataSourceGoogleComputeSslPolicy(),
"google_container_cluster": dataSourceGoogleContainerCluster(),
"google_container_engine_versions": dataSourceGoogleContainerEngineVersions(),
"google_container_registry_repository": dataSourceGoogleContainerRepo(),
"google_container_registry_image": dataSourceGoogleContainerImage(),
"google_iam_policy": dataSourceGoogleIamPolicy(),
"google_iam_role": dataSourceGoogleIamRole(),
"google_kms_secret": dataSourceGoogleKmsSecret(),
"google_folder": dataSourceGoogleFolder(),
"google_netblock_ip_ranges": dataSourceGoogleNetblockIpRanges(),
"google_organization": dataSourceGoogleOrganization(),
"google_project": dataSourceGoogleProject(),
"google_project_services": dataSourceGoogleProjectServices(),
"google_service_account": dataSourceGoogleServiceAccount(),
"google_service_account_key": dataSourceGoogleServiceAccountKey(),
"google_storage_bucket_object": dataSourceGoogleStorageBucketObject(),
"google_storage_object_signed_url": dataSourceGoogleSignedUrl(),
"google_storage_project_service_account": dataSourceGoogleStorageProjectServiceAccount(),
"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_backend_service": dataSourceGoogleComputeBackendService(),
"google_compute_default_service_account": dataSourceGoogleComputeDefaultServiceAccount(),
"google_compute_forwarding_rule": dataSourceGoogleComputeForwardingRule(),
"google_compute_image": dataSourceGoogleComputeImage(),
"google_compute_instance": dataSourceGoogleComputeInstance(),
"google_compute_instance_group": dataSourceGoogleComputeInstanceGroup(),
"google_compute_global_address": dataSourceGoogleComputeGlobalAddress(),
"google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(),
"google_compute_network": dataSourceGoogleComputeNetwork(),
"google_compute_regions": dataSourceGoogleComputeRegions(),
"google_compute_region_instance_group": dataSourceGoogleComputeRegionInstanceGroup(),
"google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(),
"google_compute_zones": dataSourceGoogleComputeZones(),
"google_compute_vpn_gateway": dataSourceGoogleComputeVpnGateway(),
"google_compute_ssl_policy": dataSourceGoogleComputeSslPolicy(),
"google_container_cluster": dataSourceGoogleContainerCluster(),
"google_container_engine_versions": dataSourceGoogleContainerEngineVersions(),
"google_container_registry_repository": dataSourceGoogleContainerRepo(),
"google_container_registry_image": dataSourceGoogleContainerImage(),
"google_iam_policy": dataSourceGoogleIamPolicy(),
"google_iam_role": dataSourceGoogleIamRole(),
"google_kms_secret": dataSourceGoogleKmsSecret(),
"google_folder": dataSourceGoogleFolder(),
"google_netblock_ip_ranges": dataSourceGoogleNetblockIpRanges(),
"google_organization": dataSourceGoogleOrganization(),
"google_project": dataSourceGoogleProject(),
"google_project_services": dataSourceGoogleProjectServices(),
"google_service_account": dataSourceGoogleServiceAccount(),
"google_service_account_key": dataSourceGoogleServiceAccountKey(),
"google_storage_bucket_object": dataSourceGoogleStorageBucketObject(),
"google_storage_object_signed_url": dataSourceGoogleSignedUrl(),
"google_storage_project_service_account": dataSourceGoogleStorageProjectServiceAccount(),
"google_storage_transfer_project_service_account": dataSourceGoogleStorageTransferProjectServiceAccount(),
},

ResourcesMap: ResourceMap(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
layout: "google"
page_title: "Google: google_storage_transfer_project_service_account"
sidebar_current: "docs-google-datasource-storage-transfer-project-service-account"
description: |-
Retrieve default service account used by Storage Transfer Jobs running in this project
---

# google\_storage\_transfer\_project\_service\_account

Use this data source to retrieve Storage Transfer service account for this project

## Example Usage

```hcl
data "google_storage_transfer_project_service_account" "default" { }

output "default_account" {
value = "${data.google_storage_transfer_project_service_account.default.email}"
}
```

## Argument Reference

The following arguments are supported:

* `project` - (Optional) The project ID. If it is not provided, the provider project is used.


## Attributes Reference

The following attributes are exported:

* `email` - Email address of the default service account used by Storage Transfer Jobs running in this project
3 changes: 3 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
<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>
<li<%= sidebar_current("docs-google-datasource-storage-transfer-project-service-account") %>>
<a href="/docs/providers/google/d/google_storage_transfer_project_service_account.html">google_storage_transfer_project_service_account</a>
</li>
</ul>
</li>

Expand Down