Skip to content

Commit afffe51

Browse files
Service account key keepers (#4390) (#2860)
Co-authored-by: Joe Wilner <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Joe Wilner <[email protected]>
1 parent 8d7f8b2 commit afffe51

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

.changelog/4390.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
serviceaccount: added a `keepers` field to `google_service_account_key` that recreates the field when it is modified
3+
```

google-beta/resource_google_service_account_key.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func resourceGoogleServiceAccountKey() *schema.Resource {
5353
ConflictsWith: []string{"key_algorithm", "private_key_type"},
5454
Description: `A field that allows clients to upload their own public key. If set, use this public key data to create a service account key for given service account. Please note, the expected format for this field is a base64 encoded X509_PEM.`,
5555
},
56+
"keepers": {
57+
Description: "Arbitrary map of values that, when changed, will trigger recreation of resource.",
58+
Type: schema.TypeMap,
59+
Optional: true,
60+
ForceNew: true,
61+
},
5662
// Computed
5763
"name": {
5864
Type: schema.TypeString,

website/docs/r/google_service_account_key.html.markdown

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@ resource "google_service_account_key" "mykey" {
2525
}
2626
```
2727

28+
## Example Usage, creating and regularly rotating a key pair
29+
30+
```hcl
31+
resource "google_service_account" "myaccount" {
32+
account_id = "myaccount"
33+
display_name = "My Service Account"
34+
}
35+
36+
# note this requires the terraform to be run regularly
37+
resource "time_rotating" "mykey_rotation" {
38+
rotate_days = 30
39+
}
40+
41+
resource "google_service_account_key" "mykey" {
42+
service_account_id = google_service_account.myaccount.name
43+
44+
keepers = {
45+
rotation_time = time_rotating.mykey_rotation.rotation_rfc3339
46+
}
47+
}
48+
```
49+
2850
## Example Usage, save key in Kubernetes secret - DEPRECATED
2951

3052
```hcl
@@ -69,6 +91,8 @@ Valid values are listed at
6991

7092
* `public_key_data` (Optional) Public key data to create a service account key for given service account. The expected format for this field is a base64 encoded X509_PEM and it conflicts with `public_key_type` and `private_key_type`.
7193

94+
* `keepers` (Optional) Arbitrary map of values that, when changed, will trigger a new key to be generated.
95+
7296
## Attributes Reference
7397

7498
The following attributes are exported in addition to the arguments listed above:

0 commit comments

Comments
 (0)