/
monitor.go
460 lines (404 loc) · 17.3 KB
/
monitor.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 datadog
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Manages a datadog Monitor.
//
// ## Example Usage
//
// ### Monitor creation with linking to Datadog organization
//
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core"
// "github.com/pulumi/pulumi-azure/sdk/v5/go/azure/datadog"
// "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-datadog"),
// Location: pulumi.String("West US 2"),
// })
// if err != nil {
// return err
// }
// _, err = datadog.NewMonitor(ctx, "example", &datadog.MonitorArgs{
// Name: pulumi.String("example-monitor"),
// ResourceGroupName: example.Name,
// Location: example.Location,
// DatadogOrganization: &datadog.MonitorDatadogOrganizationArgs{
// ApiKey: pulumi.String("XXXX"),
// ApplicationKey: pulumi.String("XXXX"),
// },
// User: &datadog.MonitorUserArgs{
// Name: pulumi.String("Example"),
// Email: pulumi.String("abc@xyz.com"),
// },
// SkuName: pulumi.String("Linked"),
// Identity: &datadog.MonitorIdentityArgs{
// Type: pulumi.String("SystemAssigned"),
// },
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
//
// ## Role Assignment
//
// To enable metrics flow, perform role assignment on the identity created above. `Monitoring reader(43d0d8ad-25c7-4714-9337-8ba259a9fe05)` role is required .
//
// ### Role assignment on the monitor created
//
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-azure/sdk/v5/go/azure/authorization"
// "github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// primary, err := core.LookupSubscription(ctx, nil, nil)
// if err != nil {
// return err
// }
// monitoringReader, err := authorization.LookupRoleDefinition(ctx, &authorization.LookupRoleDefinitionArgs{
// Name: pulumi.StringRef("Monitoring Reader"),
// }, nil)
// if err != nil {
// return err
// }
// _, err = authorization.NewAssignment(ctx, "example", &authorization.AssignmentArgs{
// Scope: pulumi.String(primary.Id),
// RoleDefinitionId: pulumi.String(monitoringReader.RoleDefinitionId),
// PrincipalId: pulumi.Any(exampleAzurermDatadogMonitor.Identity[0].PrincipalId),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
//
// ## Import
//
// Datadog Monitors can be imported using the `resource id`, e.g.
//
// ```sh
// $ pulumi import azure:datadog/monitor:Monitor example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Datadog/monitors/monitor1
// ```
type Monitor struct {
pulumi.CustomResourceState
// A `datadogOrganization` block as defined below.
DatadogOrganization MonitorDatadogOrganizationOutput `pulumi:"datadogOrganization"`
// A `identity` block as defined below.
Identity MonitorIdentityPtrOutput `pulumi:"identity"`
// The Azure Region where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
Location pulumi.StringOutput `pulumi:"location"`
// Flag specifying the Marketplace Subscription Status of the resource. If payment is not made in time, the resource will go in Suspended state.
MarketplaceSubscriptionStatus pulumi.StringOutput `pulumi:"marketplaceSubscriptionStatus"`
// Is monitoring enabled? Defaults to `true`.
MonitoringEnabled pulumi.BoolPtrOutput `pulumi:"monitoringEnabled"`
// The name of the user that will be associated with the Datadog Monitor. Changing this forces a new Datadog Monitor to be created.
Name pulumi.StringOutput `pulumi:"name"`
// The name of the Resource Group where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
ResourceGroupName pulumi.StringOutput `pulumi:"resourceGroupName"`
// The name which should be used for this sku.
SkuName pulumi.StringOutput `pulumi:"skuName"`
// A mapping of tags which should be assigned to the Datadog Monitor.
Tags pulumi.StringMapOutput `pulumi:"tags"`
// A `user` block as defined below.
User MonitorUserOutput `pulumi:"user"`
}
// NewMonitor registers a new resource with the given unique name, arguments, and options.
func NewMonitor(ctx *pulumi.Context,
name string, args *MonitorArgs, opts ...pulumi.ResourceOption) (*Monitor, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.DatadogOrganization == nil {
return nil, errors.New("invalid value for required argument 'DatadogOrganization'")
}
if args.ResourceGroupName == nil {
return nil, errors.New("invalid value for required argument 'ResourceGroupName'")
}
if args.SkuName == nil {
return nil, errors.New("invalid value for required argument 'SkuName'")
}
if args.User == nil {
return nil, errors.New("invalid value for required argument 'User'")
}
opts = internal.PkgResourceDefaultOpts(opts)
var resource Monitor
err := ctx.RegisterResource("azure:datadog/monitor:Monitor", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetMonitor gets an existing Monitor 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 GetMonitor(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *MonitorState, opts ...pulumi.ResourceOption) (*Monitor, error) {
var resource Monitor
err := ctx.ReadResource("azure:datadog/monitor:Monitor", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Monitor resources.
type monitorState struct {
// A `datadogOrganization` block as defined below.
DatadogOrganization *MonitorDatadogOrganization `pulumi:"datadogOrganization"`
// A `identity` block as defined below.
Identity *MonitorIdentity `pulumi:"identity"`
// The Azure Region where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
Location *string `pulumi:"location"`
// Flag specifying the Marketplace Subscription Status of the resource. If payment is not made in time, the resource will go in Suspended state.
MarketplaceSubscriptionStatus *string `pulumi:"marketplaceSubscriptionStatus"`
// Is monitoring enabled? Defaults to `true`.
MonitoringEnabled *bool `pulumi:"monitoringEnabled"`
// The name of the user that will be associated with the Datadog Monitor. Changing this forces a new Datadog Monitor to be created.
Name *string `pulumi:"name"`
// The name of the Resource Group where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
ResourceGroupName *string `pulumi:"resourceGroupName"`
// The name which should be used for this sku.
SkuName *string `pulumi:"skuName"`
// A mapping of tags which should be assigned to the Datadog Monitor.
Tags map[string]string `pulumi:"tags"`
// A `user` block as defined below.
User *MonitorUser `pulumi:"user"`
}
type MonitorState struct {
// A `datadogOrganization` block as defined below.
DatadogOrganization MonitorDatadogOrganizationPtrInput
// A `identity` block as defined below.
Identity MonitorIdentityPtrInput
// The Azure Region where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
Location pulumi.StringPtrInput
// Flag specifying the Marketplace Subscription Status of the resource. If payment is not made in time, the resource will go in Suspended state.
MarketplaceSubscriptionStatus pulumi.StringPtrInput
// Is monitoring enabled? Defaults to `true`.
MonitoringEnabled pulumi.BoolPtrInput
// The name of the user that will be associated with the Datadog Monitor. Changing this forces a new Datadog Monitor to be created.
Name pulumi.StringPtrInput
// The name of the Resource Group where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
ResourceGroupName pulumi.StringPtrInput
// The name which should be used for this sku.
SkuName pulumi.StringPtrInput
// A mapping of tags which should be assigned to the Datadog Monitor.
Tags pulumi.StringMapInput
// A `user` block as defined below.
User MonitorUserPtrInput
}
func (MonitorState) ElementType() reflect.Type {
return reflect.TypeOf((*monitorState)(nil)).Elem()
}
type monitorArgs struct {
// A `datadogOrganization` block as defined below.
DatadogOrganization MonitorDatadogOrganization `pulumi:"datadogOrganization"`
// A `identity` block as defined below.
Identity *MonitorIdentity `pulumi:"identity"`
// The Azure Region where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
Location *string `pulumi:"location"`
// Is monitoring enabled? Defaults to `true`.
MonitoringEnabled *bool `pulumi:"monitoringEnabled"`
// The name of the user that will be associated with the Datadog Monitor. Changing this forces a new Datadog Monitor to be created.
Name *string `pulumi:"name"`
// The name of the Resource Group where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
ResourceGroupName string `pulumi:"resourceGroupName"`
// The name which should be used for this sku.
SkuName string `pulumi:"skuName"`
// A mapping of tags which should be assigned to the Datadog Monitor.
Tags map[string]string `pulumi:"tags"`
// A `user` block as defined below.
User MonitorUser `pulumi:"user"`
}
// The set of arguments for constructing a Monitor resource.
type MonitorArgs struct {
// A `datadogOrganization` block as defined below.
DatadogOrganization MonitorDatadogOrganizationInput
// A `identity` block as defined below.
Identity MonitorIdentityPtrInput
// The Azure Region where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
Location pulumi.StringPtrInput
// Is monitoring enabled? Defaults to `true`.
MonitoringEnabled pulumi.BoolPtrInput
// The name of the user that will be associated with the Datadog Monitor. Changing this forces a new Datadog Monitor to be created.
Name pulumi.StringPtrInput
// The name of the Resource Group where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
ResourceGroupName pulumi.StringInput
// The name which should be used for this sku.
SkuName pulumi.StringInput
// A mapping of tags which should be assigned to the Datadog Monitor.
Tags pulumi.StringMapInput
// A `user` block as defined below.
User MonitorUserInput
}
func (MonitorArgs) ElementType() reflect.Type {
return reflect.TypeOf((*monitorArgs)(nil)).Elem()
}
type MonitorInput interface {
pulumi.Input
ToMonitorOutput() MonitorOutput
ToMonitorOutputWithContext(ctx context.Context) MonitorOutput
}
func (*Monitor) ElementType() reflect.Type {
return reflect.TypeOf((**Monitor)(nil)).Elem()
}
func (i *Monitor) ToMonitorOutput() MonitorOutput {
return i.ToMonitorOutputWithContext(context.Background())
}
func (i *Monitor) ToMonitorOutputWithContext(ctx context.Context) MonitorOutput {
return pulumi.ToOutputWithContext(ctx, i).(MonitorOutput)
}
// MonitorArrayInput is an input type that accepts MonitorArray and MonitorArrayOutput values.
// You can construct a concrete instance of `MonitorArrayInput` via:
//
// MonitorArray{ MonitorArgs{...} }
type MonitorArrayInput interface {
pulumi.Input
ToMonitorArrayOutput() MonitorArrayOutput
ToMonitorArrayOutputWithContext(context.Context) MonitorArrayOutput
}
type MonitorArray []MonitorInput
func (MonitorArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Monitor)(nil)).Elem()
}
func (i MonitorArray) ToMonitorArrayOutput() MonitorArrayOutput {
return i.ToMonitorArrayOutputWithContext(context.Background())
}
func (i MonitorArray) ToMonitorArrayOutputWithContext(ctx context.Context) MonitorArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(MonitorArrayOutput)
}
// MonitorMapInput is an input type that accepts MonitorMap and MonitorMapOutput values.
// You can construct a concrete instance of `MonitorMapInput` via:
//
// MonitorMap{ "key": MonitorArgs{...} }
type MonitorMapInput interface {
pulumi.Input
ToMonitorMapOutput() MonitorMapOutput
ToMonitorMapOutputWithContext(context.Context) MonitorMapOutput
}
type MonitorMap map[string]MonitorInput
func (MonitorMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Monitor)(nil)).Elem()
}
func (i MonitorMap) ToMonitorMapOutput() MonitorMapOutput {
return i.ToMonitorMapOutputWithContext(context.Background())
}
func (i MonitorMap) ToMonitorMapOutputWithContext(ctx context.Context) MonitorMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(MonitorMapOutput)
}
type MonitorOutput struct{ *pulumi.OutputState }
func (MonitorOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Monitor)(nil)).Elem()
}
func (o MonitorOutput) ToMonitorOutput() MonitorOutput {
return o
}
func (o MonitorOutput) ToMonitorOutputWithContext(ctx context.Context) MonitorOutput {
return o
}
// A `datadogOrganization` block as defined below.
func (o MonitorOutput) DatadogOrganization() MonitorDatadogOrganizationOutput {
return o.ApplyT(func(v *Monitor) MonitorDatadogOrganizationOutput { return v.DatadogOrganization }).(MonitorDatadogOrganizationOutput)
}
// A `identity` block as defined below.
func (o MonitorOutput) Identity() MonitorIdentityPtrOutput {
return o.ApplyT(func(v *Monitor) MonitorIdentityPtrOutput { return v.Identity }).(MonitorIdentityPtrOutput)
}
// The Azure Region where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
func (o MonitorOutput) Location() pulumi.StringOutput {
return o.ApplyT(func(v *Monitor) pulumi.StringOutput { return v.Location }).(pulumi.StringOutput)
}
// Flag specifying the Marketplace Subscription Status of the resource. If payment is not made in time, the resource will go in Suspended state.
func (o MonitorOutput) MarketplaceSubscriptionStatus() pulumi.StringOutput {
return o.ApplyT(func(v *Monitor) pulumi.StringOutput { return v.MarketplaceSubscriptionStatus }).(pulumi.StringOutput)
}
// Is monitoring enabled? Defaults to `true`.
func (o MonitorOutput) MonitoringEnabled() pulumi.BoolPtrOutput {
return o.ApplyT(func(v *Monitor) pulumi.BoolPtrOutput { return v.MonitoringEnabled }).(pulumi.BoolPtrOutput)
}
// The name of the user that will be associated with the Datadog Monitor. Changing this forces a new Datadog Monitor to be created.
func (o MonitorOutput) Name() pulumi.StringOutput {
return o.ApplyT(func(v *Monitor) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
}
// The name of the Resource Group where the Datadog Monitor should exist. Changing this forces a new Datadog Monitor to be created.
func (o MonitorOutput) ResourceGroupName() pulumi.StringOutput {
return o.ApplyT(func(v *Monitor) pulumi.StringOutput { return v.ResourceGroupName }).(pulumi.StringOutput)
}
// The name which should be used for this sku.
func (o MonitorOutput) SkuName() pulumi.StringOutput {
return o.ApplyT(func(v *Monitor) pulumi.StringOutput { return v.SkuName }).(pulumi.StringOutput)
}
// A mapping of tags which should be assigned to the Datadog Monitor.
func (o MonitorOutput) Tags() pulumi.StringMapOutput {
return o.ApplyT(func(v *Monitor) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput)
}
// A `user` block as defined below.
func (o MonitorOutput) User() MonitorUserOutput {
return o.ApplyT(func(v *Monitor) MonitorUserOutput { return v.User }).(MonitorUserOutput)
}
type MonitorArrayOutput struct{ *pulumi.OutputState }
func (MonitorArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Monitor)(nil)).Elem()
}
func (o MonitorArrayOutput) ToMonitorArrayOutput() MonitorArrayOutput {
return o
}
func (o MonitorArrayOutput) ToMonitorArrayOutputWithContext(ctx context.Context) MonitorArrayOutput {
return o
}
func (o MonitorArrayOutput) Index(i pulumi.IntInput) MonitorOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Monitor {
return vs[0].([]*Monitor)[vs[1].(int)]
}).(MonitorOutput)
}
type MonitorMapOutput struct{ *pulumi.OutputState }
func (MonitorMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Monitor)(nil)).Elem()
}
func (o MonitorMapOutput) ToMonitorMapOutput() MonitorMapOutput {
return o
}
func (o MonitorMapOutput) ToMonitorMapOutputWithContext(ctx context.Context) MonitorMapOutput {
return o
}
func (o MonitorMapOutput) MapIndex(k pulumi.StringInput) MonitorOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Monitor {
return vs[0].(map[string]*Monitor)[vs[1].(string)]
}).(MonitorOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*MonitorInput)(nil)).Elem(), &Monitor{})
pulumi.RegisterInputType(reflect.TypeOf((*MonitorArrayInput)(nil)).Elem(), MonitorArray{})
pulumi.RegisterInputType(reflect.TypeOf((*MonitorMapInput)(nil)).Elem(), MonitorMap{})
pulumi.RegisterOutputType(MonitorOutput{})
pulumi.RegisterOutputType(MonitorArrayOutput{})
pulumi.RegisterOutputType(MonitorMapOutput{})
}