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
204 stars 112 forks source link

Making it a Go package #427

Closed zliang-akamai closed 3 months ago

zliang-akamai commented 3 months ago

Terraform CLI and Provider Versions

N/A

Use Cases or Problem Statement

Some other tools, especially providers or acceptance tests of a provider may utilize this provider as a Go package for various reasons.

Currently, terraform-provider-http doesn't work when importing it from another Golang project.

Proposal

Making it compatible with Go package system

How much impact is this issue causing?

High

Additional Information

No response

Code of Conduct

bflad commented 3 months ago

Hi @zliang-akamai 👋 Thank you for raising this.

HashiCorp intentionally does not release provider code in an externally usable Go module for a few reasons, including but not limited to:

Some of this is mentioned in the Terraform plugin development website documentation.

In the case of this provider's functionality and given that its code is source available, you could theoretically reverse engineer the HTTP client and transport implementation into a proper Go module, if that was desirable. This provider's code is configuring and using the Go module: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp.

Since you do mention provider acceptance testing though, you can configure the terraform-plugin-testing logic to use the hashicorp/http provider in acceptance tests by configuring helper/resource.TestCase.ExternalProviders or per-step with helper/resource.TestStep.ExternalProviders. This can be done alongside configuring the other provider-under-test fields to combine external provider usage with under-test provider usage. For example:

resource.Test(t, resource.TestCase{
    ExternalProviders: map[string]resource.ExternalProvider{
        "http": {
            Source: "hashicorp/http",
            Version: "3.4.2",
        },
    },
    // ... ProviderFactories, ProtoV5ProviderFactories, ProtoV6ProviderFactories, etc.
    Steps: []resource.TestStep{
        {
            Config: `
data "http" "test" {
  url = "..."
}

# ...
`,
            // ... other fields ...
        },
    },
})

Website documentation about this testing functionality does not appear to be too findable (if at all) though. I would suggest raising a documentation issue in the terraform-plugin-testing repository for that in particular, so those maintainers can be aware of the missing or hard to find content. I will however close this issue in this particular provider issue tracker though, since the stance of exporting the Go code for providers is not going to change. If you have further questions about how to acceptance test using the ExternalProviders functionality of the terraform-plugin-testing module, I would suggest creating a new topic in the Terraform Plugin Development section of HashiCorp Discuss where other developers could also help in addition to the few engineers that maintain this provider and the testing module.