@@ -400,18 +400,6 @@ func (d *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
400
400
return
401
401
}
402
402
403
- metricsRetentionResp , err := d .client .GetMetricsStorageRetention (ctx , instanceId , projectId ).Execute ()
404
- if err != nil {
405
- core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading instance" , fmt .Sprintf ("Calling API to get metrics retention: %v" , err ))
406
- return
407
- }
408
-
409
- alertConfigResp , err := d .client .GetAlertConfigs (ctx , instanceId , projectId ).Execute ()
410
- if err != nil {
411
- core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading instance" , fmt .Sprintf ("Calling API to get alert config: %v" , err ))
412
- return
413
- }
414
-
415
403
// Map response body to schema
416
404
err = mapFields (ctx , instanceResp , & model )
417
405
if err != nil {
@@ -426,6 +414,12 @@ func (d *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
426
414
return
427
415
}
428
416
417
+ plan , err := loadPlanId (ctx , * d .client , & model )
418
+ if err != nil {
419
+ core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading instance" , fmt .Sprintf ("Loading service plan: %v" , err ))
420
+ return
421
+ }
422
+
429
423
err = mapACLField (aclListResp , & model )
430
424
if err != nil {
431
425
core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading instance" , fmt .Sprintf ("Processing API response for the ACL: %v" , err ))
@@ -439,31 +433,48 @@ func (d *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
439
433
return
440
434
}
441
435
442
- // Map response body to schema
443
- err = mapMetricsRetentionField (metricsRetentionResp , & model )
444
- if err != nil {
445
- core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading instance" , fmt .Sprintf ("Processing API response for the metrics retention: %v" , err ))
446
- return
436
+ // There are some plans which does not offer storage e.g. like Observability-Metrics-Endpoint-100k-EU01
437
+ if plan .GetLogsStorage () != 0 && plan .GetTracesStorage () != 0 {
438
+ metricsRetentionResp , err := d .client .GetMetricsStorageRetention (ctx , instanceId , projectId ).Execute ()
439
+ if err != nil {
440
+ core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading instance" , fmt .Sprintf ("Calling API to get metrics retention: %v" , err ))
441
+ return
442
+ }
443
+ // Map response body to schema
444
+ err = mapMetricsRetentionField (metricsRetentionResp , & model )
445
+ if err != nil {
446
+ core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading instance" , fmt .Sprintf ("Processing API response for the metrics retention: %v" , err ))
447
+ return
448
+ }
449
+ // Set state to fully populated data
450
+ diags := setMetricsRetentions (ctx , & resp .State , & model )
451
+ resp .Diagnostics .Append (diags ... )
452
+ if resp .Diagnostics .HasError () {
453
+ return
454
+ }
447
455
}
448
456
449
- // Set state to fully populated data
450
- diags = setMetricsRetentions (ctx , & resp .State , & model )
451
- resp .Diagnostics .Append (diags ... )
452
- if resp .Diagnostics .HasError () {
453
- return
454
- }
457
+ // There are plans where no alert matchers and receivers are present e.g. like Observability-Metrics-Endpoint-100k-EU01
458
+ if plan .GetAlertMatchers () != 0 && plan .GetAlertReceivers () != 0 {
459
+ alertConfigResp , err := d .client .GetAlertConfigs (ctx , instanceId , projectId ).Execute ()
460
+ if err != nil {
461
+ core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading instance" , fmt .Sprintf ("Calling API to get alert config: %v" , err ))
462
+ return
463
+ }
464
+ // Map response body to schema
465
+ err = mapAlertConfigField (ctx , alertConfigResp , & model )
466
+ if err != nil {
467
+ core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Processing API response for the alert config: %v" , err ))
468
+ return
469
+ }
455
470
456
- err = mapAlertConfigField (ctx , alertConfigResp , & model )
457
- if err != nil {
458
- core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Processing API response for the alert config: %v" , err ))
459
- return
471
+ // Set state to fully populated data
472
+ diags = setAlertConfig (ctx , & resp .State , & model )
473
+ resp .Diagnostics .Append (diags ... )
474
+ if resp .Diagnostics .HasError () {
475
+ return
476
+ }
460
477
}
461
478
462
- // Set state to fully populated data
463
- diags = setAlertConfig (ctx , & resp .State , & model )
464
- resp .Diagnostics .Append (diags ... )
465
- if resp .Diagnostics .HasError () {
466
- return
467
- }
468
479
tflog .Info (ctx , "Observability instance read" )
469
480
}
0 commit comments