github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/not-internal/command/e2etest/provisioner_plugin_test.go (about)

     1  package e2etest
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/muratcelep/terraform/not-internal/e2e"
    10  )
    11  
    12  // TestProvisionerPlugin is a test that terraform can execute a 3rd party
    13  // provisioner plugin.
    14  func TestProvisionerPlugin(t *testing.T) {
    15  	t.Parallel()
    16  
    17  	// This test reaches out to releases.hashicorp.com to download the
    18  	// template and null providers, so it can only run if network access is
    19  	// allowed.
    20  	skipIfCannotAccessNetwork(t)
    21  
    22  	tf := e2e.NewBinary(terraformBin, "testdata/provisioner-plugin")
    23  	defer tf.Close()
    24  
    25  	// In order to do a decent end-to-end test for this case we will need a
    26  	// real enough provisioner plugin to try to run and make sure we are able
    27  	// to actually run it. Here will build the local-exec provisioner into a
    28  	// binary called test-provisioner
    29  	provisionerExePrefix := filepath.Join(tf.WorkDir(), "terraform-provisioner-test_")
    30  	provisionerExe := e2e.GoBuild("github.com/muratcelep/terraform/not-internal/provisioner-local-exec/main", provisionerExePrefix)
    31  
    32  	// provisioners must use the old binary name format, so rename this binary
    33  	newExe := filepath.Join(tf.WorkDir(), "terraform-provisioner-test")
    34  	if _, err := os.Stat(newExe); !os.IsNotExist(err) {
    35  		t.Fatalf("%q already exists", newExe)
    36  	}
    37  	if err := os.Rename(provisionerExe, newExe); err != nil {
    38  		t.Fatalf("error renaming provisioner binary: %v", err)
    39  	}
    40  	provisionerExe = newExe
    41  
    42  	t.Logf("temporary provisioner executable is %s", provisionerExe)
    43  
    44  	//// INIT
    45  	_, stderr, err := tf.Run("init")
    46  	if err != nil {
    47  		t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
    48  	}
    49  
    50  	//// PLAN
    51  	_, stderr, err = tf.Run("plan", "-out=tfplan")
    52  	if err != nil {
    53  		t.Fatalf("unexpected plan error: %s\nstderr:\n%s", err, stderr)
    54  	}
    55  
    56  	//// APPLY
    57  	stdout, stderr, err := tf.Run("apply", "tfplan")
    58  	if err != nil {
    59  		t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr)
    60  	}
    61  
    62  	if !strings.Contains(stdout, "HelloProvisioner") {
    63  		t.Fatalf("missing provisioner output:\n%s", stdout)
    64  	}
    65  }