Skip to content

Commit c473560

Browse files
authored
feat(observability): Min/Max acceptance tests (#805)
Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent ab99821 commit c473560

6 files changed

Lines changed: 930 additions & 776 deletions

File tree

stackit/internal/services/observability/alertgroup/resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func (a *alertGroupResource) Schema(_ context.Context, _ resource.SchemaRequest,
175175
"interval": schema.StringAttribute{
176176
Description: descriptions["interval"],
177177
Optional: true,
178+
Computed: true,
178179
Validators: []validator.String{
179180
validate.ValidDurationString(),
180181
},

stackit/internal/services/observability/instance/datasource.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ func (d *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
409409
return
410410
}
411411

412+
metricsRetentionResp, err := d.client.GetMetricsStorageRetention(ctx, instanceId, projectId).Execute()
413+
if err != nil {
414+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Calling API to get metrics retention: %v", err))
415+
return
416+
}
417+
412418
alertConfigResp, err := d.client.GetAlertConfigs(ctx, instanceId, projectId).Execute()
413419
if err != nil {
414420
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Calling API to get alert config: %v", err))
@@ -421,18 +427,49 @@ func (d *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
421427
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API payload: %v", err))
422428
return
423429
}
430+
431+
// Set state to instance populated data
432+
diags = resp.State.Set(ctx, model)
433+
resp.Diagnostics.Append(diags...)
434+
if resp.Diagnostics.HasError() {
435+
return
436+
}
437+
424438
err = mapACLField(aclListResp, &model)
425439
if err != nil {
426440
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API response for the ACL: %v", err))
427441
return
428442
}
443+
444+
// Set state to fully populated data
445+
diags = setACL(ctx, &resp.State, &model)
446+
resp.Diagnostics.Append(diags...)
447+
if resp.Diagnostics.HasError() {
448+
return
449+
}
450+
451+
// Map response body to schema
452+
err = mapMetricsRetentionField(metricsRetentionResp, &model)
453+
if err != nil {
454+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API response for the metrics retention: %v", err))
455+
return
456+
}
457+
458+
// Set state to fully populated data
459+
diags = setMetricsRetentions(ctx, &resp.State, &model)
460+
resp.Diagnostics.Append(diags...)
461+
if resp.Diagnostics.HasError() {
462+
return
463+
}
464+
429465
err = mapAlertConfigField(ctx, alertConfigResp, &model)
430466
if err != nil {
431467
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Processing API response for the alert config: %v", err))
432468
return
433469
}
434470

435-
diags = resp.State.Set(ctx, model)
471+
// Set state to fully populated data
472+
diags = setAlertConfig(ctx, &resp.State, &model)
436473
resp.Diagnostics.Append(diags...)
437474
if resp.Diagnostics.HasError() {
438475
return

stackit/internal/services/observability/log-alertgroup/resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func (l *logAlertGroupResource) Schema(_ context.Context, _ resource.SchemaReque
175175
"interval": schema.StringAttribute{
176176
Description: descriptions["interval"],
177177
Optional: true,
178+
Computed: true,
178179
Validators: []validator.String{
179180
validate.ValidDurationString(),
180181
},

0 commit comments

Comments
 (0)