/
globalTable.go
338 lines (289 loc) · 11.5 KB
/
globalTable.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
// 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 dynamodb
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Manages [DynamoDB Global Tables V1 (version 2017.11.29)](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/globaltables.V1.html). These are layered on top of existing DynamoDB Tables.
//
// > **NOTE:** To instead manage [DynamoDB Global Tables V2 (version 2019.11.21)](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/globaltables.V2.html), use the `dynamodb.Table` resource `replica` configuration block.
//
// > Note: There are many restrictions before you can properly create DynamoDB Global Tables in multiple regions. See the [AWS DynamoDB Global Table Requirements](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/globaltables_reqs_bestpractices.html) for more information.
//
// ## Example Usage
//
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-aws/sdk/v5/go/aws"
// "github.com/pulumi/pulumi-aws/sdk/v5/go/aws/dynamodb"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// _, err := aws.NewProvider(ctx, "us-east-1", &aws.ProviderArgs{
// Region: pulumi.String("us-east-1"),
// })
// if err != nil {
// return err
// }
// _, err = aws.NewProvider(ctx, "us-west-2", &aws.ProviderArgs{
// Region: pulumi.String("us-west-2"),
// })
// if err != nil {
// return err
// }
// _, err = dynamodb.NewTable(ctx, "us-east-1Table", &dynamodb.TableArgs{
// HashKey: pulumi.String("myAttribute"),
// StreamEnabled: pulumi.Bool(true),
// StreamViewType: pulumi.String("NEW_AND_OLD_IMAGES"),
// ReadCapacity: pulumi.Int(1),
// WriteCapacity: pulumi.Int(1),
// Attributes: dynamodb.TableAttributeArray{
// &dynamodb.TableAttributeArgs{
// Name: pulumi.String("myAttribute"),
// Type: pulumi.String("S"),
// },
// },
// }, pulumi.Provider(aws.UsEast1))
// if err != nil {
// return err
// }
// _, err = dynamodb.NewTable(ctx, "us-west-2Table", &dynamodb.TableArgs{
// HashKey: pulumi.String("myAttribute"),
// StreamEnabled: pulumi.Bool(true),
// StreamViewType: pulumi.String("NEW_AND_OLD_IMAGES"),
// ReadCapacity: pulumi.Int(1),
// WriteCapacity: pulumi.Int(1),
// Attributes: dynamodb.TableAttributeArray{
// &dynamodb.TableAttributeArgs{
// Name: pulumi.String("myAttribute"),
// Type: pulumi.String("S"),
// },
// },
// }, pulumi.Provider(aws.UsWest2))
// if err != nil {
// return err
// }
// _, err = dynamodb.NewGlobalTable(ctx, "myTable", &dynamodb.GlobalTableArgs{
// Replicas: dynamodb.GlobalTableReplicaArray{
// &dynamodb.GlobalTableReplicaArgs{
// RegionName: pulumi.String("us-east-1"),
// },
// &dynamodb.GlobalTableReplicaArgs{
// RegionName: pulumi.String("us-west-2"),
// },
// },
// }, pulumi.Provider(aws.UsEast1), pulumi.DependsOn([]pulumi.Resource{
// us_east_1Table,
// us_west_2Table,
// }))
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
//
// ## Import
//
// DynamoDB Global Tables can be imported using the global table name, e.g.,
//
// ```sh
//
// $ pulumi import aws:dynamodb/globalTable:GlobalTable MyTable MyTable
//
// ```
type GlobalTable struct {
pulumi.CustomResourceState
// The ARN of the DynamoDB Global Table
Arn pulumi.StringOutput `pulumi:"arn"`
// The name of the global table. Must match underlying DynamoDB Table names in all regions.
Name pulumi.StringOutput `pulumi:"name"`
// Underlying DynamoDB Table. At least 1 replica must be defined. See below.
Replicas GlobalTableReplicaArrayOutput `pulumi:"replicas"`
}
// NewGlobalTable registers a new resource with the given unique name, arguments, and options.
func NewGlobalTable(ctx *pulumi.Context,
name string, args *GlobalTableArgs, opts ...pulumi.ResourceOption) (*GlobalTable, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.Replicas == nil {
return nil, errors.New("invalid value for required argument 'Replicas'")
}
var resource GlobalTable
err := ctx.RegisterResource("aws:dynamodb/globalTable:GlobalTable", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetGlobalTable gets an existing GlobalTable 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 GetGlobalTable(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *GlobalTableState, opts ...pulumi.ResourceOption) (*GlobalTable, error) {
var resource GlobalTable
err := ctx.ReadResource("aws:dynamodb/globalTable:GlobalTable", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering GlobalTable resources.
type globalTableState struct {
// The ARN of the DynamoDB Global Table
Arn *string `pulumi:"arn"`
// The name of the global table. Must match underlying DynamoDB Table names in all regions.
Name *string `pulumi:"name"`
// Underlying DynamoDB Table. At least 1 replica must be defined. See below.
Replicas []GlobalTableReplica `pulumi:"replicas"`
}
type GlobalTableState struct {
// The ARN of the DynamoDB Global Table
Arn pulumi.StringPtrInput
// The name of the global table. Must match underlying DynamoDB Table names in all regions.
Name pulumi.StringPtrInput
// Underlying DynamoDB Table. At least 1 replica must be defined. See below.
Replicas GlobalTableReplicaArrayInput
}
func (GlobalTableState) ElementType() reflect.Type {
return reflect.TypeOf((*globalTableState)(nil)).Elem()
}
type globalTableArgs struct {
// The name of the global table. Must match underlying DynamoDB Table names in all regions.
Name *string `pulumi:"name"`
// Underlying DynamoDB Table. At least 1 replica must be defined. See below.
Replicas []GlobalTableReplica `pulumi:"replicas"`
}
// The set of arguments for constructing a GlobalTable resource.
type GlobalTableArgs struct {
// The name of the global table. Must match underlying DynamoDB Table names in all regions.
Name pulumi.StringPtrInput
// Underlying DynamoDB Table. At least 1 replica must be defined. See below.
Replicas GlobalTableReplicaArrayInput
}
func (GlobalTableArgs) ElementType() reflect.Type {
return reflect.TypeOf((*globalTableArgs)(nil)).Elem()
}
type GlobalTableInput interface {
pulumi.Input
ToGlobalTableOutput() GlobalTableOutput
ToGlobalTableOutputWithContext(ctx context.Context) GlobalTableOutput
}
func (*GlobalTable) ElementType() reflect.Type {
return reflect.TypeOf((**GlobalTable)(nil)).Elem()
}
func (i *GlobalTable) ToGlobalTableOutput() GlobalTableOutput {
return i.ToGlobalTableOutputWithContext(context.Background())
}
func (i *GlobalTable) ToGlobalTableOutputWithContext(ctx context.Context) GlobalTableOutput {
return pulumi.ToOutputWithContext(ctx, i).(GlobalTableOutput)
}
// GlobalTableArrayInput is an input type that accepts GlobalTableArray and GlobalTableArrayOutput values.
// You can construct a concrete instance of `GlobalTableArrayInput` via:
//
// GlobalTableArray{ GlobalTableArgs{...} }
type GlobalTableArrayInput interface {
pulumi.Input
ToGlobalTableArrayOutput() GlobalTableArrayOutput
ToGlobalTableArrayOutputWithContext(context.Context) GlobalTableArrayOutput
}
type GlobalTableArray []GlobalTableInput
func (GlobalTableArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*GlobalTable)(nil)).Elem()
}
func (i GlobalTableArray) ToGlobalTableArrayOutput() GlobalTableArrayOutput {
return i.ToGlobalTableArrayOutputWithContext(context.Background())
}
func (i GlobalTableArray) ToGlobalTableArrayOutputWithContext(ctx context.Context) GlobalTableArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(GlobalTableArrayOutput)
}
// GlobalTableMapInput is an input type that accepts GlobalTableMap and GlobalTableMapOutput values.
// You can construct a concrete instance of `GlobalTableMapInput` via:
//
// GlobalTableMap{ "key": GlobalTableArgs{...} }
type GlobalTableMapInput interface {
pulumi.Input
ToGlobalTableMapOutput() GlobalTableMapOutput
ToGlobalTableMapOutputWithContext(context.Context) GlobalTableMapOutput
}
type GlobalTableMap map[string]GlobalTableInput
func (GlobalTableMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*GlobalTable)(nil)).Elem()
}
func (i GlobalTableMap) ToGlobalTableMapOutput() GlobalTableMapOutput {
return i.ToGlobalTableMapOutputWithContext(context.Background())
}
func (i GlobalTableMap) ToGlobalTableMapOutputWithContext(ctx context.Context) GlobalTableMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(GlobalTableMapOutput)
}
type GlobalTableOutput struct{ *pulumi.OutputState }
func (GlobalTableOutput) ElementType() reflect.Type {
return reflect.TypeOf((**GlobalTable)(nil)).Elem()
}
func (o GlobalTableOutput) ToGlobalTableOutput() GlobalTableOutput {
return o
}
func (o GlobalTableOutput) ToGlobalTableOutputWithContext(ctx context.Context) GlobalTableOutput {
return o
}
// The ARN of the DynamoDB Global Table
func (o GlobalTableOutput) Arn() pulumi.StringOutput {
return o.ApplyT(func(v *GlobalTable) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput)
}
// The name of the global table. Must match underlying DynamoDB Table names in all regions.
func (o GlobalTableOutput) Name() pulumi.StringOutput {
return o.ApplyT(func(v *GlobalTable) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
}
// Underlying DynamoDB Table. At least 1 replica must be defined. See below.
func (o GlobalTableOutput) Replicas() GlobalTableReplicaArrayOutput {
return o.ApplyT(func(v *GlobalTable) GlobalTableReplicaArrayOutput { return v.Replicas }).(GlobalTableReplicaArrayOutput)
}
type GlobalTableArrayOutput struct{ *pulumi.OutputState }
func (GlobalTableArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*GlobalTable)(nil)).Elem()
}
func (o GlobalTableArrayOutput) ToGlobalTableArrayOutput() GlobalTableArrayOutput {
return o
}
func (o GlobalTableArrayOutput) ToGlobalTableArrayOutputWithContext(ctx context.Context) GlobalTableArrayOutput {
return o
}
func (o GlobalTableArrayOutput) Index(i pulumi.IntInput) GlobalTableOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *GlobalTable {
return vs[0].([]*GlobalTable)[vs[1].(int)]
}).(GlobalTableOutput)
}
type GlobalTableMapOutput struct{ *pulumi.OutputState }
func (GlobalTableMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*GlobalTable)(nil)).Elem()
}
func (o GlobalTableMapOutput) ToGlobalTableMapOutput() GlobalTableMapOutput {
return o
}
func (o GlobalTableMapOutput) ToGlobalTableMapOutputWithContext(ctx context.Context) GlobalTableMapOutput {
return o
}
func (o GlobalTableMapOutput) MapIndex(k pulumi.StringInput) GlobalTableOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *GlobalTable {
return vs[0].(map[string]*GlobalTable)[vs[1].(string)]
}).(GlobalTableOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*GlobalTableInput)(nil)).Elem(), &GlobalTable{})
pulumi.RegisterInputType(reflect.TypeOf((*GlobalTableArrayInput)(nil)).Elem(), GlobalTableArray{})
pulumi.RegisterInputType(reflect.TypeOf((*GlobalTableMapInput)(nil)).Elem(), GlobalTableMap{})
pulumi.RegisterOutputType(GlobalTableOutput{})
pulumi.RegisterOutputType(GlobalTableArrayOutput{})
pulumi.RegisterOutputType(GlobalTableMapOutput{})
}