Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making it a Go package #427

Closed
1 task done
zliang-akamai opened this issue May 29, 2024 · 1 comment
Closed
1 task done

Making it a Go package #427

zliang-akamai opened this issue May 29, 2024 · 1 comment

Comments

@zliang-akamai
Copy link

zliang-akamai commented May 29, 2024

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

  • I agree to follow this project's Code of Conduct
@bflad
Copy link
Contributor

bflad commented May 29, 2024

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:

  • Go module code implies having a stable, exported API. The Go code for many providers is not designed or implemented with external Go code consumers in mind.
  • Versioning of the code/providers is intentionally in terms of Terraform configuration compatibility, not Go compatibility. Version changes for Terraform configurations may not result in any actual changes for hypothetically released Go packages and vice-versa.
  • Generic Go module consumers potentially have much broader customization needs and varying use cases than the Terraform implementation of the code.

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.

@bflad bflad closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants