terraform-provider-splunk
terraform-provider-splunk copied to clipboard
URL with path provides invalid port error
Configuring a URL with a PATH provides an error, for example:
provider "splunk" {
url = "https://hostname:443/some/path"
auth_token = var.splunk_auth_token
insecure_skip_verify = true
}
Provides the error:
> terraform apply
splunk_saved_searches.saved_search: Refreshing state... [id=Test New Alert]
╷
│ Error: parse "https://https:%2F%2Fhostname:443%2Fsome%2Fpath/servicesNS/-/-/saved/searches?count=-1&output_mode=json": invalid port ":443%2Fsome%2Fpath" after host
│
│ with splunk_saved_searches.saved_search,
│ on main.tf line 17, in resource "splunk_saved_searches" "saved_search":
│ 17: resource "splunk_saved_searches" "saved_search" {
│
try https://hostname:443/some/path -> hostname:443/some/path
I have a similar problem. In my organization splunk url looks like this <hostname>/observability/splunk
. I get the error:
Error: parse "https://<hostname>%2Fobservability%2Fsplunk/servicesNS/<irrelevant_url_part>": invalid URL escape "%2F"
I looked into the code and this is what I found:
url
is not parsed as URL but used as host
. Looks like when Provider is built, url
is passed to client.NewSplunkdClient
to build a new Client. So url
is assigned to Client.host
https://github.com/splunk/terraform-provider-splunk/blob/0cb4f0706dfc0dea10c5ec89fae192e98341a5db/splunk/provider.go#L125
When url.URL
is built, the BuildSplunkURL
method uses Client.host
as Host
. The method doesn't parse host and doesn't interpret the part after /
as Path
.
https://github.com/splunk/terraform-provider-splunk/blob/0cb4f0706dfc0dea10c5ec89fae192e98341a5db/client/client.go#L91
I am still getting error.
splunk_saved_searches.new-search-01: Creating... ╷ │ Error: parse "https://myURL%2Fen-US%2Fapp%2Fsearch/servicesNS/user01/search/saved/searches?count=-1&output_mode=json": invalid URL escape "%2F" │ │ with splunk_saved_searches.new-search-01, │ on main.tf line 15, in resource "splunk_saved_searches" "new-search-01": │ 15: resource "splunk_saved_searches" "new-search-01" {