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

Add an option to not parse the body

Open azz opened this issue 6 years ago • 2 comments

It would be helpful to have a way to ignore the response body when it is binary and you only care about the headers. In addition, an option to change from GET to HEAD would be handy.

Affected Resource(s)

  • data.http

Terraform Configuration Files

data "http" "artifact" {
  url           = "https://example.com/artifact"
  response_body = false
  http_method   = "HEAD"
}

locals {
  hash = lookup(data.http.artifact.response_headers, "x-checksum-sha1", "")
  body = data.http.artifact.body # null
}

azz avatar Mar 26 '20 07:03 azz

Alternatively, a second resource http_head could be considered?

azz avatar Mar 26 '20 08:03 azz

yeah, I also would like an option to return arbitrary types and not parse. Or maybe just have a secondresponse type that is the b64encoded form of the response itself?

I started a PR for this but it gets a little odd to make it all back-compatible: in the snippet below if the allowed_content_types is not set set, the output data.http.ga.body is populated if it is set and isn't one of the printable types to return, the b64 encoded field data.http.ga.b64_std is set

i can file a PR if this is ok though (it does preserve back compatiblity but its odd to have a filed conditionally populated (eg, the 'body` field there woudn't be populated in the bit below

provider "http" {}

resource "random_id" "id" {
  byte_length = 4
  prefix      = "ts-"
}

variable "ga_id" {
  type = string
  default = "UA-1551170838-1"
}

variable "s_id" {
  type = string
  default = "https://cloud.google.com/solutions/gaming/minecraft-server"
}

data "http" ga {
  url = "https://www.google-analytics.com/collect?v=1&tid=${var.ga_id}&cid=${random_id.id.b64_url}&dp=${var.s_id}"
  allowed_content_types = ["image/jpg"]
}

output "ga_resp" {
  value = data.http.ga.b64_std
}

salrashid123 avatar Jul 27 '20 12:07 salrashid123

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar May 23 '24 15:05 github-actions[bot]