github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/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/hashicorp/terraform/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 if !canRunGoBuild { 16 // We're running in a separate-build-then-run context, so we can't 17 // currently execute this test which depends on being able to build 18 // new executable at runtime. 19 // 20 // (See the comment on canRunGoBuild's declaration for more information.) 21 t.Skip("can't run without building a new provisioner executable") 22 } 23 t.Parallel() 24 25 // This test reaches out to releases.hashicorp.com to download the 26 // template and null providers, so it can only run if network access is 27 // allowed. 28 skipIfCannotAccessNetwork(t) 29 30 tf := e2e.NewBinary(t, terraformBin, "testdata/provisioner-plugin") 31 32 // In order to do a decent end-to-end test for this case we will need a 33 // real enough provisioner plugin to try to run and make sure we are able 34 // to actually run it. Here will build the local-exec provisioner into a 35 // binary called test-provisioner 36 provisionerExePrefix := filepath.Join(tf.WorkDir(), "terraform-provisioner-test_") 37 provisionerExe := e2e.GoBuild("github.com/hashicorp/terraform/internal/provisioner-local-exec/main", provisionerExePrefix) 38 39 // provisioners must use the old binary name format, so rename this binary 40 newExe := filepath.Join(tf.WorkDir(), "terraform-provisioner-test") 41 if _, err := os.Stat(newExe); !os.IsNotExist(err) { 42 t.Fatalf("%q already exists", newExe) 43 } 44 if err := os.Rename(provisionerExe, newExe); err != nil { 45 t.Fatalf("error renaming provisioner binary: %v", err) 46 } 47 provisionerExe = newExe 48 49 t.Logf("temporary provisioner executable is %s", provisionerExe) 50 51 //// INIT 52 _, stderr, err := tf.Run("init") 53 if err != nil { 54 t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr) 55 } 56 57 //// PLAN 58 _, stderr, err = tf.Run("plan", "-out=tfplan") 59 if err != nil { 60 t.Fatalf("unexpected plan error: %s\nstderr:\n%s", err, stderr) 61 } 62 63 //// APPLY 64 stdout, stderr, err := tf.Run("apply", "tfplan") 65 if err != nil { 66 t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr) 67 } 68 69 if !strings.Contains(stdout, "HelloProvisioner") { 70 t.Fatalf("missing provisioner output:\n%s", stdout) 71 } 72 }