Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saved search update handler doesn't support schedule_priority #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

muang0
Copy link

@muang0 muang0 commented Mar 25, 2023

API requests to update saved searches don't actually update the saved search when the schedule_priority field is set. As a workaround we can remove this field from update requests & instead force new resource creation when this field is updated.

#2

@okaraev
Copy link

okaraev commented Apr 21, 2023

It happens when you don't have edit_schedule_priority permission. Even though you set it to "", it doesn't mean that provider will not send that key. As a workaround you can delete all keys you have problem with:
unnec := []string{
"auto_summarize.command",
"auto_summarize.cron_schedule",
"auto_summarize.dispatch.time_format",
"auto_summarize.dispatch.ttl",
"auto_summarize.max_disabled_buckets",
"auto_summarize.max_summary_ratio",
"auto_summarize.max_summary_size",
"auto_summarize.suspend_period",
"schedule_priority",
"action.webhook.param.url",
}
for _, item := range unnec {
values.Del(item)
}

But for the solution provider must compare changes, and put only changed values.

@muang0
Copy link
Author

muang0 commented Apr 21, 2023

Setting the value to an empty string + json:omitempty on that struct field should keep the provider from including that field in the request. Permissions issue being the root cause makes sense, but I'm surprised the error didn't indicate that there was a permissions issue if that is the case. Do you have any thoughts on the associated issue?

@okaraev
Copy link

okaraev commented Apr 23, 2023

Yes, you're right for that point. My problem was about another field, and when I used your changes it didn't work for me, and because there is no error from terraform apply I couldn't figure out the actual problem. I changed UpdateSavedSearches function to use changes as an argument

func (client *Client) UpdateSavedSearches(name string, owner string, app string, changes map[string]interface{}) error {
	endpoint := client.BuildSplunkURL(nil, "servicesNS", owner, app, "saved", "searches", name)
	resp, err := client.Post(endpoint, changes)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	return nil
}

And used schema.ResourceData.HasChange function to check if there is a change for each field and generate all the changed fields.
There is no error in the terraform apply output because the provider doesn't check the response from the api server. It should check the response status code and body for error message

resp, err := client.Post(endpoint, values)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants