terraform-provider-http
terraform-provider-http copied to clipboard
Add ability to store/cache result in state to avoid "will be read during apply"
Terraform CLI and Provider Versions
Terraform v1.3.6 on linux_amd64
Use Cases or Problem Statement
The data source is always doing an HTTP request even if I know the source will not change unless I change the URL.
For example, I get a remote JSON file with some configuration, but this file is static and will not change. In the following example I'm using a file from a git repository, but this can also be some other static file that will not change. For example some static api like https://grafana.com/api/dashboards/9614/revisions/1/download.
locals {
nginx_ingress_version = "4.4.0"
}
# Fetching static JSON where the response_body will only change when I change the URL
data "http" "grafana_nginx_ingress_controller" {
request_headers = {
Accept = "application/json"
}
url = "https://raw.githubusercontent.com/kubernetes/ingress-nginx/helm-chart-${local.nginx_ingress_version}/deploy/grafana/dashboards/nginx.json"
lifecycle {
postcondition {
condition = contains([200], self.status_code)
error_message = "Error fetching Grafana Dashboard JSON file. Got HTTP Status code ${self.status_code}: ${self.response_body}"
}
}
}
The result from the above example is always:
Terraform will perform the following actions:
# data.http.grafana_nginx_ingress_controller will be read during apply
# (depends on a resource or a module with changes pending)
<= data "http" "grafana_nginx_ingress_controller" {
+ body = (known after apply)
+ id = (known after apply)
+ request_headers = {
+ "Accept" = "application/json"
}
+ response_body = (known after apply)
+ response_headers = (known after apply)
+ status_code = (known after apply)
+ url = "https://raw.githubusercontent.com/kubernetes/ingress-nginx/helm-chart-4.4.0/deploy/grafana/dashboards/nginx.json"
}
Even if the source data does not change and I've already applied that change. (because it is part of the "apply" phase. According to this (https://github.com/hashicorp/terraform/issues/25805#issuecomment-672071546) comment the data source should cache the result if the input does not change.
I understand why that is not happening here, but for some use cases it might be useful. (for example when using the above use case with a static API)
The reason why this poses an issue is when you're reviewing the plan and it gets filled with these kind of messages. It makes it harder to validate the plan and to see if anything that should not happen, happens. It also poses an impact on the resources that uses this data result, as commented in the following issue: https://github.com/hashicorp/terraform-provider-http/issues/101
Proposal
It would be good if there is some method to enable the caching of the result in the state unless the input configuration changes. By either some kind of a setting or by default (but that would mean a breaking change).
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