8
8
"strings"
9
9
10
10
"github.com/hashicorp/terraform/helper/schema"
11
- "github.com /zorkian/go-datadog-api"
11
+ "gopkg.in /zorkian/go-datadog-api.v2 "
12
12
)
13
13
14
14
func resourceDatadogMonitor () * schema.Resource {
@@ -137,17 +137,18 @@ func buildMonitorStruct(d *schema.ResourceData) *datadog.Monitor {
137
137
var thresholds datadog.ThresholdCount
138
138
139
139
if r , ok := d .GetOk ("thresholds.ok" ); ok {
140
- thresholds .Ok = json .Number (r .(string ))
140
+ thresholds .SetOk ( json .Number (r .(string ) ))
141
141
}
142
142
if r , ok := d .GetOk ("thresholds.warning" ); ok {
143
- thresholds .Warning = json .Number (r .(string ))
143
+ thresholds .SetWarning ( json .Number (r .(string ) ))
144
144
}
145
145
if r , ok := d .GetOk ("thresholds.critical" ); ok {
146
- thresholds .Critical = json .Number (r .(string ))
146
+ thresholds .SetCritical ( json .Number (r .(string ) ))
147
147
}
148
148
149
149
o := datadog.Options {
150
- Thresholds : thresholds ,
150
+ Thresholds : & thresholds ,
151
+ NotifyNoData : datadog .Bool (d .Get ("notify_no_data" ).(bool )),
151
152
}
152
153
if attr , ok := d .GetOk ("silenced" ); ok {
153
154
s := make (map [string ]int )
@@ -158,42 +159,42 @@ func buildMonitorStruct(d *schema.ResourceData) *datadog.Monitor {
158
159
o .Silenced = s
159
160
}
160
161
if attr , ok := d .GetOk ("notify_no_data" ); ok {
161
- o .NotifyNoData = attr .(bool )
162
+ o .SetNotifyNoData ( attr .(bool ) )
162
163
}
163
164
if attr , ok := d .GetOk ("new_host_delay" ); ok {
164
- o .NewHostDelay = datadog . Int (attr .(int ))
165
+ o .SetNewHostDelay (attr .(int ))
165
166
}
166
167
if attr , ok := d .GetOk ("no_data_timeframe" ); ok {
167
168
o .NoDataTimeframe = datadog .NoDataTimeframe (attr .(int ))
168
169
}
169
170
if attr , ok := d .GetOk ("renotify_interval" ); ok {
170
- o .RenotifyInterval = attr .(int )
171
+ o .SetRenotifyInterval ( attr .(int ) )
171
172
}
172
173
if attr , ok := d .GetOk ("notify_audit" ); ok {
173
- o .NotifyAudit = attr .(bool )
174
+ o .SetNotifyAudit ( attr .(bool ) )
174
175
}
175
176
if attr , ok := d .GetOk ("timeout_h" ); ok {
176
- o .TimeoutH = attr .(int )
177
+ o .SetTimeoutH ( attr .(int ) )
177
178
}
178
179
if attr , ok := d .GetOk ("escalation_message" ); ok {
179
- o .EscalationMessage = attr .(string )
180
+ o .SetEscalationMessage ( attr .(string ) )
180
181
}
181
182
if attr , ok := d .GetOk ("include_tags" ); ok {
182
- o .IncludeTags = attr .(bool )
183
+ o .SetIncludeTags ( attr .(bool ) )
183
184
}
184
185
if attr , ok := d .GetOk ("require_full_window" ); ok {
185
- o .RequireFullWindow = attr .(bool )
186
+ o .SetRequireFullWindow ( attr .(bool ) )
186
187
}
187
188
if attr , ok := d .GetOk ("locked" ); ok {
188
- o .Locked = attr .(bool )
189
+ o .SetLocked ( attr .(bool ) )
189
190
}
190
191
191
192
m := datadog.Monitor {
192
- Type : d .Get ("type" ).(string ),
193
- Query : d .Get ("query" ).(string ),
194
- Name : d .Get ("name" ).(string ),
195
- Message : d .Get ("message" ).(string ),
196
- Options : o ,
193
+ Type : datadog . String ( d .Get ("type" ).(string ) ),
194
+ Query : datadog . String ( d .Get ("query" ).(string ) ),
195
+ Name : datadog . String ( d .Get ("name" ).(string ) ),
196
+ Message : datadog . String ( d .Get ("message" ).(string ) ),
197
+ Options : & o ,
197
198
}
198
199
199
200
if attr , ok := d .GetOk ("tags" ); ok {
@@ -237,7 +238,7 @@ func resourceDatadogMonitorCreate(d *schema.ResourceData, meta interface{}) erro
237
238
return fmt .Errorf ("error updating monitor: %s" , err .Error ())
238
239
}
239
240
240
- d .SetId (strconv .Itoa (m .Id ))
241
+ d .SetId (strconv .Itoa (m .GetId () ))
241
242
242
243
return nil
243
244
}
@@ -257,9 +258,9 @@ func resourceDatadogMonitorRead(d *schema.ResourceData, meta interface{}) error
257
258
258
259
thresholds := make (map [string ]string )
259
260
for k , v := range map [string ]json.Number {
260
- "ok" : m .Options .Thresholds .Ok ,
261
- "warning" : m .Options .Thresholds .Warning ,
262
- "critical" : m .Options .Thresholds .Critical ,
261
+ "ok" : m .Options .Thresholds .GetOk () ,
262
+ "warning" : m .Options .Thresholds .GetWarning () ,
263
+ "critical" : m .Options .Thresholds .GetCritical () ,
263
264
} {
264
265
s := v .String ()
265
266
if s != "" {
@@ -273,24 +274,24 @@ func resourceDatadogMonitorRead(d *schema.ResourceData, meta interface{}) error
273
274
}
274
275
275
276
log .Printf ("[DEBUG] monitor: %v" , m )
276
- d .Set ("name" , m .Name )
277
- d .Set ("message" , m .Message )
278
- d .Set ("query" , m .Query )
279
- d .Set ("type" , m .Type )
277
+ d .Set ("name" , m .GetName () )
278
+ d .Set ("message" , m .GetMessage () )
279
+ d .Set ("query" , m .GetQuery () )
280
+ d .Set ("type" , m .GetType () )
280
281
d .Set ("thresholds" , thresholds )
281
282
282
- d .Set ("new_host_delay" , m .Options .NewHostDelay )
283
- d .Set ("notify_no_data" , m .Options .NotifyNoData )
283
+ d .Set ("new_host_delay" , m .Options .GetNewHostDelay () )
284
+ d .Set ("notify_no_data" , m .Options .GetNotifyNoData () )
284
285
d .Set ("no_data_timeframe" , m .Options .NoDataTimeframe )
285
- d .Set ("renotify_interval" , m .Options .RenotifyInterval )
286
- d .Set ("notify_audit" , m .Options .NotifyAudit )
287
- d .Set ("timeout_h" , m .Options .TimeoutH )
288
- d .Set ("escalation_message" , m .Options .EscalationMessage )
286
+ d .Set ("renotify_interval" , m .Options .GetRenotifyInterval () )
287
+ d .Set ("notify_audit" , m .Options .GetNotifyAudit () )
288
+ d .Set ("timeout_h" , m .Options .GetTimeoutH () )
289
+ d .Set ("escalation_message" , m .Options .GetEscalationMessage () )
289
290
d .Set ("silenced" , m .Options .Silenced )
290
- d .Set ("include_tags" , m .Options .IncludeTags )
291
+ d .Set ("include_tags" , m .Options .GetIncludeTags () )
291
292
d .Set ("tags" , tags )
292
- d .Set ("require_full_window" , m .Options .RequireFullWindow )
293
- d .Set ("locked" , m .Options .Locked )
293
+ d .Set ("require_full_window" , m .Options .GetRequireFullWindow ()) // TODO Is this one of those options that we neeed to check?
294
+ d .Set ("locked" , m .Options .GetLocked () )
294
295
295
296
return nil
296
297
}
@@ -305,15 +306,15 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
305
306
return err
306
307
}
307
308
308
- m .Id = i
309
+ m .Id = datadog . Int ( i )
309
310
if attr , ok := d .GetOk ("name" ); ok {
310
- m .Name = attr .(string )
311
+ m .SetName ( attr .(string ) )
311
312
}
312
313
if attr , ok := d .GetOk ("message" ); ok {
313
- m .Message = attr .(string )
314
+ m .SetMessage ( attr .(string ) )
314
315
}
315
316
if attr , ok := d .GetOk ("query" ); ok {
316
- m .Query = attr .(string )
317
+ m .SetQuery ( attr .(string ) )
317
318
}
318
319
319
320
if attr , ok := d .GetOk ("tags" ); ok {
@@ -324,40 +325,43 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
324
325
m .Tags = s
325
326
}
326
327
327
- o := datadog.Options {}
328
+ o := datadog.Options {
329
+ NotifyNoData : datadog .Bool (d .Get ("notify_no_data" ).(bool )),
330
+ }
328
331
if attr , ok := d .GetOk ("thresholds" ); ok {
329
332
thresholds := attr .(map [string ]interface {})
333
+ o .Thresholds = & datadog.ThresholdCount {} // TODO: This is a little annoying..
330
334
if thresholds ["ok" ] != nil {
331
- o .Thresholds .Ok = json .Number (thresholds ["ok" ].(string ))
335
+ o .Thresholds .SetOk ( json .Number (thresholds ["ok" ].(string ) ))
332
336
}
333
337
if thresholds ["warning" ] != nil {
334
- o .Thresholds .Warning = json .Number (thresholds ["warning" ].(string ))
338
+ o .Thresholds .SetWarning ( json .Number (thresholds ["warning" ].(string ) ))
335
339
}
336
340
if thresholds ["critical" ] != nil {
337
- o .Thresholds .Critical = json .Number (thresholds ["critical" ].(string ))
341
+ o .Thresholds .SetCritical ( json .Number (thresholds ["critical" ].(string ) ))
338
342
}
339
343
}
340
344
341
345
if attr , ok := d .GetOk ("notify_no_data" ); ok {
342
- o .NotifyNoData = attr .(bool )
346
+ o .SetNotifyNoData ( attr .(bool ) )
343
347
}
344
348
if attr , ok := d .GetOk ("new_host_delay" ); ok {
345
- o .NewHostDelay = datadog . Int (attr .(int ))
349
+ o .SetNewHostDelay (attr .(int ))
346
350
}
347
351
if attr , ok := d .GetOk ("no_data_timeframe" ); ok {
348
352
o .NoDataTimeframe = datadog .NoDataTimeframe (attr .(int ))
349
353
}
350
354
if attr , ok := d .GetOk ("renotify_interval" ); ok {
351
- o .RenotifyInterval = attr .(int )
355
+ o .SetRenotifyInterval ( attr .(int ) )
352
356
}
353
357
if attr , ok := d .GetOk ("notify_audit" ); ok {
354
- o .NotifyAudit = attr .(bool )
358
+ o .SetNotifyAudit ( attr .(bool ) )
355
359
}
356
360
if attr , ok := d .GetOk ("timeout_h" ); ok {
357
- o .TimeoutH = attr .(int )
361
+ o .SetTimeoutH ( attr .(int ) )
358
362
}
359
363
if attr , ok := d .GetOk ("escalation_message" ); ok {
360
- o .EscalationMessage = attr .(string )
364
+ o .SetEscalationMessage ( attr .(string ) )
361
365
}
362
366
if attr , ok := d .GetOk ("silenced" ); ok {
363
367
// TODO: this is not very defensive, test if we can fail non int input
@@ -368,16 +372,16 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
368
372
o .Silenced = s
369
373
}
370
374
if attr , ok := d .GetOk ("include_tags" ); ok {
371
- o .IncludeTags = attr .(bool )
375
+ o .SetIncludeTags ( attr .(bool ) )
372
376
}
373
377
if attr , ok := d .GetOk ("require_full_window" ); ok {
374
- o .RequireFullWindow = attr .(bool )
378
+ o .SetRequireFullWindow ( attr .(bool ) )
375
379
}
376
380
if attr , ok := d .GetOk ("locked" ); ok {
377
- o .Locked = attr .(bool )
381
+ o .SetLocked ( attr .(bool ) )
378
382
}
379
383
380
- m .Options = o
384
+ m .Options = & o
381
385
382
386
if err = client .UpdateMonitor (m ); err != nil {
383
387
return fmt .Errorf ("error updating monitor: %s" , err .Error ())
0 commit comments