Closed somnathpathak closed 1 week ago
After running terraform apply, executing the terraform plan command sends a GET request to the resource's endpoint. However, this request does not include the headers defined in the provider block, causing a 401 Unauthorized error.
terraform apply
terraform plan
GET
401 Unauthorized
Terrafrom log trace:
Sample provider and restapi_object block:
provider "restapi" { debug = true uri = "https://test-tenant.api.ibm.com" create_returns_object = true write_returns_object = true headers = { "Authorization" = data.ibm_iam_auth_token.token_data.iam_access_token, "Content-Type" = "application/json", "IBM-API-Version" = formatdate("YYYY-MM-DD", timestamp()) } create_method = "POST" destroy_method = "DELETE" read_method = "GET" update_method = "PATCH" } resource "restapi_object" "create_tenant" { debug = true path = "/v1/tenants" data = "{\n \"name\": \"test-tenant\",\n \"targets\": [\n {\n \"name\": \"test-my-log-sink\",\n \"parameters\": {\n \"host\": \"${local.tenant_private_endpoint}\",\n \"port\": ${local.tenant_port},\n \"access_credential\": \"${local.tenant_secret_key}\"\n }\n }\n ]\n}" id_attribute = "id" force_new = ["id"] }
@DRuggeri Can you please help me out here.
Identified and resolved the issue. Closing the ticket.
After running
terraform apply
, executing theterraform plan
command sends aGET
request to the resource's endpoint. However, this request does not include the headers defined in the provider block, causing a401 Unauthorized
error.Terrafrom log trace:![B2415215-1583-4451-A927-BC5B8226ED22_1_201_a](https://github.com/Mastercard/terraform-provider-restapi/assets/6602586/60e414b2-9b3f-469c-91af-f28553bcb15e)
Sample provider and restapi_object block: