Mastercard / terraform-provider-restapi

A terraform provider to manage objects in a RESTful API
Other
785 stars 215 forks source link

Headers in Provider Block Not Passed to GET Requests During `terraform refresh` and Subsequent `terraform plan` #271

Closed somnathpathak closed 1 week ago

somnathpathak commented 2 weeks 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.

Terrafrom log trace: B2415215-1583-4451-A927-BC5B8226ED22_1_201_a

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"]
}
somnathpathak commented 2 weeks ago

@DRuggeri Can you please help me out here.

somnathpathak commented 1 week ago

Identified and resolved the issue. Closing the ticket.