2023-05-10 09:02:25 +00:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os/exec"
|
|
|
|
"testing"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
2023-05-10 09:02:25 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadWithNoState(t *testing.T) {
|
|
|
|
_, err := exec.LookPath("terraform")
|
|
|
|
if err != nil {
|
|
|
|
t.Skipf("cannot find terraform binary: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b := &bundle.Bundle{
|
2024-09-27 10:03:05 +00:00
|
|
|
BundleRootPath: t.TempDir(),
|
2023-05-10 09:02:25 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Bundle: config.Bundle{
|
2023-08-17 15:22:32 +00:00
|
|
|
Target: "whatever",
|
2023-05-10 09:02:25 +00:00
|
|
|
Terraform: &config.Terraform{
|
|
|
|
ExecPath: "terraform",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Setenv("DATABRICKS_HOST", "https://x")
|
|
|
|
t.Setenv("DATABRICKS_TOKEN", "foobar")
|
|
|
|
b.WorkspaceClient()
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, bundle.Seq(
|
2023-05-10 09:02:25 +00:00
|
|
|
Initialize(),
|
2023-11-02 11:00:30 +00:00
|
|
|
Load(ErrorOnEmptyState),
|
2023-05-24 12:45:19 +00:00
|
|
|
))
|
2023-05-10 09:02:25 +00:00
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
require.ErrorContains(t, diags.Error(), "Did you forget to run 'databricks bundle deploy'")
|
2023-05-10 09:02:25 +00:00
|
|
|
}
|