Skip to content

Commit e2f6442

Browse files
fix 0 values for save search params (#221)
* add test for 0 values of action_email parameters * also fix tests so optional run lookup file tests
1 parent 7bc74fb commit e2f6442

File tree

6 files changed

+79
-4
lines changed

6 files changed

+79
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.4.36
2+
* Fix: saved search action_email_include_results_link handles 0 value
3+
* Fix: saved search action_email_include_view_link handles 0 value
4+
15
## 1.4.35
26
* Fix: lookup_table_file - handle nil values in file_contents by converting to empty strings before JSON marshaling
37
* Fix: lookup_table_file - properly URL-encode form parameters in Create/Read/Update operations

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ fmt:
2121
build:
2222
go build -o terraform-provider-splunk .
2323

24+
# Use external linker on macOS to avoid dyld "missing LC_UUID" abort (macOS 15+).
25+
# TF_ACC= ensures acceptance tests are skipped (no API required).
2426
test:
25-
go test ./...
27+
TF_ACC= go test -ldflags="-linkmode=external" ./...
2628

2729
testacc:
28-
TF_ACC=1 go test ./... -v
30+
TF_ACC=1 go test -ldflags="-linkmode=external" ./... -v
2931

3032
init:
3133
@terraform init

client/models/saved_searches.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ type SavedSearchObject struct {
2222
ActionEmailFormat string `json:"action.email.format,omitempty" url:"action.email.format,omitempty"`
2323
ActionEmailFrom string `json:"action.email.from,omitempty" url:"action.email.from,omitempty"`
2424
ActionEmailHostname string `json:"action.email.hostname,omitempty" url:"action.email.hostname,omitempty"`
25-
ActionEmailIncludeResultsLink int `json:"action.email.include.results_link,string,omitempty" url:"action.email.include.results_link,omitempty"`
25+
ActionEmailIncludeResultsLink int `json:"action.email.include.results_link,string,omitempty" url:"action.email.include.results_link"`
2626
ActionEmailIncludeSearch int `json:"action.email.include.search,string,omitempty" url:"action.email.include.search,omitempty"`
2727
ActionEmailIncludeTrigger int `json:"action.email.include.trigger,string,omitempty" url:"action.email.include.trigger,omitempty"`
2828
ActionEmailIncludeTriggerTime int `json:"action.email.include.trigger_time,string,omitempty" url:"action.email.include.trigger_time,omitempty"`
29-
ActionEmailIncludeViewLink int `json:"action.email.include.view_link,string,omitempty" url:"action.email.include.view_link,omitempty"`
29+
ActionEmailIncludeViewLink int `json:"action.email.include.view_link,string,omitempty" url:"action.email.include.view_link"`
3030
ActionEmailInline bool `json:"action.email.inline" url:"action.email.inline"`
3131
ActionEmailMailserver string `json:"action.email.mailserver,omitempty" url:"action.email.mailserver,omitempty"`
3232
ActionEmailMaxResults int `json:"action.email.maxresults,omitempty" url:"action.email.maxresults,omitempty"`

docs/resources/lookup_table_file.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Resource: splunk_lookup_table_file
22
Create and manage lookup table files.
33

4+
## Requirements
5+
This resource uses the Splunk `data/lookup_edit` REST API to create and update lookup file contents. That API is not part of core Splunk Enterprise; it is typically provided by the **Splunk App for Lookup File Editing** (Lookup Editor app). If the API is not available, the provider will receive 404 errors. Install the app on your Splunk instance if you need to manage lookup table file contents with Terraform.
6+
47
## Example Usage
58
```
69
resource "splunk_lookup_table_file" "lookup_table_file" {

splunk/resource_splunk_lookup_table_file_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package splunk
33
import (
44
"fmt"
55
"net/http"
6+
"os"
67
"testing"
78

89
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -37,6 +38,13 @@ resource "splunk_lookup_table_file" "test" {
3738
`
3839

3940
func TestAccSplunkLookupTableFile(t *testing.T) {
41+
// The splunk_lookup_table_file resource uses the lookup_edit API (e.g. from the
42+
// Splunk App for Lookup File Editing), which is not part of core Splunk. If that
43+
// API is not available, the provider gets 404. Skip this test unless the env var
44+
// is set so CI and default runs do not fail.
45+
if os.Getenv("SPLUNK_TEST_LOOKUP_TABLE_FILE") == "" {
46+
t.Skip("Skipping lookup table file test; set SPLUNK_TEST_LOOKUP_TABLE_FILE=1 when Splunk has the Lookup File Editing API available (e.g. Splunk App for Lookup File Editing installed)")
47+
}
4048
resourceName := "splunk_lookup_table_file.test"
4149
resource.Test(t, resource.TestCase{
4250
PreCheck: func() {

splunk/resource_splunk_saved_searches_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,40 @@ resource "splunk_saved_searches" "test" {
9797
}
9898
}
9999
`
100+
101+
// savedSearchesEmailIncludeLinksZero sets action_email_include_results_link and
102+
// action_email_include_view_link to 0 to verify they are sent to the API and
103+
// returned on read (and thus appear in savedsearches.conf).
104+
const savedSearchesEmailIncludeLinksZero = `
105+
resource "splunk_saved_searches" "test" {
106+
name = "Test Email Include Links Zero"
107+
search = "index=main"
108+
actions = "email"
109+
action_email_include_results_link = 0
110+
action_email_include_view_link = 0
111+
action_email_include_search = 0
112+
action_email_include_trigger = 1
113+
action_email_format = "table"
114+
action_email_max_time = "5m"
115+
action_email_max_results = 10
116+
action_email_send_csv = 1
117+
action_email_send_results = false
118+
action_email_subject = "Splunk Alert: $name$"
119+
action_email_to = "splunk@splunk.com"
120+
action_email_track_alert = true
121+
alert_track = true
122+
dispatch_earliest_time = "rt-15m"
123+
dispatch_latest_time = "rt-0m"
124+
dispatch_index_earliest = "-10m"
125+
dispatch_index_latest = "-5m"
126+
cron_schedule = "*/5 * * * *"
127+
acl {
128+
owner = "admin"
129+
sharing = "app"
130+
app = "launcher"
131+
}
132+
}
133+
`
100134
const newSavedSearchesLogEvent = `
101135
resource "splunk_saved_searches" "test" {
102136
name = "Test Log Event Alert"
@@ -742,6 +776,30 @@ func TestAccSplunkSavedSearches(t *testing.T) {
742776
})
743777
}
744778

779+
// TestAccSplunkSavedSearchesEmailIncludeLinksZero verifies that setting
780+
// action_email_include_results_link and action_email_include_view_link to 0
781+
// sends them to the API and they are returned on read (and appear in savedsearches.conf).
782+
func TestAccSplunkSavedSearchesEmailIncludeLinksZero(t *testing.T) {
783+
resourceName := "splunk_saved_searches.test"
784+
resource.Test(t, resource.TestCase{
785+
PreCheck: func() {
786+
testAccPreCheck(t)
787+
},
788+
Providers: testAccProviders,
789+
CheckDestroy: testAccSplunkSavedSearchesDestroyResources,
790+
Steps: []resource.TestStep{
791+
{
792+
Config: savedSearchesEmailIncludeLinksZero,
793+
Check: resource.ComposeTestCheckFunc(
794+
resource.TestCheckResourceAttr(resourceName, "name", "Test Email Include Links Zero"),
795+
resource.TestCheckResourceAttr(resourceName, "action_email_include_results_link", "0"),
796+
resource.TestCheckResourceAttr(resourceName, "action_email_include_view_link", "0"),
797+
),
798+
},
799+
},
800+
})
801+
}
802+
745803
func testAccSplunkSavedSearchesDestroyResources(s *terraform.State) error {
746804
client, err := newTestClient()
747805
if err != nil {

0 commit comments

Comments
 (0)