/
failoverGroup.go
460 lines (404 loc) · 20.2 KB
/
failoverGroup.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
// 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 sql
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Create a failover group of databases on a collection of Azure SQL servers.
//
// > **Note:** The `sql.FailoverGroup` resource is deprecated in version 3.0 of the AzureRM provider and will be removed in version 4.0. Please use the `mssql.FailoverGroup` resource instead.
//
// ## Example Usage
//
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core"
// "github.com/pulumi/pulumi-azure/sdk/v5/go/azure/sql"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// example, err := core.NewResourceGroup(ctx, "example", &core.ResourceGroupArgs{
// Name: pulumi.String("example-resources"),
// Location: pulumi.String("West Europe"),
// })
// if err != nil {
// return err
// }
// primary, err := sql.NewSqlServer(ctx, "primary", &sql.SqlServerArgs{
// Name: pulumi.String("sql-primary"),
// ResourceGroupName: example.Name,
// Location: example.Location,
// Version: pulumi.String("12.0"),
// AdministratorLogin: pulumi.String("sqladmin"),
// AdministratorLoginPassword: pulumi.String("pa$$w0rd"),
// })
// if err != nil {
// return err
// }
// secondary, err := sql.NewSqlServer(ctx, "secondary", &sql.SqlServerArgs{
// Name: pulumi.String("sql-secondary"),
// ResourceGroupName: example.Name,
// Location: example.Location,
// Version: pulumi.String("12.0"),
// AdministratorLogin: pulumi.String("sqladmin"),
// AdministratorLoginPassword: pulumi.String("pa$$w0rd"),
// })
// if err != nil {
// return err
// }
// db1, err := sql.NewDatabase(ctx, "db1", &sql.DatabaseArgs{
// Name: pulumi.String("db1"),
// ResourceGroupName: primary.ResourceGroupName,
// Location: primary.Location,
// ServerName: primary.Name,
// })
// if err != nil {
// return err
// }
// _, err = sql.NewFailoverGroup(ctx, "example", &sql.FailoverGroupArgs{
// Name: pulumi.String("example-failover-group"),
// ResourceGroupName: primary.ResourceGroupName,
// ServerName: primary.Name,
// Databases: pulumi.StringArray{
// db1.ID(),
// },
// PartnerServers: sql.FailoverGroupPartnerServerArray{
// &sql.FailoverGroupPartnerServerArgs{
// Id: secondary.ID(),
// },
// },
// ReadWriteEndpointFailoverPolicy: &sql.FailoverGroupReadWriteEndpointFailoverPolicyArgs{
// Mode: pulumi.String("Automatic"),
// GraceMinutes: pulumi.Int(60),
// },
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
//
// ## Import
//
// SQL Failover Groups can be imported using the `resource id`, e.g.
//
// ```sh
// $ pulumi import azure:sql/failoverGroup:FailoverGroup example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.Sql/servers/myserver/failoverGroups/group1
// ```
type FailoverGroup struct {
pulumi.CustomResourceState
// A list of database ids to add to the failover group
//
// > **NOTE:** The failover group will create a secondary database for each database listed in `databases`. If the secondary databases need to be managed through this provider, they should be defined as resources and a dependency added to the failover group to ensure the secondary databases are created first.
Databases pulumi.StringArrayOutput `pulumi:"databases"`
// the location of the failover group.
Location pulumi.StringOutput `pulumi:"location"`
// The name of the failover group. Changing this forces a new resource to be created.
Name pulumi.StringOutput `pulumi:"name"`
// A list of `partnerServers` blocks as documented below.
PartnerServers FailoverGroupPartnerServerArrayOutput `pulumi:"partnerServers"`
// A `readWriteEndpointFailoverPolicy` block as documented below.
ReadWriteEndpointFailoverPolicy FailoverGroupReadWriteEndpointFailoverPolicyOutput `pulumi:"readWriteEndpointFailoverPolicy"`
// A `readonlyEndpointFailoverPolicy` block as documented below.
ReadonlyEndpointFailoverPolicy FailoverGroupReadonlyEndpointFailoverPolicyOutput `pulumi:"readonlyEndpointFailoverPolicy"`
// The name of the resource group containing the SQL server Changing this forces a new resource to be created.
ResourceGroupName pulumi.StringOutput `pulumi:"resourceGroupName"`
// local replication role of the failover group instance.
Role pulumi.StringOutput `pulumi:"role"`
// The name of the primary SQL server. Changing this forces a new resource to be created.
ServerName pulumi.StringOutput `pulumi:"serverName"`
// A mapping of tags to assign to the resource.
Tags pulumi.StringMapOutput `pulumi:"tags"`
}
// NewFailoverGroup registers a new resource with the given unique name, arguments, and options.
func NewFailoverGroup(ctx *pulumi.Context,
name string, args *FailoverGroupArgs, opts ...pulumi.ResourceOption) (*FailoverGroup, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.PartnerServers == nil {
return nil, errors.New("invalid value for required argument 'PartnerServers'")
}
if args.ReadWriteEndpointFailoverPolicy == nil {
return nil, errors.New("invalid value for required argument 'ReadWriteEndpointFailoverPolicy'")
}
if args.ResourceGroupName == nil {
return nil, errors.New("invalid value for required argument 'ResourceGroupName'")
}
if args.ServerName == nil {
return nil, errors.New("invalid value for required argument 'ServerName'")
}
opts = internal.PkgResourceDefaultOpts(opts)
var resource FailoverGroup
err := ctx.RegisterResource("azure:sql/failoverGroup:FailoverGroup", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetFailoverGroup gets an existing FailoverGroup 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 GetFailoverGroup(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *FailoverGroupState, opts ...pulumi.ResourceOption) (*FailoverGroup, error) {
var resource FailoverGroup
err := ctx.ReadResource("azure:sql/failoverGroup:FailoverGroup", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering FailoverGroup resources.
type failoverGroupState struct {
// A list of database ids to add to the failover group
//
// > **NOTE:** The failover group will create a secondary database for each database listed in `databases`. If the secondary databases need to be managed through this provider, they should be defined as resources and a dependency added to the failover group to ensure the secondary databases are created first.
Databases []string `pulumi:"databases"`
// the location of the failover group.
Location *string `pulumi:"location"`
// The name of the failover group. Changing this forces a new resource to be created.
Name *string `pulumi:"name"`
// A list of `partnerServers` blocks as documented below.
PartnerServers []FailoverGroupPartnerServer `pulumi:"partnerServers"`
// A `readWriteEndpointFailoverPolicy` block as documented below.
ReadWriteEndpointFailoverPolicy *FailoverGroupReadWriteEndpointFailoverPolicy `pulumi:"readWriteEndpointFailoverPolicy"`
// A `readonlyEndpointFailoverPolicy` block as documented below.
ReadonlyEndpointFailoverPolicy *FailoverGroupReadonlyEndpointFailoverPolicy `pulumi:"readonlyEndpointFailoverPolicy"`
// The name of the resource group containing the SQL server Changing this forces a new resource to be created.
ResourceGroupName *string `pulumi:"resourceGroupName"`
// local replication role of the failover group instance.
Role *string `pulumi:"role"`
// The name of the primary SQL server. Changing this forces a new resource to be created.
ServerName *string `pulumi:"serverName"`
// A mapping of tags to assign to the resource.
Tags map[string]string `pulumi:"tags"`
}
type FailoverGroupState struct {
// A list of database ids to add to the failover group
//
// > **NOTE:** The failover group will create a secondary database for each database listed in `databases`. If the secondary databases need to be managed through this provider, they should be defined as resources and a dependency added to the failover group to ensure the secondary databases are created first.
Databases pulumi.StringArrayInput
// the location of the failover group.
Location pulumi.StringPtrInput
// The name of the failover group. Changing this forces a new resource to be created.
Name pulumi.StringPtrInput
// A list of `partnerServers` blocks as documented below.
PartnerServers FailoverGroupPartnerServerArrayInput
// A `readWriteEndpointFailoverPolicy` block as documented below.
ReadWriteEndpointFailoverPolicy FailoverGroupReadWriteEndpointFailoverPolicyPtrInput
// A `readonlyEndpointFailoverPolicy` block as documented below.
ReadonlyEndpointFailoverPolicy FailoverGroupReadonlyEndpointFailoverPolicyPtrInput
// The name of the resource group containing the SQL server Changing this forces a new resource to be created.
ResourceGroupName pulumi.StringPtrInput
// local replication role of the failover group instance.
Role pulumi.StringPtrInput
// The name of the primary SQL server. Changing this forces a new resource to be created.
ServerName pulumi.StringPtrInput
// A mapping of tags to assign to the resource.
Tags pulumi.StringMapInput
}
func (FailoverGroupState) ElementType() reflect.Type {
return reflect.TypeOf((*failoverGroupState)(nil)).Elem()
}
type failoverGroupArgs struct {
// A list of database ids to add to the failover group
//
// > **NOTE:** The failover group will create a secondary database for each database listed in `databases`. If the secondary databases need to be managed through this provider, they should be defined as resources and a dependency added to the failover group to ensure the secondary databases are created first.
Databases []string `pulumi:"databases"`
// The name of the failover group. Changing this forces a new resource to be created.
Name *string `pulumi:"name"`
// A list of `partnerServers` blocks as documented below.
PartnerServers []FailoverGroupPartnerServer `pulumi:"partnerServers"`
// A `readWriteEndpointFailoverPolicy` block as documented below.
ReadWriteEndpointFailoverPolicy FailoverGroupReadWriteEndpointFailoverPolicy `pulumi:"readWriteEndpointFailoverPolicy"`
// A `readonlyEndpointFailoverPolicy` block as documented below.
ReadonlyEndpointFailoverPolicy *FailoverGroupReadonlyEndpointFailoverPolicy `pulumi:"readonlyEndpointFailoverPolicy"`
// The name of the resource group containing the SQL server Changing this forces a new resource to be created.
ResourceGroupName string `pulumi:"resourceGroupName"`
// The name of the primary SQL server. Changing this forces a new resource to be created.
ServerName string `pulumi:"serverName"`
// A mapping of tags to assign to the resource.
Tags map[string]string `pulumi:"tags"`
}
// The set of arguments for constructing a FailoverGroup resource.
type FailoverGroupArgs struct {
// A list of database ids to add to the failover group
//
// > **NOTE:** The failover group will create a secondary database for each database listed in `databases`. If the secondary databases need to be managed through this provider, they should be defined as resources and a dependency added to the failover group to ensure the secondary databases are created first.
Databases pulumi.StringArrayInput
// The name of the failover group. Changing this forces a new resource to be created.
Name pulumi.StringPtrInput
// A list of `partnerServers` blocks as documented below.
PartnerServers FailoverGroupPartnerServerArrayInput
// A `readWriteEndpointFailoverPolicy` block as documented below.
ReadWriteEndpointFailoverPolicy FailoverGroupReadWriteEndpointFailoverPolicyInput
// A `readonlyEndpointFailoverPolicy` block as documented below.
ReadonlyEndpointFailoverPolicy FailoverGroupReadonlyEndpointFailoverPolicyPtrInput
// The name of the resource group containing the SQL server Changing this forces a new resource to be created.
ResourceGroupName pulumi.StringInput
// The name of the primary SQL server. Changing this forces a new resource to be created.
ServerName pulumi.StringInput
// A mapping of tags to assign to the resource.
Tags pulumi.StringMapInput
}
func (FailoverGroupArgs) ElementType() reflect.Type {
return reflect.TypeOf((*failoverGroupArgs)(nil)).Elem()
}
type FailoverGroupInput interface {
pulumi.Input
ToFailoverGroupOutput() FailoverGroupOutput
ToFailoverGroupOutputWithContext(ctx context.Context) FailoverGroupOutput
}
func (*FailoverGroup) ElementType() reflect.Type {
return reflect.TypeOf((**FailoverGroup)(nil)).Elem()
}
func (i *FailoverGroup) ToFailoverGroupOutput() FailoverGroupOutput {
return i.ToFailoverGroupOutputWithContext(context.Background())
}
func (i *FailoverGroup) ToFailoverGroupOutputWithContext(ctx context.Context) FailoverGroupOutput {
return pulumi.ToOutputWithContext(ctx, i).(FailoverGroupOutput)
}
// FailoverGroupArrayInput is an input type that accepts FailoverGroupArray and FailoverGroupArrayOutput values.
// You can construct a concrete instance of `FailoverGroupArrayInput` via:
//
// FailoverGroupArray{ FailoverGroupArgs{...} }
type FailoverGroupArrayInput interface {
pulumi.Input
ToFailoverGroupArrayOutput() FailoverGroupArrayOutput
ToFailoverGroupArrayOutputWithContext(context.Context) FailoverGroupArrayOutput
}
type FailoverGroupArray []FailoverGroupInput
func (FailoverGroupArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*FailoverGroup)(nil)).Elem()
}
func (i FailoverGroupArray) ToFailoverGroupArrayOutput() FailoverGroupArrayOutput {
return i.ToFailoverGroupArrayOutputWithContext(context.Background())
}
func (i FailoverGroupArray) ToFailoverGroupArrayOutputWithContext(ctx context.Context) FailoverGroupArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(FailoverGroupArrayOutput)
}
// FailoverGroupMapInput is an input type that accepts FailoverGroupMap and FailoverGroupMapOutput values.
// You can construct a concrete instance of `FailoverGroupMapInput` via:
//
// FailoverGroupMap{ "key": FailoverGroupArgs{...} }
type FailoverGroupMapInput interface {
pulumi.Input
ToFailoverGroupMapOutput() FailoverGroupMapOutput
ToFailoverGroupMapOutputWithContext(context.Context) FailoverGroupMapOutput
}
type FailoverGroupMap map[string]FailoverGroupInput
func (FailoverGroupMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*FailoverGroup)(nil)).Elem()
}
func (i FailoverGroupMap) ToFailoverGroupMapOutput() FailoverGroupMapOutput {
return i.ToFailoverGroupMapOutputWithContext(context.Background())
}
func (i FailoverGroupMap) ToFailoverGroupMapOutputWithContext(ctx context.Context) FailoverGroupMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(FailoverGroupMapOutput)
}
type FailoverGroupOutput struct{ *pulumi.OutputState }
func (FailoverGroupOutput) ElementType() reflect.Type {
return reflect.TypeOf((**FailoverGroup)(nil)).Elem()
}
func (o FailoverGroupOutput) ToFailoverGroupOutput() FailoverGroupOutput {
return o
}
func (o FailoverGroupOutput) ToFailoverGroupOutputWithContext(ctx context.Context) FailoverGroupOutput {
return o
}
// A list of database ids to add to the failover group
//
// > **NOTE:** The failover group will create a secondary database for each database listed in `databases`. If the secondary databases need to be managed through this provider, they should be defined as resources and a dependency added to the failover group to ensure the secondary databases are created first.
func (o FailoverGroupOutput) Databases() pulumi.StringArrayOutput {
return o.ApplyT(func(v *FailoverGroup) pulumi.StringArrayOutput { return v.Databases }).(pulumi.StringArrayOutput)
}
// the location of the failover group.
func (o FailoverGroupOutput) Location() pulumi.StringOutput {
return o.ApplyT(func(v *FailoverGroup) pulumi.StringOutput { return v.Location }).(pulumi.StringOutput)
}
// The name of the failover group. Changing this forces a new resource to be created.
func (o FailoverGroupOutput) Name() pulumi.StringOutput {
return o.ApplyT(func(v *FailoverGroup) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
}
// A list of `partnerServers` blocks as documented below.
func (o FailoverGroupOutput) PartnerServers() FailoverGroupPartnerServerArrayOutput {
return o.ApplyT(func(v *FailoverGroup) FailoverGroupPartnerServerArrayOutput { return v.PartnerServers }).(FailoverGroupPartnerServerArrayOutput)
}
// A `readWriteEndpointFailoverPolicy` block as documented below.
func (o FailoverGroupOutput) ReadWriteEndpointFailoverPolicy() FailoverGroupReadWriteEndpointFailoverPolicyOutput {
return o.ApplyT(func(v *FailoverGroup) FailoverGroupReadWriteEndpointFailoverPolicyOutput {
return v.ReadWriteEndpointFailoverPolicy
}).(FailoverGroupReadWriteEndpointFailoverPolicyOutput)
}
// A `readonlyEndpointFailoverPolicy` block as documented below.
func (o FailoverGroupOutput) ReadonlyEndpointFailoverPolicy() FailoverGroupReadonlyEndpointFailoverPolicyOutput {
return o.ApplyT(func(v *FailoverGroup) FailoverGroupReadonlyEndpointFailoverPolicyOutput {
return v.ReadonlyEndpointFailoverPolicy
}).(FailoverGroupReadonlyEndpointFailoverPolicyOutput)
}
// The name of the resource group containing the SQL server Changing this forces a new resource to be created.
func (o FailoverGroupOutput) ResourceGroupName() pulumi.StringOutput {
return o.ApplyT(func(v *FailoverGroup) pulumi.StringOutput { return v.ResourceGroupName }).(pulumi.StringOutput)
}
// local replication role of the failover group instance.
func (o FailoverGroupOutput) Role() pulumi.StringOutput {
return o.ApplyT(func(v *FailoverGroup) pulumi.StringOutput { return v.Role }).(pulumi.StringOutput)
}
// The name of the primary SQL server. Changing this forces a new resource to be created.
func (o FailoverGroupOutput) ServerName() pulumi.StringOutput {
return o.ApplyT(func(v *FailoverGroup) pulumi.StringOutput { return v.ServerName }).(pulumi.StringOutput)
}
// A mapping of tags to assign to the resource.
func (o FailoverGroupOutput) Tags() pulumi.StringMapOutput {
return o.ApplyT(func(v *FailoverGroup) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput)
}
type FailoverGroupArrayOutput struct{ *pulumi.OutputState }
func (FailoverGroupArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*FailoverGroup)(nil)).Elem()
}
func (o FailoverGroupArrayOutput) ToFailoverGroupArrayOutput() FailoverGroupArrayOutput {
return o
}
func (o FailoverGroupArrayOutput) ToFailoverGroupArrayOutputWithContext(ctx context.Context) FailoverGroupArrayOutput {
return o
}
func (o FailoverGroupArrayOutput) Index(i pulumi.IntInput) FailoverGroupOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *FailoverGroup {
return vs[0].([]*FailoverGroup)[vs[1].(int)]
}).(FailoverGroupOutput)
}
type FailoverGroupMapOutput struct{ *pulumi.OutputState }
func (FailoverGroupMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*FailoverGroup)(nil)).Elem()
}
func (o FailoverGroupMapOutput) ToFailoverGroupMapOutput() FailoverGroupMapOutput {
return o
}
func (o FailoverGroupMapOutput) ToFailoverGroupMapOutputWithContext(ctx context.Context) FailoverGroupMapOutput {
return o
}
func (o FailoverGroupMapOutput) MapIndex(k pulumi.StringInput) FailoverGroupOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *FailoverGroup {
return vs[0].(map[string]*FailoverGroup)[vs[1].(string)]
}).(FailoverGroupOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*FailoverGroupInput)(nil)).Elem(), &FailoverGroup{})
pulumi.RegisterInputType(reflect.TypeOf((*FailoverGroupArrayInput)(nil)).Elem(), FailoverGroupArray{})
pulumi.RegisterInputType(reflect.TypeOf((*FailoverGroupMapInput)(nil)).Elem(), FailoverGroupMap{})
pulumi.RegisterOutputType(FailoverGroupOutput{})
pulumi.RegisterOutputType(FailoverGroupArrayOutput{})
pulumi.RegisterOutputType(FailoverGroupMapOutput{})
}