mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-03 01:01:06 +00:00
Datasource for GCE service account (#1119)
* Data source for retrieving GCE service account * Added project id for service account lookups (#15) * Renaming attribute project_id -> project
This commit is contained in:
parent
c33b33e1cc
commit
2efa710696
40
google/data_source_google_compute_default_service_account.go
Normal file
40
google/data_source_google_compute_default_service_account.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package google
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dataSourceGoogleComputeDefaultServiceAccount() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
Read: dataSourceGoogleComputeDefaultServiceAccountRead,
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"email": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"project": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceGoogleComputeDefaultServiceAccountRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
config := meta.(*Config)
|
||||||
|
|
||||||
|
project, err := getProject(d, config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
projectCompResource, err := config.clientCompute.Projects.Get(project).Do()
|
||||||
|
if err != nil {
|
||||||
|
return handleNotFoundError(err, d, "GCE service account not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetId(projectCompResource.DefaultServiceAccount)
|
||||||
|
d.Set("email", projectCompResource.DefaultServiceAccount)
|
||||||
|
d.Set("project", project)
|
||||||
|
return nil
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package google
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccDataSourceGoogleComputeDefaultServiceAccount_basic(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
resourceName := "data.google_compute_default_service_account.default"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccCheckGoogleComputeDefaultServiceAccount_basic,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttrSet(resourceName, "id"),
|
||||||
|
resource.TestCheckResourceAttrSet(resourceName, "email"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const testAccCheckGoogleComputeDefaultServiceAccount_basic = `
|
||||||
|
data "google_compute_default_service_account" "default" { }
|
||||||
|
`
|
@ -66,6 +66,7 @@ func Provider() terraform.ResourceProvider {
|
|||||||
"google_client_config": dataSourceGoogleClientConfig(),
|
"google_client_config": dataSourceGoogleClientConfig(),
|
||||||
"google_cloudfunctions_function": dataSourceGoogleCloudFunctionsFunction(),
|
"google_cloudfunctions_function": dataSourceGoogleCloudFunctionsFunction(),
|
||||||
"google_compute_address": dataSourceGoogleComputeAddress(),
|
"google_compute_address": dataSourceGoogleComputeAddress(),
|
||||||
|
"google_compute_default_service_account": dataSourceGoogleComputeDefaultServiceAccount(),
|
||||||
"google_compute_image": dataSourceGoogleComputeImage(),
|
"google_compute_image": dataSourceGoogleComputeImage(),
|
||||||
"google_compute_global_address": dataSourceGoogleComputeGlobalAddress(),
|
"google_compute_global_address": dataSourceGoogleComputeGlobalAddress(),
|
||||||
"google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(),
|
"google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(),
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
layout: "google"
|
||||||
|
page_title: "Google: google_compute_default_service_account"
|
||||||
|
sidebar_current: "docs-google-datasource-compute-default-service-account"
|
||||||
|
description: |-
|
||||||
|
Retrieve default service account used by VMs running in this project
|
||||||
|
---
|
||||||
|
|
||||||
|
# google\_compute\_default\_service\_account
|
||||||
|
|
||||||
|
Use this data source to retrieve default service account for this project
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
data "google_compute_default_service_account" "default" { }
|
||||||
|
|
||||||
|
output "default_account" {
|
||||||
|
value = "${google_compute_default_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 VMs running in this project
|
@ -25,6 +25,9 @@
|
|||||||
<li<%= sidebar_current("docs-google-datasource-compute-address") %>>
|
<li<%= sidebar_current("docs-google-datasource-compute-address") %>>
|
||||||
<a href="/docs/providers/google/d/datasource_compute_address.html">google_compute_address</a>
|
<a href="/docs/providers/google/d/datasource_compute_address.html">google_compute_address</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li<%= sidebar_current("docs-google-datasource-compute-default-service-account") %>>
|
||||||
|
<a href="/docs/providers/google/d/google_compute_default_service_account.html">google_compute_default_service_account</a>
|
||||||
|
</li>
|
||||||
<li<%= sidebar_current("docs-google-datasource-compute-image") %>>
|
<li<%= sidebar_current("docs-google-datasource-compute-image") %>>
|
||||||
<a href="/docs/providers/google/d/datasource_compute_image.html">google_compute_image</a>
|
<a href="/docs/providers/google/d/datasource_compute_image.html">google_compute_image</a>
|
||||||
</li>
|
</li>
|
||||||
|
Loading…
Reference in New Issue
Block a user