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

Add docs for ExternalProviders in TestCase #349

Open
zliang-akamai opened this issue May 29, 2024 · 2 comments
Open

Add docs for ExternalProviders in TestCase #349

zliang-akamai opened this issue May 29, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@zliang-akamai
Copy link

Use cases

There are some useful utility provider like null and http, which might be used in the acceptance tests of the another provider.

Attempted solutions

Importing those providers as Go packages and placing them into the provider factory. This doesn't work well because many providers doesn't follow Golang's package standard.

See this example: hashicorp/terraform-provider-http#428

Proposal

Maybe we can have a new field on Test struct to allow setup of other providers?

@zliang-akamai zliang-akamai added the enhancement New feature or request label May 29, 2024
@bflad bflad added documentation Improvements or additions to documentation and removed enhancement New feature or request labels May 29, 2024
@bflad
Copy link
Contributor

bflad commented May 29, 2024

Hi again, @zliang-akamai 👋 Looks like you already created the issue I alluded to creating over in hashicorp/terraform-provider-http#427. Thanks for that. 😄

For others benefit, this functionality does already exist in the terraform-plugin-testing Go module. I'll copy some of the verbiage described in that separate issue:

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 ...
		},
	},
})

This functionality can be used for any provider that is available to Terraform while the testing is running. Website documentation about this testing functionality does not appear to be too findable (if at all) though. Since this functionality does already exist, but the documentation is lacking, I have changed this feature request into a documentation request.

@zliang-akamai
Copy link
Author

@bflad Ah, thank you so much! Didn't realize that feature was already there.

@zliang-akamai zliang-akamai changed the title Allow Third-Party Providers in Provider Acceptance Testing Add docs for ExternalProviders in TestCase May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants