/
document.go
496 lines (435 loc) · 17.7 KB
/
document.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
// Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
package firestore
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
)
// In Cloud Firestore, the unit of storage is the document. A document is a lightweight record
// that contains fields, which map to values. Each document is identified by a name.
//
// To get more information about Document, see:
//
// * [API documentation](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents)
// * How-to Guides
// - [Official Documentation](https://cloud.google.com/firestore/docs/manage-data/add-data)
//
// > **Warning:** This resource creates a Firestore Document on a project that already has
// a Firestore database. If you haven't already created it, you may
// create a `firestore.Database` resource with `type` set to
// `"FIRESTORE_NATIVE"` and `locationId` set to your chosen location.
// If you wish to use App Engine, you may instead create a
// `appengine.Application` resource with `databaseType` set to
// `"CLOUD_FIRESTORE"`. Your Firestore location will be the same as
// the App Engine location specified.
//
// ## Example Usage
// ### Firestore Document Basic
//
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/firestore"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// _, err := firestore.NewDocument(ctx, "mydoc", &firestore.DocumentArgs{
// Collection: pulumi.String("somenewcollection"),
// DocumentId: pulumi.String("my-doc-id"),
// Fields: pulumi.String("{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}"),
// Project: pulumi.String("my-project-name"),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
// ### Firestore Document Nested Document
//
// ```go
// package main
//
// import (
//
// "fmt"
//
// "github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/firestore"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// mydoc, err := firestore.NewDocument(ctx, "mydoc", &firestore.DocumentArgs{
// Collection: pulumi.String("somenewcollection"),
// DocumentId: pulumi.String("my-doc-id"),
// Fields: pulumi.String("{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}"),
// Project: pulumi.String("my-project-name"),
// })
// if err != nil {
// return err
// }
// subDocument, err := firestore.NewDocument(ctx, "subDocument", &firestore.DocumentArgs{
// Collection: mydoc.Path.ApplyT(func(path string) (string, error) {
// return fmt.Sprintf("%v/subdocs", path), nil
// }).(pulumi.StringOutput),
// DocumentId: pulumi.String("bitcoinkey"),
// Fields: pulumi.String("{\"something\":{\"mapValue\":{\"fields\":{\"ayo\":{\"stringValue\":\"val2\"}}}}}"),
// Project: pulumi.String("my-project-name"),
// })
// if err != nil {
// return err
// }
// _, err = firestore.NewDocument(ctx, "subSubDocument", &firestore.DocumentArgs{
// Collection: subDocument.Path.ApplyT(func(path string) (string, error) {
// return fmt.Sprintf("%v/subsubdocs", path), nil
// }).(pulumi.StringOutput),
// DocumentId: pulumi.String("asecret"),
// Fields: pulumi.String("{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}}}"),
// Project: pulumi.String("my-project-name"),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
//
// ## Import
//
// Document can be imported using any of these accepted formats:
//
// ```sh
//
// $ pulumi import gcp:firestore/document:Document default {{name}}
//
// ```
type Document struct {
pulumi.CustomResourceState
// The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.
Collection pulumi.StringOutput `pulumi:"collection"`
// Creation timestamp in RFC3339 format.
CreateTime pulumi.StringOutput `pulumi:"createTime"`
// The Firestore database id. Defaults to `"(default)"`.
Database pulumi.StringPtrOutput `pulumi:"database"`
// The client-assigned document ID to use for this document during creation.
//
// ***
DocumentId pulumi.StringOutput `pulumi:"documentId"`
// The document's [fields](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents) formated as a json string.
Fields pulumi.StringOutput `pulumi:"fields"`
// A server defined name for this index. Format:
// `projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}`
Name pulumi.StringOutput `pulumi:"name"`
// A relative path to the collection this document exists within
Path pulumi.StringOutput `pulumi:"path"`
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project pulumi.StringOutput `pulumi:"project"`
// Last update timestamp in RFC3339 format.
UpdateTime pulumi.StringOutput `pulumi:"updateTime"`
}
// NewDocument registers a new resource with the given unique name, arguments, and options.
func NewDocument(ctx *pulumi.Context,
name string, args *DocumentArgs, opts ...pulumi.ResourceOption) (*Document, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.Collection == nil {
return nil, errors.New("invalid value for required argument 'Collection'")
}
if args.DocumentId == nil {
return nil, errors.New("invalid value for required argument 'DocumentId'")
}
if args.Fields == nil {
return nil, errors.New("invalid value for required argument 'Fields'")
}
opts = internal.PkgResourceDefaultOpts(opts)
var resource Document
err := ctx.RegisterResource("gcp:firestore/document:Document", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetDocument gets an existing Document resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetDocument(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *DocumentState, opts ...pulumi.ResourceOption) (*Document, error) {
var resource Document
err := ctx.ReadResource("gcp:firestore/document:Document", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Document resources.
type documentState struct {
// The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.
Collection *string `pulumi:"collection"`
// Creation timestamp in RFC3339 format.
CreateTime *string `pulumi:"createTime"`
// The Firestore database id. Defaults to `"(default)"`.
Database *string `pulumi:"database"`
// The client-assigned document ID to use for this document during creation.
//
// ***
DocumentId *string `pulumi:"documentId"`
// The document's [fields](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents) formated as a json string.
Fields *string `pulumi:"fields"`
// A server defined name for this index. Format:
// `projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}`
Name *string `pulumi:"name"`
// A relative path to the collection this document exists within
Path *string `pulumi:"path"`
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project *string `pulumi:"project"`
// Last update timestamp in RFC3339 format.
UpdateTime *string `pulumi:"updateTime"`
}
type DocumentState struct {
// The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.
Collection pulumi.StringPtrInput
// Creation timestamp in RFC3339 format.
CreateTime pulumi.StringPtrInput
// The Firestore database id. Defaults to `"(default)"`.
Database pulumi.StringPtrInput
// The client-assigned document ID to use for this document during creation.
//
// ***
DocumentId pulumi.StringPtrInput
// The document's [fields](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents) formated as a json string.
Fields pulumi.StringPtrInput
// A server defined name for this index. Format:
// `projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}`
Name pulumi.StringPtrInput
// A relative path to the collection this document exists within
Path pulumi.StringPtrInput
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project pulumi.StringPtrInput
// Last update timestamp in RFC3339 format.
UpdateTime pulumi.StringPtrInput
}
func (DocumentState) ElementType() reflect.Type {
return reflect.TypeOf((*documentState)(nil)).Elem()
}
type documentArgs struct {
// The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.
Collection string `pulumi:"collection"`
// The Firestore database id. Defaults to `"(default)"`.
Database *string `pulumi:"database"`
// The client-assigned document ID to use for this document during creation.
//
// ***
DocumentId string `pulumi:"documentId"`
// The document's [fields](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents) formated as a json string.
Fields string `pulumi:"fields"`
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project *string `pulumi:"project"`
}
// The set of arguments for constructing a Document resource.
type DocumentArgs struct {
// The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.
Collection pulumi.StringInput
// The Firestore database id. Defaults to `"(default)"`.
Database pulumi.StringPtrInput
// The client-assigned document ID to use for this document during creation.
//
// ***
DocumentId pulumi.StringInput
// The document's [fields](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents) formated as a json string.
Fields pulumi.StringInput
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project pulumi.StringPtrInput
}
func (DocumentArgs) ElementType() reflect.Type {
return reflect.TypeOf((*documentArgs)(nil)).Elem()
}
type DocumentInput interface {
pulumi.Input
ToDocumentOutput() DocumentOutput
ToDocumentOutputWithContext(ctx context.Context) DocumentOutput
}
func (*Document) ElementType() reflect.Type {
return reflect.TypeOf((**Document)(nil)).Elem()
}
func (i *Document) ToDocumentOutput() DocumentOutput {
return i.ToDocumentOutputWithContext(context.Background())
}
func (i *Document) ToDocumentOutputWithContext(ctx context.Context) DocumentOutput {
return pulumi.ToOutputWithContext(ctx, i).(DocumentOutput)
}
func (i *Document) ToOutput(ctx context.Context) pulumix.Output[*Document] {
return pulumix.Output[*Document]{
OutputState: i.ToDocumentOutputWithContext(ctx).OutputState,
}
}
// DocumentArrayInput is an input type that accepts DocumentArray and DocumentArrayOutput values.
// You can construct a concrete instance of `DocumentArrayInput` via:
//
// DocumentArray{ DocumentArgs{...} }
type DocumentArrayInput interface {
pulumi.Input
ToDocumentArrayOutput() DocumentArrayOutput
ToDocumentArrayOutputWithContext(context.Context) DocumentArrayOutput
}
type DocumentArray []DocumentInput
func (DocumentArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Document)(nil)).Elem()
}
func (i DocumentArray) ToDocumentArrayOutput() DocumentArrayOutput {
return i.ToDocumentArrayOutputWithContext(context.Background())
}
func (i DocumentArray) ToDocumentArrayOutputWithContext(ctx context.Context) DocumentArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(DocumentArrayOutput)
}
func (i DocumentArray) ToOutput(ctx context.Context) pulumix.Output[[]*Document] {
return pulumix.Output[[]*Document]{
OutputState: i.ToDocumentArrayOutputWithContext(ctx).OutputState,
}
}
// DocumentMapInput is an input type that accepts DocumentMap and DocumentMapOutput values.
// You can construct a concrete instance of `DocumentMapInput` via:
//
// DocumentMap{ "key": DocumentArgs{...} }
type DocumentMapInput interface {
pulumi.Input
ToDocumentMapOutput() DocumentMapOutput
ToDocumentMapOutputWithContext(context.Context) DocumentMapOutput
}
type DocumentMap map[string]DocumentInput
func (DocumentMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Document)(nil)).Elem()
}
func (i DocumentMap) ToDocumentMapOutput() DocumentMapOutput {
return i.ToDocumentMapOutputWithContext(context.Background())
}
func (i DocumentMap) ToDocumentMapOutputWithContext(ctx context.Context) DocumentMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(DocumentMapOutput)
}
func (i DocumentMap) ToOutput(ctx context.Context) pulumix.Output[map[string]*Document] {
return pulumix.Output[map[string]*Document]{
OutputState: i.ToDocumentMapOutputWithContext(ctx).OutputState,
}
}
type DocumentOutput struct{ *pulumi.OutputState }
func (DocumentOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Document)(nil)).Elem()
}
func (o DocumentOutput) ToDocumentOutput() DocumentOutput {
return o
}
func (o DocumentOutput) ToDocumentOutputWithContext(ctx context.Context) DocumentOutput {
return o
}
func (o DocumentOutput) ToOutput(ctx context.Context) pulumix.Output[*Document] {
return pulumix.Output[*Document]{
OutputState: o.OutputState,
}
}
// The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.
func (o DocumentOutput) Collection() pulumi.StringOutput {
return o.ApplyT(func(v *Document) pulumi.StringOutput { return v.Collection }).(pulumi.StringOutput)
}
// Creation timestamp in RFC3339 format.
func (o DocumentOutput) CreateTime() pulumi.StringOutput {
return o.ApplyT(func(v *Document) pulumi.StringOutput { return v.CreateTime }).(pulumi.StringOutput)
}
// The Firestore database id. Defaults to `"(default)"`.
func (o DocumentOutput) Database() pulumi.StringPtrOutput {
return o.ApplyT(func(v *Document) pulumi.StringPtrOutput { return v.Database }).(pulumi.StringPtrOutput)
}
// The client-assigned document ID to use for this document during creation.
//
// ***
func (o DocumentOutput) DocumentId() pulumi.StringOutput {
return o.ApplyT(func(v *Document) pulumi.StringOutput { return v.DocumentId }).(pulumi.StringOutput)
}
// The document's [fields](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents) formated as a json string.
func (o DocumentOutput) Fields() pulumi.StringOutput {
return o.ApplyT(func(v *Document) pulumi.StringOutput { return v.Fields }).(pulumi.StringOutput)
}
// A server defined name for this index. Format:
// `projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}`
func (o DocumentOutput) Name() pulumi.StringOutput {
return o.ApplyT(func(v *Document) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
}
// A relative path to the collection this document exists within
func (o DocumentOutput) Path() pulumi.StringOutput {
return o.ApplyT(func(v *Document) pulumi.StringOutput { return v.Path }).(pulumi.StringOutput)
}
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
func (o DocumentOutput) Project() pulumi.StringOutput {
return o.ApplyT(func(v *Document) pulumi.StringOutput { return v.Project }).(pulumi.StringOutput)
}
// Last update timestamp in RFC3339 format.
func (o DocumentOutput) UpdateTime() pulumi.StringOutput {
return o.ApplyT(func(v *Document) pulumi.StringOutput { return v.UpdateTime }).(pulumi.StringOutput)
}
type DocumentArrayOutput struct{ *pulumi.OutputState }
func (DocumentArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Document)(nil)).Elem()
}
func (o DocumentArrayOutput) ToDocumentArrayOutput() DocumentArrayOutput {
return o
}
func (o DocumentArrayOutput) ToDocumentArrayOutputWithContext(ctx context.Context) DocumentArrayOutput {
return o
}
func (o DocumentArrayOutput) ToOutput(ctx context.Context) pulumix.Output[[]*Document] {
return pulumix.Output[[]*Document]{
OutputState: o.OutputState,
}
}
func (o DocumentArrayOutput) Index(i pulumi.IntInput) DocumentOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Document {
return vs[0].([]*Document)[vs[1].(int)]
}).(DocumentOutput)
}
type DocumentMapOutput struct{ *pulumi.OutputState }
func (DocumentMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Document)(nil)).Elem()
}
func (o DocumentMapOutput) ToDocumentMapOutput() DocumentMapOutput {
return o
}
func (o DocumentMapOutput) ToDocumentMapOutputWithContext(ctx context.Context) DocumentMapOutput {
return o
}
func (o DocumentMapOutput) ToOutput(ctx context.Context) pulumix.Output[map[string]*Document] {
return pulumix.Output[map[string]*Document]{
OutputState: o.OutputState,
}
}
func (o DocumentMapOutput) MapIndex(k pulumi.StringInput) DocumentOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Document {
return vs[0].(map[string]*Document)[vs[1].(string)]
}).(DocumentOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*DocumentInput)(nil)).Elem(), &Document{})
pulumi.RegisterInputType(reflect.TypeOf((*DocumentArrayInput)(nil)).Elem(), DocumentArray{})
pulumi.RegisterInputType(reflect.TypeOf((*DocumentMapInput)(nil)).Elem(), DocumentMap{})
pulumi.RegisterOutputType(DocumentOutput{})
pulumi.RegisterOutputType(DocumentArrayOutput{})
pulumi.RegisterOutputType(DocumentMapOutput{})
}