Skip to content

Commit c26ef6b

Browse files
committed
PR feedback
1 parent 5405b81 commit c26ef6b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

internal/fleet/integration_policy/resource_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package integration_policy_test
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"regexp"
78
"testing"
@@ -12,13 +13,23 @@ import (
1213
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
1314
"github.com/elastic/terraform-provider-elasticstack/internal/versionutils"
1415
"github.com/hashicorp/go-version"
16+
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
1517
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1618
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1719
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
20+
"github.com/stretchr/testify/require"
1821
)
1922

2023
var minVersionIntegrationPolicy = version.Must(version.NewVersion("8.10.0"))
2124

25+
func TestJsonTypes(t *testing.T) {
26+
mapBytes, err := json.Marshal(map[string]string{})
27+
require.NoError(t, err)
28+
equal, diags := jsontypes.NewNormalizedValue(`{"a": "b"}`).StringSemanticEquals(context.Background(), jsontypes.NewNormalizedValue(string(mapBytes)))
29+
require.Empty(t, diags)
30+
require.False(t, equal)
31+
}
32+
2233
func TestAccResourceIntegrationPolicy(t *testing.T) {
2334
policyName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
2435

internal/kibana/alerting.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"regexp"
78
"strings"
89

910
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
@@ -21,6 +22,12 @@ var frequencyMinSupportedVersion = version.Must(version.NewVersion("8.6.0"))
2122
var alertsFilterMinSupportedVersion = version.Must(version.NewVersion("8.9.0"))
2223
var alertDelayMinSupportedVersion = version.Must(version.NewVersion("8.13.0"))
2324

25+
//nolint:staticcheck Avoid lint error on deprecated SchemaValidateFunc usage.
26+
func stringIsAlertingDuration() schema.SchemaValidateFunc {
27+
r := regexp.MustCompile(`^[0-9]+(?:\.[0-9]+)?(?:d|h|m|s)$`)
28+
return validation.StringMatch(r, "string is not a valid Alerting duration in seconds (s), minutes (m), hours (h), or days (d)")
29+
}
30+
2431
func ResourceAlertingRule() *schema.Resource {
2532
apikeySchema := map[string]*schema.Schema{
2633
"rule_id": {
@@ -71,7 +78,7 @@ func ResourceAlertingRule() *schema.Resource {
7178
Description: "The check interval, which specifies how frequently the rule conditions are checked. The interval must be specified in seconds, minutes, hours or days.",
7279
Type: schema.TypeString,
7380
Required: true,
74-
ValidateFunc: utils.StringIsElasticDuration,
81+
ValidateFunc: stringIsAlertingDuration(),
7582
},
7683
"actions": {
7784
Description: "An action that runs under defined conditions.",
@@ -120,7 +127,7 @@ func ResourceAlertingRule() *schema.Resource {
120127
Description: "Defines how often an alert generates repeated actions. This custom action interval must be specified in seconds, minutes, hours, or days. For example, 10m or 1h. This property is applicable only if `notify_when` is `onThrottleInterval`. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `throttle` values.",
121128
Type: schema.TypeString,
122129
Optional: true,
123-
ValidateFunc: utils.StringIsElasticDuration,
130+
ValidateFunc: stringIsAlertingDuration(),
124131
},
125132
},
126133
},
@@ -198,7 +205,7 @@ func ResourceAlertingRule() *schema.Resource {
198205
Description: "Deprecated in 8.13.0. Defines how often an alert generates repeated actions. This custom action interval must be specified in seconds, minutes, hours, or days. For example, 10m or 1h. This property is applicable only if `notify_when` is `onThrottleInterval`. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `throttle` values.",
199206
Type: schema.TypeString,
200207
Optional: true,
201-
ValidateFunc: utils.StringIsElasticDuration,
208+
ValidateFunc: stringIsAlertingDuration(),
202209
},
203210
"scheduled_task_id": {
204211
Description: "ID of the scheduled task that will execute the alert.",

0 commit comments

Comments
 (0)