Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## [Unreleased]

### Changes

- Fix validation of `throttle`, and `interval` attributes in `elasticstack_kibana_alerting_rule` allowing all Elastic duration values ([#846](https://github.com/elastic/terraform-provider-elasticstack/pull/846))
- Fix boolean setting parsing for `elasticstack_elasticsearch_indices` data source. ([#842](https://github.com/elastic/terraform-provider-elasticstack/pull/842))

## [0.11.9] - 2024-10-14
Expand Down
11 changes: 11 additions & 0 deletions internal/fleet/integration_policy/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration_policy_test

import (
"context"
"encoding/json"
"fmt"
"regexp"
"testing"
Expand All @@ -12,13 +13,23 @@ import (
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/elastic/terraform-provider-elasticstack/internal/versionutils"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/stretchr/testify/require"
)

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

func TestJsonTypes(t *testing.T) {
mapBytes, err := json.Marshal(map[string]string{})
require.NoError(t, err)
equal, diags := jsontypes.NewNormalizedValue(`{"a": "b"}`).StringSemanticEquals(context.Background(), jsontypes.NewNormalizedValue(string(mapBytes)))
require.Empty(t, diags)
require.False(t, equal)
}

func TestAccResourceIntegrationPolicy(t *testing.T) {
policyName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)

Expand Down
15 changes: 12 additions & 3 deletions internal/kibana/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"regexp"
"strings"

"github.com/elastic/terraform-provider-elasticstack/internal/clients"
Expand All @@ -21,6 +22,14 @@ var frequencyMinSupportedVersion = version.Must(version.NewVersion("8.6.0"))
var alertsFilterMinSupportedVersion = version.Must(version.NewVersion("8.9.0"))
var alertDelayMinSupportedVersion = version.Must(version.NewVersion("8.13.0"))

// Avoid lint error on deprecated SchemaValidateFunc usage.
//
//nolint:staticcheck
func stringIsAlertingDuration() schema.SchemaValidateFunc {
r := regexp.MustCompile(`^[1-9][0-9]*(?:d|h|m|s)$`)
return validation.StringMatch(r, "string is not a valid Alerting duration in seconds (s), minutes (m), hours (h), or days (d)")
}

func ResourceAlertingRule() *schema.Resource {
apikeySchema := map[string]*schema.Schema{
"rule_id": {
Expand Down Expand Up @@ -71,7 +80,7 @@ func ResourceAlertingRule() *schema.Resource {
Description: "The check interval, which specifies how frequently the rule conditions are checked. The interval must be specified in seconds, minutes, hours or days.",
Type: schema.TypeString,
Required: true,
ValidateFunc: utils.StringIsDuration,
ValidateFunc: stringIsAlertingDuration(),
},
"actions": {
Description: "An action that runs under defined conditions.",
Expand Down Expand Up @@ -120,7 +129,7 @@ func ResourceAlertingRule() *schema.Resource {
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.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: utils.StringIsDuration,
ValidateFunc: stringIsAlertingDuration(),
},
},
},
Expand Down Expand Up @@ -198,7 +207,7 @@ func ResourceAlertingRule() *schema.Resource {
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.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: utils.StringIsDuration,
ValidateFunc: stringIsAlertingDuration(),
},
"scheduled_task_id": {
Description: "ID of the scheduled task that will execute the alert.",
Expand Down
8 changes: 4 additions & 4 deletions internal/kibana/alerting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestAccResourceAlertingRule(t *testing.T) {
resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "consumer", "alerts"),
resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "notify_when", "onActiveAlert"),
resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "rule_type_id", ".index-threshold"),
resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "interval", "10m"),
resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "interval", "1d"),
resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "enabled", "false"),
resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "tags.0", "first"),
resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "tags.1", "second"),
Expand Down Expand Up @@ -244,7 +244,7 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
termField = "name"
})
rule_type_id = ".index-threshold"
interval = "10m"
interval = "1d"
enabled = false
tags = ["first", "second"]
}
Expand Down Expand Up @@ -439,7 +439,7 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
days = [1,2,3]
timezone = "Africa/Accra"
hours_start = "01:00"
hours_end = "07:00"
hours_end = "07:00"
}
}
}
Expand Down Expand Up @@ -514,7 +514,7 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
days = [7]
timezone = "Pacific/Honolulu"
hours_start = "02:00"
hours_end = "03:00"
hours_end = "03:00"
}
}
}
Expand Down
Loading