/
accountPrivilege.go
417 lines (367 loc) · 15.6 KB
/
accountPrivilege.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
// 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 rds
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Provides an RDS account privilege resource and used to grant several database some access privilege. A database can be granted by multiple account, see [What is DB Account Privilege](https://www.alibabacloud.com/help/en/apsaradb-for-rds/latest/api-rds-2014-08-15-grantaccountprivilege).
//
// > **NOTE:** At present, a database can only have one database owner.
//
// > **NOTE:** Available since v1.5.0.
//
// ## Example Usage
//
// ```go
// package main
//
// import (
//
// "fmt"
//
// "github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/rds"
// "github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/vpc"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// cfg := config.New(ctx, "")
// name := "tf_example"
// if param := cfg.Get("name"); param != "" {
// name = param
// }
// _default, err := rds.GetZones(ctx, &rds.GetZonesArgs{
// Engine: pulumi.StringRef("MySQL"),
// EngineVersion: pulumi.StringRef("5.6"),
// }, nil)
// if err != nil {
// return err
// }
// defaultNetwork, err := vpc.NewNetwork(ctx, "default", &vpc.NetworkArgs{
// VpcName: pulumi.String(name),
// CidrBlock: pulumi.String("172.16.0.0/16"),
// })
// if err != nil {
// return err
// }
// defaultSwitch, err := vpc.NewSwitch(ctx, "default", &vpc.SwitchArgs{
// VpcId: defaultNetwork.ID(),
// CidrBlock: pulumi.String("172.16.0.0/24"),
// ZoneId: pulumi.String(_default.Zones[0].Id),
// VswitchName: pulumi.String(name),
// })
// if err != nil {
// return err
// }
// instance, err := rds.NewInstance(ctx, "instance", &rds.InstanceArgs{
// Engine: pulumi.String("MySQL"),
// EngineVersion: pulumi.String("5.6"),
// InstanceType: pulumi.String("rds.mysql.s1.small"),
// InstanceStorage: pulumi.Int(10),
// VswitchId: defaultSwitch.ID(),
// InstanceName: pulumi.String(name),
// })
// if err != nil {
// return err
// }
// var db []*rds.Database
// for index := 0; index < 2; index++ {
// key0 := index
// val0 := index
// __res, err := rds.NewDatabase(ctx, fmt.Sprintf("db-%v", key0), &rds.DatabaseArgs{
// InstanceId: instance.ID(),
// Name: pulumi.String(fmt.Sprintf("%v_%v", name, val0)),
// Description: pulumi.String("from terraform"),
// })
// if err != nil {
// return err
// }
// db = append(db, __res)
// }
// account, err := rds.NewAccount(ctx, "account", &rds.AccountArgs{
// DbInstanceId: instance.ID(),
// AccountName: pulumi.String("tfexample"),
// AccountPassword: pulumi.String("Example12345"),
// AccountDescription: pulumi.String("from terraform"),
// })
// if err != nil {
// return err
// }
// var splat0 pulumi.StringArray
// for _, val0 := range db {
// splat0 = append(splat0, val0.Name)
// }
// _, err = rds.NewAccountPrivilege(ctx, "privilege", &rds.AccountPrivilegeArgs{
// InstanceId: instance.ID(),
// AccountName: account.Name,
// Privilege: pulumi.String("ReadOnly"),
// DbNames: splat0,
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
//
// ## Import
//
// RDS account privilege can be imported using the id, e.g.
//
// ```sh
// $ pulumi import alicloud:rds/accountPrivilege:AccountPrivilege example "rm-12345:tf_account:ReadOnly"
// ```
type AccountPrivilege struct {
pulumi.CustomResourceState
// A specified account name.
AccountName pulumi.StringOutput `pulumi:"accountName"`
// List of specified database name.
DbNames pulumi.StringArrayOutput `pulumi:"dbNames"`
// The Id of instance in which account belongs.
InstanceId pulumi.StringOutput `pulumi:"instanceId"`
// The privilege of one account access database. Valid values:
// - ReadOnly: This value is only for MySQL, MariaDB and SQL Server
// - ReadWrite: This value is only for MySQL, MariaDB and SQL Server
// - DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
// Default to "ReadOnly".
Privilege pulumi.StringPtrOutput `pulumi:"privilege"`
}
// NewAccountPrivilege registers a new resource with the given unique name, arguments, and options.
func NewAccountPrivilege(ctx *pulumi.Context,
name string, args *AccountPrivilegeArgs, opts ...pulumi.ResourceOption) (*AccountPrivilege, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.AccountName == nil {
return nil, errors.New("invalid value for required argument 'AccountName'")
}
if args.DbNames == nil {
return nil, errors.New("invalid value for required argument 'DbNames'")
}
if args.InstanceId == nil {
return nil, errors.New("invalid value for required argument 'InstanceId'")
}
opts = internal.PkgResourceDefaultOpts(opts)
var resource AccountPrivilege
err := ctx.RegisterResource("alicloud:rds/accountPrivilege:AccountPrivilege", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetAccountPrivilege gets an existing AccountPrivilege 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 GetAccountPrivilege(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *AccountPrivilegeState, opts ...pulumi.ResourceOption) (*AccountPrivilege, error) {
var resource AccountPrivilege
err := ctx.ReadResource("alicloud:rds/accountPrivilege:AccountPrivilege", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering AccountPrivilege resources.
type accountPrivilegeState struct {
// A specified account name.
AccountName *string `pulumi:"accountName"`
// List of specified database name.
DbNames []string `pulumi:"dbNames"`
// The Id of instance in which account belongs.
InstanceId *string `pulumi:"instanceId"`
// The privilege of one account access database. Valid values:
// - ReadOnly: This value is only for MySQL, MariaDB and SQL Server
// - ReadWrite: This value is only for MySQL, MariaDB and SQL Server
// - DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
// Default to "ReadOnly".
Privilege *string `pulumi:"privilege"`
}
type AccountPrivilegeState struct {
// A specified account name.
AccountName pulumi.StringPtrInput
// List of specified database name.
DbNames pulumi.StringArrayInput
// The Id of instance in which account belongs.
InstanceId pulumi.StringPtrInput
// The privilege of one account access database. Valid values:
// - ReadOnly: This value is only for MySQL, MariaDB and SQL Server
// - ReadWrite: This value is only for MySQL, MariaDB and SQL Server
// - DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
// Default to "ReadOnly".
Privilege pulumi.StringPtrInput
}
func (AccountPrivilegeState) ElementType() reflect.Type {
return reflect.TypeOf((*accountPrivilegeState)(nil)).Elem()
}
type accountPrivilegeArgs struct {
// A specified account name.
AccountName string `pulumi:"accountName"`
// List of specified database name.
DbNames []string `pulumi:"dbNames"`
// The Id of instance in which account belongs.
InstanceId string `pulumi:"instanceId"`
// The privilege of one account access database. Valid values:
// - ReadOnly: This value is only for MySQL, MariaDB and SQL Server
// - ReadWrite: This value is only for MySQL, MariaDB and SQL Server
// - DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
// Default to "ReadOnly".
Privilege *string `pulumi:"privilege"`
}
// The set of arguments for constructing a AccountPrivilege resource.
type AccountPrivilegeArgs struct {
// A specified account name.
AccountName pulumi.StringInput
// List of specified database name.
DbNames pulumi.StringArrayInput
// The Id of instance in which account belongs.
InstanceId pulumi.StringInput
// The privilege of one account access database. Valid values:
// - ReadOnly: This value is only for MySQL, MariaDB and SQL Server
// - ReadWrite: This value is only for MySQL, MariaDB and SQL Server
// - DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
// Default to "ReadOnly".
Privilege pulumi.StringPtrInput
}
func (AccountPrivilegeArgs) ElementType() reflect.Type {
return reflect.TypeOf((*accountPrivilegeArgs)(nil)).Elem()
}
type AccountPrivilegeInput interface {
pulumi.Input
ToAccountPrivilegeOutput() AccountPrivilegeOutput
ToAccountPrivilegeOutputWithContext(ctx context.Context) AccountPrivilegeOutput
}
func (*AccountPrivilege) ElementType() reflect.Type {
return reflect.TypeOf((**AccountPrivilege)(nil)).Elem()
}
func (i *AccountPrivilege) ToAccountPrivilegeOutput() AccountPrivilegeOutput {
return i.ToAccountPrivilegeOutputWithContext(context.Background())
}
func (i *AccountPrivilege) ToAccountPrivilegeOutputWithContext(ctx context.Context) AccountPrivilegeOutput {
return pulumi.ToOutputWithContext(ctx, i).(AccountPrivilegeOutput)
}
// AccountPrivilegeArrayInput is an input type that accepts AccountPrivilegeArray and AccountPrivilegeArrayOutput values.
// You can construct a concrete instance of `AccountPrivilegeArrayInput` via:
//
// AccountPrivilegeArray{ AccountPrivilegeArgs{...} }
type AccountPrivilegeArrayInput interface {
pulumi.Input
ToAccountPrivilegeArrayOutput() AccountPrivilegeArrayOutput
ToAccountPrivilegeArrayOutputWithContext(context.Context) AccountPrivilegeArrayOutput
}
type AccountPrivilegeArray []AccountPrivilegeInput
func (AccountPrivilegeArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*AccountPrivilege)(nil)).Elem()
}
func (i AccountPrivilegeArray) ToAccountPrivilegeArrayOutput() AccountPrivilegeArrayOutput {
return i.ToAccountPrivilegeArrayOutputWithContext(context.Background())
}
func (i AccountPrivilegeArray) ToAccountPrivilegeArrayOutputWithContext(ctx context.Context) AccountPrivilegeArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(AccountPrivilegeArrayOutput)
}
// AccountPrivilegeMapInput is an input type that accepts AccountPrivilegeMap and AccountPrivilegeMapOutput values.
// You can construct a concrete instance of `AccountPrivilegeMapInput` via:
//
// AccountPrivilegeMap{ "key": AccountPrivilegeArgs{...} }
type AccountPrivilegeMapInput interface {
pulumi.Input
ToAccountPrivilegeMapOutput() AccountPrivilegeMapOutput
ToAccountPrivilegeMapOutputWithContext(context.Context) AccountPrivilegeMapOutput
}
type AccountPrivilegeMap map[string]AccountPrivilegeInput
func (AccountPrivilegeMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*AccountPrivilege)(nil)).Elem()
}
func (i AccountPrivilegeMap) ToAccountPrivilegeMapOutput() AccountPrivilegeMapOutput {
return i.ToAccountPrivilegeMapOutputWithContext(context.Background())
}
func (i AccountPrivilegeMap) ToAccountPrivilegeMapOutputWithContext(ctx context.Context) AccountPrivilegeMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(AccountPrivilegeMapOutput)
}
type AccountPrivilegeOutput struct{ *pulumi.OutputState }
func (AccountPrivilegeOutput) ElementType() reflect.Type {
return reflect.TypeOf((**AccountPrivilege)(nil)).Elem()
}
func (o AccountPrivilegeOutput) ToAccountPrivilegeOutput() AccountPrivilegeOutput {
return o
}
func (o AccountPrivilegeOutput) ToAccountPrivilegeOutputWithContext(ctx context.Context) AccountPrivilegeOutput {
return o
}
// A specified account name.
func (o AccountPrivilegeOutput) AccountName() pulumi.StringOutput {
return o.ApplyT(func(v *AccountPrivilege) pulumi.StringOutput { return v.AccountName }).(pulumi.StringOutput)
}
// List of specified database name.
func (o AccountPrivilegeOutput) DbNames() pulumi.StringArrayOutput {
return o.ApplyT(func(v *AccountPrivilege) pulumi.StringArrayOutput { return v.DbNames }).(pulumi.StringArrayOutput)
}
// The Id of instance in which account belongs.
func (o AccountPrivilegeOutput) InstanceId() pulumi.StringOutput {
return o.ApplyT(func(v *AccountPrivilege) pulumi.StringOutput { return v.InstanceId }).(pulumi.StringOutput)
}
// The privilege of one account access database. Valid values:
// - ReadOnly: This value is only for MySQL, MariaDB and SQL Server
// - ReadWrite: This value is only for MySQL, MariaDB and SQL Server
// - DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
// - DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
// Default to "ReadOnly".
func (o AccountPrivilegeOutput) Privilege() pulumi.StringPtrOutput {
return o.ApplyT(func(v *AccountPrivilege) pulumi.StringPtrOutput { return v.Privilege }).(pulumi.StringPtrOutput)
}
type AccountPrivilegeArrayOutput struct{ *pulumi.OutputState }
func (AccountPrivilegeArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*AccountPrivilege)(nil)).Elem()
}
func (o AccountPrivilegeArrayOutput) ToAccountPrivilegeArrayOutput() AccountPrivilegeArrayOutput {
return o
}
func (o AccountPrivilegeArrayOutput) ToAccountPrivilegeArrayOutputWithContext(ctx context.Context) AccountPrivilegeArrayOutput {
return o
}
func (o AccountPrivilegeArrayOutput) Index(i pulumi.IntInput) AccountPrivilegeOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *AccountPrivilege {
return vs[0].([]*AccountPrivilege)[vs[1].(int)]
}).(AccountPrivilegeOutput)
}
type AccountPrivilegeMapOutput struct{ *pulumi.OutputState }
func (AccountPrivilegeMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*AccountPrivilege)(nil)).Elem()
}
func (o AccountPrivilegeMapOutput) ToAccountPrivilegeMapOutput() AccountPrivilegeMapOutput {
return o
}
func (o AccountPrivilegeMapOutput) ToAccountPrivilegeMapOutputWithContext(ctx context.Context) AccountPrivilegeMapOutput {
return o
}
func (o AccountPrivilegeMapOutput) MapIndex(k pulumi.StringInput) AccountPrivilegeOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *AccountPrivilege {
return vs[0].(map[string]*AccountPrivilege)[vs[1].(string)]
}).(AccountPrivilegeOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*AccountPrivilegeInput)(nil)).Elem(), &AccountPrivilege{})
pulumi.RegisterInputType(reflect.TypeOf((*AccountPrivilegeArrayInput)(nil)).Elem(), AccountPrivilegeArray{})
pulumi.RegisterInputType(reflect.TypeOf((*AccountPrivilegeMapInput)(nil)).Elem(), AccountPrivilegeMap{})
pulumi.RegisterOutputType(AccountPrivilegeOutput{})
pulumi.RegisterOutputType(AccountPrivilegeArrayOutput{})
pulumi.RegisterOutputType(AccountPrivilegeMapOutput{})
}