mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-01 11:47:07 -06:00
7b7273e3aa
* Add support for plugin protocol v6 This PR turns on support for plugin protocol v6. A provider can advertise itself as supporting protocol version 6 and terraform will use the correct client. Todo: The "unmanaged" providers functionality does not support protocol version, so at the moment terraform will continue to assume that "unmanaged" providers are on protocol v5. This will require some upstream work on go-plugin (I believe). I would like to convert the builtin providers to use protocol v6 in a future PR; however it is not necessary until we remove protocol v6. * add e2e test for using both plugin protocol versions - copied grpcwrap and made a version that returns protocol v6 provider - copied the test provider, provider-simple, and made a version that's using protocol v6 with the above fun - added an e2etest
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package e2etest
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/e2e"
|
|
)
|
|
|
|
// TestProvisionerPlugin is a test that terraform can execute a 3rd party
|
|
// provisioner plugin.
|
|
func TestProvisionerPlugin(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// This test reaches out to releases.hashicorp.com to download the
|
|
// template and null providers, so it can only run if network access is
|
|
// allowed.
|
|
skipIfCannotAccessNetwork(t)
|
|
|
|
tf := e2e.NewBinary(terraformBin, "testdata/provisioner-plugin")
|
|
defer tf.Close()
|
|
|
|
// In order to do a decent end-to-end test for this case we will need a
|
|
// real enough provisioner plugin to try to run and make sure we are able
|
|
// to actually run it. Here will build the local-exec provisioner into a
|
|
// binary called test-provisioner
|
|
provisionerExePrefix := filepath.Join(tf.WorkDir(), "terraform-provisioner-test_")
|
|
provisionerExe := e2e.GoBuild("github.com/hashicorp/terraform/internal/provisioner-local-exec/main", provisionerExePrefix)
|
|
|
|
// provisioners must use the old binary name format, so rename this binary
|
|
newExe := filepath.Join(tf.WorkDir(), "terraform-provisioner-test")
|
|
if _, err := os.Stat(newExe); !os.IsNotExist(err) {
|
|
t.Fatalf("%q already exists", newExe)
|
|
}
|
|
if err := os.Rename(provisionerExe, newExe); err != nil {
|
|
t.Fatalf("error renaming provisioner binary: %v", err)
|
|
}
|
|
provisionerExe = newExe
|
|
|
|
t.Logf("temporary provisioner executable is %s", provisionerExe)
|
|
|
|
//// INIT
|
|
_, stderr, err := tf.Run("init")
|
|
if err != nil {
|
|
t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
|
|
}
|
|
|
|
//// PLAN
|
|
_, stderr, err = tf.Run("plan", "-out=tfplan")
|
|
if err != nil {
|
|
t.Fatalf("unexpected plan error: %s\nstderr:\n%s", err, stderr)
|
|
}
|
|
|
|
//// APPLY
|
|
stdout, stderr, err := tf.Run("apply", "tfplan")
|
|
if err != nil {
|
|
t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr)
|
|
}
|
|
|
|
if !strings.Contains(stdout, "HelloProvisioner") {
|
|
t.Fatalf("missing provisioner output:\n%s", stdout)
|
|
}
|
|
}
|