hashicorp / terraform-provider-http

Utility provider for interacting with generic HTTP servers as part of a Terraform configuration.
https://registry.terraform.io/providers/hashicorp/http/latest
Mozilla Public License 2.0
206 stars 116 forks source link

Feature Request: Resource Object for POST/PUT Methods #241

Closed hikerspath closed 7 months ago

hikerspath commented 1 year ago

Terraform CLI and Provider Versions

0.12+

Use Cases or Problem Statement

So datasources are read during the 'Refreshing state' phase of both plan and apply so that the data that they are given is available through the remainder of the runtime. This prevents pushing configuration into API's only during an apply phase, to build / configure something for an API that has no provider.

Proposal

Creation of a resource type object that would afford the ability to interact with virtually ANY api through paths and variables to build a resource. Given that the resource would store the json outputs in the state file then configuration could be built for any API (not just those which have a first-class provider).

How much impact is this issue causing?

Medium

Additional Information

For instance, I run a grafana instance using the kubernetes provider. It would be super cool to have a resource based trigger that would trigger the reload URL:

// Possible clean re-load of a datasource change
// https://grafana.com/docs/grafana/v8.1/http_api/admin/#reload-provisioning-configurations
data "http" "config_reload" {
  url    = "https://grafana-poc.meltwater.io/api/admin/provisioning/datasources/reload"
  method = "POST"

  request_headers = {
    "x-config-sha" = sha256(jsonencode(kubernetes_config_map.grafana-config.data)),
    Accept = "application/json"
  }

  lifecycle {
    postcondition {
      condition = contains(["config reloaded"], data.http.config_reload.response_body)
      message   = "Invalid response given during reload: ${data.http.config_reload.response_body}..."
    }
  }
}

Unfortunately, while the above does "work" it triggers before any of the changes are applied and does not help interact with the changes to the config (even though I think we found a creative way of causing the resource to "change". This type of action can only be accomplished in a resource.

Code of Conduct

sean-freeman commented 8 months ago

Link this GH Issue to fix in PR #298

bendbennett commented 7 months ago

@hikerspath thank you for opening this issue.

As described in the responses to #298, the http data source, and more broadly, the scope of the http provider is intended to be limited to operations that do not perform any mutation. Consequently, introduction of a resource, which would allow mutation of the target would be outside of this scope. Unfortunately, this means that we are unable to consider your proposal at this time. Perhaps the restapi provider might prove to be a suitable alternative, as the restapi_object resource allows POST, GET, PUT and DELETE operations.

github-actions[bot] commented 4 months ago

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.