profile
viewpoint

Ask questionsGetting 401 even though credentials are provided

I'm trying to POST a request using basic auth with the following:

terraform {
  required_providers {
    restapi = {
      source = "fmontezuma/restapi"
      version = "1.14.1"
    }
  }
}

provider "restapi" {
  uri = "http://test.com"
  headers = {
    "Authorization": "Basic abc"
  }
  debug = true
  write_returns_object = true
}

resource "restapi_object" "mapping" {
  path = "/elastic/_mapping/"
  data = file("${path.module}/mapping.json")
}

Unfortunately I'm getting the following error:

Error: Unexpected response code '401': {"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/elastic/_mapping/]","header":{"WWW-Authenticate":["Bearer realm=\"security\"","
ApiKey","Basic realm=\"security\" charset=\"UTF-8\""]}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/elastic/_mapping/]","header":{"WWW-Authenticate":["Bearer realm=\"security\"","ApiKey"
,"Basic realm=\"security\" charset=\"UTF-8\""]}},"status":401}

Any idea what I might be doing wrong?

I've also tried with the following but getting the same error:

provider "restapi" {
  uri = "http://test.com"
  username = "test"
  password = "test"
  debug = true
  write_returns_object = true
}
Mastercard/terraform-provider-restapi

Answer questions nadworny

Ok I think the problem is that on http I'm getting redirect to https and then the basic auth header won't be propagated? Would that be a possible root cause? Is there a possibility to add pem certificate to the command?

useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List