terraform-provider-terracurl icon indicating copy to clipboard operation
terraform-provider-terracurl copied to clipboard

Ability to override the Host with request headers

Open niroz89 opened this issue 8 months ago • 0 comments

Terraform Version

Terraform v1.7.0

Terracurl does not provide an option to override the Host using Host header, similar to curl.

Terraform Configuration Files

data "terracurl_request" "home" {
    name   = "home"
    url    = "https://d2mxderzerczer.cloudfront.net"
    method = "GET"

    headers = {
      "Host"               = "www.example.com"
    }

    response_codes = [
      200,
    ]
    max_retry      = 1
    retry_interval = 3
  }

Origin has host header checks and return 400 Bad request if wrong host is provided.

Expected Behavior

Since the header overrides Host with correct value, should return 200.

Actual Behavior

Returns 400.

Use case

My use case is, I'm adding an end to end test using terraform checks to validate the response codes and headers.

check "home_page" {
  data "terracurl_request" "home" {
    name   = "home"
    url    = "https://d2mxderzerczer.cloudfront.net"
    method = "GET"

    headers = {
      "Host"               = "www.example.com"
    }

    response_codes = [
      200,
    ]
    max_retry      = 1
    retry_interval = 3
  }

  assert {
    condition     = data.terracurl_request.home.status_code == 200
    error_message = "${data.terracurl_request.home.url} returned an unhealthy status code"
  }
}

References

This issue is similar to the http provider issue. https://github.com/hashicorp/terraform-provider-http/issues/311

niroz89 avatar Jun 23 '24 14:06 niroz89