From 64830b4d78277fd813e6e019a634884eb735d2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20P=C5=82oski?= Date: Wed, 6 Nov 2024 15:26:18 +0100 Subject: [PATCH] Fix wrong mapping from string to int of returned input script config --- client/models/inputs_script.go | 17 ++++++++++++++--- splunk/resource_splunk_inputs_script.go | 13 ++++++++++--- splunk/resource_splunk_inputs_script_test.go | 5 +++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/client/models/inputs_script.go b/client/models/inputs_script.go index 370fe771..510ba02a 100644 --- a/client/models/inputs_script.go +++ b/client/models/inputs_script.go @@ -7,9 +7,9 @@ type InputsScriptResponse struct { } type InputsScriptEntry struct { - Name string `json:"name"` - ACL ACLObject `json:"acl"` - Content InputsScriptObject `json:"content"` + Name string `json:"name"` + ACL ACLObject `json:"acl"` + Content InputsScriptObjectResponse `json:"content"` } type InputsScriptObject struct { @@ -22,3 +22,14 @@ type InputsScriptObject struct { Disabled bool `json:"disabled,omitempty" url:"disabled"` Interval int `json:"interval,omitempty" url:"interval,omitempty"` } + +type InputsScriptObjectResponse struct { + Host string `json:"host,omitempty"` + Index string `json:"index,omitempty"` + Source string `json:"source,omitempty"` + SourceType string `json:"sourcetype,omitempty"` + RenameSource string `json:"rename-source,omitempty"` + PassAuth string `json:"passAuth,omitempty"` + Disabled bool `json:"disabled,omitempty"` + Interval interface{} `json:"interval,omitempty"` // Can be int or string +} diff --git a/splunk/resource_splunk_inputs_script.go b/splunk/resource_splunk_inputs_script.go index 18204993..f6e4af67 100644 --- a/splunk/resource_splunk_inputs_script.go +++ b/splunk/resource_splunk_inputs_script.go @@ -4,11 +4,12 @@ import ( "encoding/json" "errors" "fmt" - "github.com/splunk/terraform-provider-splunk/client/models" "net/http" "net/url" "regexp" + "github.com/splunk/terraform-provider-splunk/client/models" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) @@ -68,7 +69,7 @@ func inputsScript() *schema.Resource { Type: schema.TypeInt, Required: true, ValidateFunc: validation.IntAtLeast(60), - Description: "Specify an integer or cron schedule. This parameter specifies how often to execute the specified script, in seconds or a valid cron schedule. If you specify a cron schedule, the script is not executed on start-up.", + Description: "Specify an integer. This parameter specifies how often to execute the specified script, in seconds. Cron schedule is not supported", }, "acl": aclSchema(), }, @@ -138,6 +139,7 @@ func inputsScriptRead(d *schema.ResourceData, meta interface{}) error { defer resp.Body.Close() entry, err = getScriptedInputsConfigByName(name, resp) + if err != nil { return err } @@ -170,7 +172,12 @@ func inputsScriptRead(d *schema.ResourceData, meta interface{}) error { return err } - if err = d.Set("interval", entry.Content.Interval); err != nil { + interval, ok := entry.Content.Interval.(float64) + if !ok { + fmt.Print(ok) + return err + } + if err = d.Set("interval", int(interval)); err != nil { return err } diff --git a/splunk/resource_splunk_inputs_script_test.go b/splunk/resource_splunk_inputs_script_test.go index 8cd3f1b5..6e9f829b 100644 --- a/splunk/resource_splunk_inputs_script_test.go +++ b/splunk/resource_splunk_inputs_script_test.go @@ -2,12 +2,13 @@ package splunk import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" "net/http" "os" "path/filepath" "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" ) const inputsScriptConfig = `