Skip to content

Commit 732cc1e

Browse files
committed
WIP
1 parent f46c2fe commit 732cc1e

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed

internal/elasticsearch/ml/anomaly_detector/acc_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ func TestAccResourceAnomalyDetectorJob(t *testing.T) {
5959
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "model_plot_config.enabled", "true"),
6060
// Other settings checks
6161
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "allow_lazy_open", "true"),
62+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "background_persist_interval", "1h"),
63+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "custom_settings", "{\"custom_key\": \"custom_value\"}"),
64+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "daily_model_snapshot_retention_after_days", "3"),
6265
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "model_snapshot_retention_days", "7"),
66+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "renormalization_window_days", "14"),
6367
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "results_retention_days", "30"),
6468
// Computed fields
6569
resource.TestCheckResourceAttrSet("elasticstack_elasticsearch_ml_anomaly_detector.test", "create_time"),
@@ -73,6 +77,17 @@ func TestAccResourceAnomalyDetectorJob(t *testing.T) {
7377
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "job_id", jobID),
7478
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "description", "Updated test anomaly detection job"),
7579
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "groups.#", "1"),
80+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "groups.0", "test-group"),
81+
// Verify that updatable fields were actually updated
82+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "analysis_limits.model_memory_limit", "200mb"),
83+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "model_plot_config.enabled", "false"),
84+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "allow_lazy_open", "false"),
85+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "background_persist_interval", "2h"),
86+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "custom_settings", "{\"updated_key\": \"updated_value\"}"),
87+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "daily_model_snapshot_retention_after_days", "5"),
88+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "model_snapshot_retention_days", "14"),
89+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "renormalization_window_days", "30"),
90+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_ml_anomaly_detector.test", "results_retention_days", "60"),
7691
),
7792
},
7893
},
@@ -159,7 +174,11 @@ resource "elasticstack_elasticsearch_ml_anomaly_detector" "test" {
159174
}
160175
161176
allow_lazy_open = true
177+
background_persist_interval = "1h"
178+
custom_settings = "{\"custom_key\": \"custom_value\"}"
179+
daily_model_snapshot_retention_after_days = 3
162180
model_snapshot_retention_days = 7
181+
renormalization_window_days = 14
163182
results_retention_days = 30
164183
}
165184
`, jobID, jobID)
@@ -191,6 +210,23 @@ resource "elasticstack_elasticsearch_ml_anomaly_detector" "test" {
191210
}
192211
193212
groups = ["test-group"]
213+
214+
# Test updating some of the other updatable fields
215+
analysis_limits = {
216+
model_memory_limit = "200mb"
217+
}
218+
219+
model_plot_config = {
220+
enabled = false
221+
}
222+
223+
allow_lazy_open = false
224+
background_persist_interval = "2h"
225+
custom_settings = "{\"updated_key\": \"updated_value\"}"
226+
daily_model_snapshot_retention_after_days = 5
227+
model_snapshot_retention_days = 14
228+
renormalization_window_days = 30
229+
results_retention_days = 60
194230
}
195231
`, jobID)
196232
}

internal/elasticsearch/ml/anomaly_detector/models_tf.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ import (
1515

1616
// AnomalyDetectorJobTFModel represents the Terraform resource model for ML anomaly detection jobs
1717
type AnomalyDetectorJobTFModel struct {
18-
ID types.String `tfsdk:"id"`
19-
ElasticsearchConnection types.List `tfsdk:"elasticsearch_connection"`
20-
JobID types.String `tfsdk:"job_id"`
21-
Description types.String `tfsdk:"description"`
22-
Groups types.Set `tfsdk:"groups"`
23-
AnalysisConfig types.Object `tfsdk:"analysis_config"`
24-
AnalysisLimits types.Object `tfsdk:"analysis_limits"`
25-
DataDescription types.Object `tfsdk:"data_description"`
26-
DatafeedConfig types.Object `tfsdk:"datafeed_config"`
27-
ModelPlotConfig types.Object `tfsdk:"model_plot_config"`
28-
AllowLazyOpen types.Bool `tfsdk:"allow_lazy_open"`
29-
BackgroundPersistInterval types.String `tfsdk:"background_persist_interval"`
30-
CustomSettings types.String `tfsdk:"custom_settings"`
31-
DailyModelSnapshotRetentionAfterDays types.Int64 `tfsdk:"daily_model_snapshot_retention_after_days"`
32-
ModelSnapshotRetentionDays types.Int64 `tfsdk:"model_snapshot_retention_days"`
33-
RenormalizationWindowDays types.Int64 `tfsdk:"renormalization_window_days"`
34-
ResultsIndexName types.String `tfsdk:"results_index_name"`
35-
ResultsRetentionDays types.Int64 `tfsdk:"results_retention_days"`
18+
ID types.String `tfsdk:"id"`
19+
ElasticsearchConnection types.List `tfsdk:"elasticsearch_connection"`
20+
JobID types.String `tfsdk:"job_id"`
21+
Description types.String `tfsdk:"description"`
22+
Groups types.Set `tfsdk:"groups"`
23+
AnalysisConfig types.Object `tfsdk:"analysis_config"`
24+
AnalysisLimits types.Object `tfsdk:"analysis_limits"`
25+
DataDescription types.Object `tfsdk:"data_description"`
26+
DatafeedConfig types.Object `tfsdk:"datafeed_config"`
27+
ModelPlotConfig types.Object `tfsdk:"model_plot_config"`
28+
AllowLazyOpen types.Bool `tfsdk:"allow_lazy_open"`
29+
BackgroundPersistInterval types.String `tfsdk:"background_persist_interval"`
30+
CustomSettings jsontypes.Normalized `tfsdk:"custom_settings"`
31+
DailyModelSnapshotRetentionAfterDays types.Int64 `tfsdk:"daily_model_snapshot_retention_after_days"`
32+
ModelSnapshotRetentionDays types.Int64 `tfsdk:"model_snapshot_retention_days"`
33+
RenormalizationWindowDays types.Int64 `tfsdk:"renormalization_window_days"`
34+
ResultsIndexName types.String `tfsdk:"results_index_name"`
35+
ResultsRetentionDays types.Int64 `tfsdk:"results_retention_days"`
3636

3737
// Read-only computed fields
3838
CreateTime types.String `tfsdk:"create_time"`
@@ -430,7 +430,9 @@ func (tfModel *AnomalyDetectorJobTFModel) fromAPIModel(ctx context.Context, apiM
430430
diags.AddError("Failed to marshal custom_settings", err.Error())
431431
return diags
432432
}
433-
tfModel.CustomSettings = types.StringValue(string(customSettingsJSON))
433+
tfModel.CustomSettings = jsontypes.NewNormalizedValue(string(customSettingsJSON))
434+
} else {
435+
tfModel.CustomSettings = jsontypes.NewNormalizedNull()
434436
}
435437

436438
if apiModel.DailyModelSnapshotRetentionAfterDays != nil {

internal/elasticsearch/ml/anomaly_detector/schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ func GetSchema() schema.Schema {
469469
"custom_settings": schema.StringAttribute{
470470
MarkdownDescription: "Advanced configuration option. Contains custom meta data about the job. For example, it can contain custom URL information.",
471471
Optional: true,
472+
CustomType: jsontypes.NormalizedType{},
472473
},
473474
"daily_model_snapshot_retention_after_days": schema.Int64Attribute{
474475
MarkdownDescription: "Advanced configuration option, which affects the automatic removal of old model snapshots for this job.",

0 commit comments

Comments
 (0)