mirror of https://github.com/hashicorp/terraform
For normal provider installation we want to associate each provider with a selected version number and find a suitable package for that version that conforms to the official hashes for that release. Those requirements are very onerous for a provider developer currently testing a not-yet-released build, though. To allow for that case this new CLI configuration feature allows overriding specific providers to refer to give local filesystem directories. Any provider overridden in this way is not subject to the usual restrictions about selected versions or checksum conformance, and activating an override won't cause any changes to the selections recorded in the lock file because it's intended to be a temporary setting for one developer only. This is, in a sense, a spiritual successor of an old capability we had to override specific plugins in the CLI configuration file. There were some vestiges of that left in the main package and CLI config package but nothing has actually been honoring them for several versions now and so this commit removes them to avoid confusion with the new mechanism.pull/26618/head
parent
98dc399062
commit
30204ecded
@ -0,0 +1,76 @@
|
||||
package e2etest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/e2e"
|
||||
)
|
||||
|
||||
// TestProviderDevOverrides is a test for the special dev_overrides setting
|
||||
// in the provider_installation section of the CLI configuration file, which
|
||||
// is our current answer to smoothing provider development by allowing
|
||||
// developers to opt out of the version number and checksum verification
|
||||
// we normally do, so they can just overwrite the same local executable
|
||||
// in-place to iterate faster.
|
||||
func TestProviderDevOverrides(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tf := e2e.NewBinary(terraformBin, "testdata/provider-dev-override")
|
||||
defer tf.Close()
|
||||
|
||||
// In order to do a decent end-to-end test for this case we will need a
|
||||
// real enough provider plugin to try to run and make sure we are able
|
||||
// to actually run it. For now we'll use the "test" provider for that,
|
||||
// because it happens to be in this repository and therefore allows
|
||||
// us to avoid drawing in anything external, but we might revisit this
|
||||
// strategy in future if other needs cause us to evolve the test
|
||||
// provider in a way that makes it less suitable for this particular test,
|
||||
// such as if it stops being buildable into an independent executable.
|
||||
providerExeDir := filepath.Join(tf.WorkDir(), "pkgdir")
|
||||
providerExePrefix := filepath.Join(providerExeDir, "terraform-provider-test_")
|
||||
providerExe := e2e.GoBuild("github.com/hashicorp/terraform/builtin/bins/provider-test", providerExePrefix)
|
||||
t.Logf("temporary provider executable is %s", providerExe)
|
||||
|
||||
err := ioutil.WriteFile(filepath.Join(tf.WorkDir(), "dev.tfrc"), []byte(fmt.Sprintf(`
|
||||
provider_installation {
|
||||
dev_overrides {
|
||||
"example.com/test/test" = %q
|
||||
}
|
||||
}
|
||||
`, providerExeDir)), os.ModePerm)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tf.AddEnv("TF_CLI_CONFIG_FILE=dev.tfrc")
|
||||
|
||||
stdout, stderr, err := tf.Run("providers")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s\n%s", err, stderr)
|
||||
}
|
||||
if got, want := stdout, `provider[example.com/test/test]`; !strings.Contains(got, want) {
|
||||
t.Errorf("configuration should depend on %s, but doesn't\n%s", want, got)
|
||||
}
|
||||
|
||||
// NOTE: We're intentionally not running "terraform init" here, because
|
||||
// dev overrides are always ready to use and don't need any special action
|
||||
// to "install" them. This test is mimicking the a happy path of going
|
||||
// directly from "go build" to validate/plan/apply without interacting
|
||||
// with any registries, mirrors, lock files, etc.
|
||||
stdout, stderr, err = tf.Run("validate")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s\n%s", err, stderr)
|
||||
}
|
||||
|
||||
if got, want := stdout, `The configuration is valid, but`; !strings.Contains(got, want) {
|
||||
t.Errorf("stdout doesn't include the success message\nwant: %s\n%s", want, got)
|
||||
}
|
||||
if got, want := stdout, `Provider development overrides are in effect`; !strings.Contains(got, want) {
|
||||
t.Errorf("stdout doesn't include the warning about development overrides\nwant: %s\n%s", want, got)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
This is where the test will place the temporary build of the test provider.
|
||||
@ -0,0 +1,14 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
test = {
|
||||
source = "example.com/test/test"
|
||||
version = "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "test" {
|
||||
}
|
||||
|
||||
data "test_data_source" "test" {
|
||||
}
|
||||
Loading…
Reference in new issue