terraform-provider-http
terraform-provider-http copied to clipboard
Enable http data source to accept binary data
Terraform CLI and Provider Versions
$ terraform version
Terraform v1.1.8
on darwin_amd64
provider "registry.terraform.io/hashicorp/http" {
version = "2.2.0"
}
Use Cases or Problem Statement
HTTP data sources can be used to download externally provided tools and binary data. For example, to manage a Kubernetes cluster, you can obtain the same version of the kubectl command as the cluster as follows
data "http" "kubectl" {
url = "https://storage.googleapis.com/kubernetes-release/release/v1.24.0/bin/darwin/amd64/kubectl"
}
However, current HTTP data sources expect response data to be text data, and dumping response data, for example, as shown below, will produce corrupted data.
resource "local_sensitive_file" "kubectl" {
filename = "${path.module}/kubectl"
content_base64 = base64encode(data.http.kubectl.response_body)
file_permission = "0755"
}
Proposal
Add the base64_response_body read-only attribute, which is mainly intended for binary data.
When reading values through this attribute, the provider is not aware of the content, but treats it only as an octet-stream.
The result is encoded in base64 format for safe handling as a string in Terraform.
Example
data "http" "kubectl" {
url = "https://storage.googleapis.com/kubernetes-release/release/v1.24.0/bin/darwin/amd64/kubectl"
}
resource "local_sensitive_file" "kubectl" {
filename = "${path.module}/kubectl"
content_base64 = data.http.kubectl.base64_response_body
file_permission = "0755"
}
How much impact is this issue causing?
Medium
Additional Information
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct