Skip to content
Open
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
7 changes: 7 additions & 0 deletions splunk/resource_splunk_indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ func indexRead(d *schema.ResourceData, meta interface{}) error {
}

if entry == nil {
if !d.IsNewResource() {
// This probably means someone has deleted the index from Splunk directly. Setting empty id here to
// force Terraform to delete resource from state and thereby recreating it
d.SetId("")

return nil
}
return fmt.Errorf("Unable to find resource: %s", name)
}

Expand Down
8 changes: 8 additions & 0 deletions splunk/resource_splunk_indexes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func TestAccCreateSplunkIndex(t *testing.T) {
),
},
{
// to test re-creation of remotely deleted or missing resources, delete the new index before updating it
PreConfig: func() {
client, _ := newTestClient()

if _, err := client.DeleteIndexObject("new-index", "nobody", "system"); err != nil {
t.Error("PreConfig deletion of new-index failed")
}
},
Config: updateIndex,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "max_time_unreplicated_no_acks", "301"),
Expand Down
13 changes: 10 additions & 3 deletions splunk/resource_splunk_saved_searches.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func savedSearches() *schema.Resource {
"4 - Warning",
},
"action_snow_event_param_description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: " A brief description of the event.",
},
"action_snow_event_param_ci_identifier": {
Expand Down Expand Up @@ -1152,6 +1152,13 @@ func savedSearchesRead(d *schema.ResourceData, meta interface{}) error {
}

if entry == nil {
if !d.IsNewResource() {
// This probably means someone has deleted the saved search from Splunk directly. Setting empty id here to
// force Terraform to delete resource from state and thereby recreating it
d.SetId("")

return nil
}
return fmt.Errorf("Unable to find resource: %v", name)
}

Expand Down
8 changes: 8 additions & 0 deletions splunk/resource_splunk_saved_searches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ func TestAccSplunkSavedSearches(t *testing.T) {
),
},
{
// to test re-creation of remotely deleted or missing resources, delete the new saved serarch before updating it
PreConfig: func() {
client, _ := newTestClient()

if _, err := client.DeleteSavedSearches("Test New Alert", "nobody", "search"); err != nil {
t.Error("PreConfig deletion of Test New Alert failed")
}
},
Config: updatedSavedSearches,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", "Test New Alert"),
Expand Down