mirror of
https://github.com/mcuadros/ascode
synced 2024-11-26 06:01:08 +01:00
terraform: allow skip provisioner test and proper error
This commit is contained in:
parent
fd709c4694
commit
af30b3e5d1
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
@ -18,5 +18,11 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Allow skip provisioner tests
|
||||||
|
uses: allenevans/set-env@v1.0.0
|
||||||
|
if: matrix.os != 'ubuntu-latest'
|
||||||
|
with:
|
||||||
|
ALLOW_PROVISIONER_SKIP: 1
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test ./...
|
run: go test ./...
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
stdos "os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mcuadros/ascode/starlark/module/os"
|
"github.com/mcuadros/ascode/starlark/module/os"
|
||||||
@ -33,6 +34,10 @@ func TestProvider(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestProvisioner(t *testing.T) {
|
func TestProvisioner(t *testing.T) {
|
||||||
|
if stdos.Getenv("ALLOW_PROVISIONER_SKIP") != "" && !terraform.IsTerraformBinaryAvailable() {
|
||||||
|
t.Skip("terraform binary now available in $PATH")
|
||||||
|
}
|
||||||
|
|
||||||
doTest(t, "testdata/provisioner.star")
|
doTest(t, "testdata/provisioner.star")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package terraform
|
package terraform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
@ -42,6 +43,10 @@ func (m *PluginManager) Provider(provider, version string, forceLocal bool) (*pl
|
|||||||
// try to locate it at the local Path, if not try to execute it from the
|
// try to locate it at the local Path, if not try to execute it from the
|
||||||
// built-in plugins in the terraform binary.
|
// built-in plugins in the terraform binary.
|
||||||
func (m *PluginManager) Provisioner(provisioner string) (*plugin.Client, discovery.PluginMeta, error) {
|
func (m *PluginManager) Provisioner(provisioner string) (*plugin.Client, discovery.PluginMeta, error) {
|
||||||
|
if !IsTerraformBinaryAvailable() {
|
||||||
|
return nil, discovery.PluginMeta{}, ErrTerraformNotAvailable
|
||||||
|
}
|
||||||
|
|
||||||
meta, ok := m.getLocal("provisioner", provisioner, "")
|
meta, ok := m.getLocal("provisioner", provisioner, "")
|
||||||
if ok {
|
if ok {
|
||||||
return client(meta), meta, nil
|
return client(meta), meta, nil
|
||||||
@ -121,3 +126,17 @@ func (m *PluginManager) getLocal(kind, provider, version string) (discovery.Plug
|
|||||||
|
|
||||||
return set.Newest(), true
|
return set.Newest(), true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrTerraformNotAvailable error used when `terraform` binary in not in the
|
||||||
|
// path and we try to use a provisioner.
|
||||||
|
var ErrTerraformNotAvailable = fmt.Errorf("provisioner error: executable file 'terraform' not found in $PATH")
|
||||||
|
|
||||||
|
// IsTerraformBinaryAvailable determines if Terraform binary is available in
|
||||||
|
// the path of the system. Terraform binary is a requirement for executing
|
||||||
|
// provisioner plugins, since they are built-in on the Terrafrom binary. :(
|
||||||
|
//
|
||||||
|
// https://github.com/hashicorp/terraform/issues/20896#issuecomment-479054649
|
||||||
|
func IsTerraformBinaryAvailable() bool {
|
||||||
|
_, err := exec.LookPath("terraform")
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@ package terraform
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -51,6 +52,10 @@ func TestPluginManager_ProviderDefault(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPluginManager_ProvisionerDefault(t *testing.T) {
|
func TestPluginManager_ProvisionerDefault(t *testing.T) {
|
||||||
|
if os.Getenv("ALLOW_PROVISIONER_SKIP") != "" && !IsTerraformBinaryAvailable() {
|
||||||
|
t.Skip("terraform binary now available in $PATH")
|
||||||
|
}
|
||||||
|
|
||||||
path, err := ioutil.TempDir("", "provisioner")
|
path, err := ioutil.TempDir("", "provisioner")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user