Skip to content

Commit 6361d3d

Browse files
vishennat-henderson
authored andcommitted
New datasource: service account and service account key (hashicorp#1535)
1 parent 047f0f3 commit 6361d3d

3 files changed

+119
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
layout: "google"
3+
page_title: "Google: google_service_account"
4+
sidebar_current: "docs-google-datasource-service-account"
5+
description: |-
6+
Get the service account from a project.
7+
---
8+
9+
# google\_service\_account
10+
11+
Get the service account from a project. For more information see
12+
the official [API](https://cloud.google.com/compute/docs/access/service-accounts) documentation.
13+
14+
## Example Usage
15+
16+
```hcl
17+
data "google_service_account" "object_viewer" {
18+
account_id = "object-viewer"
19+
}
20+
```
21+
22+
## Example Usage, save key in Kubernetes secret
23+
```hcl
24+
data "google_service_account" "myaccount" {
25+
account_id = "myaccount-id"
26+
}
27+
28+
resource "google_service_account_key" "mykey" {
29+
service_account_id = "${data.google_service_account.myaccount.name}"
30+
}
31+
32+
resource "kubernetes_secret" "google-application-credentials" {
33+
metadata {
34+
name = "google-application-credentials"
35+
}
36+
data {
37+
credentials.json = "${base64decode(google_service_account_key.mykey.private_key)}"
38+
}
39+
```
40+
41+
## Argument Reference
42+
43+
The following arguments are supported:
44+
45+
* `account_id` - (Required) The Service account id.
46+
47+
* `project` - (Optional) The ID of the project that the service account will be created in.
48+
Defaults to the provider project configuration.
49+
50+
## Attributes Reference
51+
52+
In addition to the arguments listed above, the following computed attributes are
53+
exported:
54+
55+
* `email` - The e-mail address of the service account. This value
56+
should be referenced from any `google_iam_policy` data sources
57+
that would grant the service account privileges.
58+
59+
* `unique_id` - The unique id of the service account.
60+
61+
* `name` - The fully-qualified name of the service account.
62+
63+
* `display_name` - The display name for the service account.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
layout: "google"
3+
page_title: "Google: google_service_account_key"
4+
sidebar_current: "docs-google-datasource-service-account-key"
5+
description: |-
6+
Get a Google Cloud Platform service account Public Key
7+
---
8+
9+
# google\_service\_account\_key
10+
11+
Get service account public key. For more information, see [the official documentation](https://cloud.google.com/iam/docs/creating-managing-service-account-keys) and [API](https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys/get).
12+
13+
14+
## Example Usage
15+
16+
```hcl
17+
data "google_service_account" "myaccount" {
18+
account_id = "myaccount"
19+
}
20+
21+
data "google_service_account_key" "mykey" {
22+
service_account_id = "${data.google_service_account.myaccount.name}"
23+
public_key_type = "TYPE_X509_PEM_FILE"
24+
}
25+
26+
output "mykey_public_key" {
27+
value = "${data.google_service_account_key.mykey.public_key}"
28+
}
29+
```
30+
31+
## Argument Reference
32+
33+
The following arguments are supported:
34+
35+
* `service_account_id` - (Required) The Service account id of the Key Pair. This can be a string in the format
36+
`{ACCOUNT}` or `projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}`, where `{ACCOUNT}` is the email address or
37+
unique id of the service account. If the `{ACCOUNT}` syntax is used, the project will be inferred from the account.
38+
39+
* `project` - (Optional) The ID of the project that the service account will be created in.
40+
Defaults to the provider project configuration.
41+
42+
* `public_key_type` (Optional) The output format of the public key requested. X509_PEM is the default output format.
43+
44+
## Attributes Reference
45+
46+
The following attributes are exported in addition to the arguments listed above:
47+
48+
* `name` - The name used for this key pair
49+
50+
* `public_key` - The public key, base64 encoded

google.erb

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
<li<%= sidebar_current("docs-google-datasource-compute-network") %>>
4141
<a href="/docs/providers/google/d/datasource_compute_network.html">google_compute_network</a>
4242
</li>
43-
</li>
4443
<li<%= sidebar_current("docs-google-datasource-project") %>>
4544
<a href="/docs/providers/google/d/google_project.html">google_project</a>
4645
</li>
@@ -98,6 +97,12 @@
9897
<li<%= sidebar_current("docs-google-datasource-folder") %>>
9998
<a href="/docs/providers/google/d/google_folder.html">google_folder</a>
10099
</li>
100+
<li<%= sidebar_current("docs-google-datasource-service-account") %>>
101+
<a href="/docs/providers/google/d/datasource_google_service_account.html">google_service_account</a>
102+
</li>
103+
<li<%= sidebar_current("docs-google-datasource-service-account-key") %>>
104+
<a href="/docs/providers/google/d/datasource_google_service_account_key.html">google_service_account_key</a>
105+
</li>
101106
<li<%= sidebar_current("docs-google-datasource-signed_url") %>>
102107
<a href="/docs/providers/google/d/signed_url.html">google_storage_object_signed_url</a>
103108
</li>

0 commit comments

Comments
 (0)