Skip to content

Commit

Permalink
[Terraform]: Add data_source_google_storage_transfer_project_service_…
Browse files Browse the repository at this point in the history
…account (#1068)

Merged PR #1068.
  • Loading branch information
akramhussein authored and modular-magician committed Dec 18, 2018
1 parent 5d310bc commit 8721665
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
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" { }
`
9 changes: 9 additions & 0 deletions third_party/terraform/utils/config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 @@ -102,6 +103,7 @@ type Config struct {
<% unless version == 'ga' -%>
clientServiceNetworking *servicenetworking.APIService
<% end -%>
clientStorageTransfer *storagetransfer.Service

bigtableClientFactory *BigtableClientFactory
}
Expand Down Expand Up @@ -412,6 +414,13 @@ func (c *Config) loadAndValidate() error {
c.clientServiceNetworking.UserAgent = userAgent
<% end -%>

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
77 changes: 39 additions & 38 deletions third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,44 +63,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_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_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 third_party/terraform/website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,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

0 comments on commit 8721665

Please sign in to comment.