Skip to content

Commit a126b72

Browse files
authored
Add support for the Google Firestore UserCreds resource. (#15379)
1 parent 43fa651 commit a126b72

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright 2025 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: 'UserCreds'
16+
description: |
17+
User credentials for a Cloud Firestore with MongoDB compatibility database.
18+
The resource is owned by the database and is deleted along with the database.
19+
references:
20+
guides:
21+
'Authenticate and connect to a database': 'https://cloud.google.com/firestore/mongodb-compatibility/docs/connect'
22+
api: 'https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.userCreds'
23+
base_url: 'projects/{{project}}/databases/{{database}}/userCreds'
24+
self_link: 'projects/{{project}}/databases/{{database}}/userCreds/{{name}}'
25+
immutable: true
26+
create_url: 'projects/{{project}}/databases/{{database}}/userCreds?userCredsId={{name}}'
27+
autogen_async: false
28+
custom_code:
29+
post_create: templates/terraform/post_create/firestore_user_creds.go.tmpl
30+
examples:
31+
- name: 'firestore_user_creds_basic'
32+
primary_resource_id: 'my-user-creds'
33+
vars:
34+
database_id: 'database-id-mongodb-compatible'
35+
test_env_vars:
36+
project_id: 'PROJECT_NAME'
37+
- name: 'firestore_user_creds_with_secret_manager'
38+
primary_resource_id: 'my-user-creds'
39+
vars:
40+
database_id: 'database-id-mongodb-compatible'
41+
test_env_vars:
42+
project_id: 'PROJECT_NAME'
43+
parameters:
44+
- name: 'database'
45+
type: String
46+
description: |
47+
The Firestore database ID.
48+
required: true
49+
url_param_only: true
50+
- name: 'name'
51+
type: String
52+
description: |
53+
The ID to use for the user creds, which will become the final component
54+
of the user cred's resource name.
55+
56+
This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
57+
with first character a letter and the last a letter or a number. Must not
58+
be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
59+
required: true
60+
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.tmpl'
61+
custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.tmpl'
62+
properties:
63+
- name: 'createTime'
64+
type: String
65+
description: |
66+
The timestamp at which these user creds were created.
67+
output: true
68+
- name: 'updateTime'
69+
type: String
70+
description: |
71+
The timestamp at which these user creds were updated.
72+
output: true
73+
- name: 'state'
74+
type: String
75+
description: |
76+
The state of the user creds.
77+
output: true
78+
- name: 'securePassword'
79+
type: String
80+
description: |
81+
The plaintext server-generated password for the user creds.
82+
output: true
83+
sensitive: true
84+
# Only returned in the create call.
85+
ignore_read: true
86+
- name: 'resourceIdentity'
87+
type: NestedObject
88+
description: |
89+
Describes the Resource Identity principal.
90+
output: true
91+
properties:
92+
- name: 'principal'
93+
type: String
94+
description: |
95+
The principal identifier string.
96+
See https://cloud.google.com/iam/docs/principal-identifiers.
97+
output: true
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource "google_firestore_database" "database" {
2+
project = "{{index $.TestEnvVars "project_id"}}"
3+
name = "{{index $.Vars "database_id"}}"
4+
location_id = "nam5"
5+
type = "FIRESTORE_NATIVE"
6+
database_edition = "ENTERPRISE"
7+
8+
delete_protection_state = "DELETE_PROTECTION_DISABLED"
9+
deletion_policy = "DELETE"
10+
}
11+
12+
resource "google_firestore_user_creds" "{{$.PrimaryResourceId}}" {
13+
project = "{{index $.TestEnvVars "project_id"}}"
14+
database = google_firestore_database.database.name
15+
name = "my-username"
16+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
resource "google_firestore_database" "database" {
2+
project = "{{index $.TestEnvVars "project_id"}}"
3+
name = "{{index $.Vars "database_id"}}"
4+
location_id = "nam5"
5+
type = "FIRESTORE_NATIVE"
6+
database_edition = "ENTERPRISE"
7+
8+
delete_protection_state = "DELETE_PROTECTION_DISABLED"
9+
deletion_policy = "DELETE"
10+
}
11+
12+
resource "google_firestore_user_creds" "{{$.PrimaryResourceId}}" {
13+
project = "{{index $.TestEnvVars "project_id"}}"
14+
database = google_firestore_database.database.name
15+
name = "my-username"
16+
}
17+
18+
resource "google_secret_manager_secret" "my-fs-user-creds-secret" {
19+
project = "{{index $.TestEnvVars "project_id"}}"
20+
secret_id = "my-fs-user-creds-secret"
21+
22+
replication {
23+
auto {}
24+
}
25+
}
26+
27+
resource "google_secret_manager_secret_version" "my-fs-user-creds-secret-version" {
28+
secret = google_secret_manager_secret.my-fs-user-creds-secret.id
29+
secret_data = google_firestore_user_creds.{{$.PrimaryResourceId}}.secure_password
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
securePassword, ok := res["securePassword"]
2+
if (!ok) {
3+
return fmt.Errorf("Create response did not contain secure_password. Create may not have succeeded.")
4+
}
5+
if err := d.Set("secure_password", securePassword); err != nil {
6+
// securePassword is only returned in the create call.
7+
return fmt.Errorf("Error setting secure_password: %s", err)
8+
}

0 commit comments

Comments
 (0)