Do CheckRunningResource only after terraform.Write (#1292)

## Changes
CheckRunningResource does `terraform.Show` which (I believe) expects
valid `bundle.tf.json` which is only written as part of
`terraform.Write` later.

With this PR order is changed.

Fixes #1286 

## Tests
Added regression E2E test
This commit is contained in:
Andrew Nester 2024-03-18 16:39:18 +01:00 committed by GitHub
parent 1b0ac61093
commit d216404f27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 1 deletions

View File

@ -25,7 +25,6 @@ func Deploy() bundle.Mutator {
bundle.Seq(
terraform.StatePull(),
deploy.StatePull(),
deploy.CheckRunningResource(),
mutator.ValidateGitDetails(),
libraries.MatchWithArtifacts(),
artifacts.CleanUp(),
@ -36,6 +35,7 @@ func Deploy() bundle.Mutator {
permissions.ApplyWorkspaceRootPermissions(),
terraform.Interpolate(),
terraform.Write(),
deploy.CheckRunningResource(),
bundle.Defer(
terraform.Apply(),
bundle.Seq(

View File

@ -0,0 +1,43 @@
package bundle
import (
"os"
"path/filepath"
"testing"
"github.com/databricks/cli/internal"
"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/libs/env"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)
func TestAccBasicBundleDeployWithFailOnActiveRuns(t *testing.T) {
ctx, _ := acc.WorkspaceTest(t)
nodeTypeId := internal.GetNodeTypeId(env.Get(ctx, "CLOUD_ENV"))
uniqueId := uuid.New().String()
root, err := initTestTemplate(t, ctx, "basic", map[string]any{
"unique_id": uniqueId,
"node_type_id": nodeTypeId,
"spark_version": "13.2.x-snapshot-scala2.12",
})
require.NoError(t, err)
t.Cleanup(func() {
err = destroyBundle(t, ctx, root)
require.NoError(t, err)
})
// deploy empty bundle
err = deployBundleWithFlags(t, ctx, root, []string{"--fail-on-active-runs"})
require.NoError(t, err)
// Remove .databricks directory to simulate a fresh deployment
err = os.RemoveAll(filepath.Join(root, ".databricks"))
require.NoError(t, err)
// deploy empty bundle again
err = deployBundleWithFlags(t, ctx, root, []string{"--fail-on-active-runs"})
require.NoError(t, err)
}

View File

@ -56,6 +56,15 @@ func deployBundle(t *testing.T, ctx context.Context, path string) error {
return err
}
func deployBundleWithFlags(t *testing.T, ctx context.Context, path string, flags []string) error {
t.Setenv("BUNDLE_ROOT", path)
args := []string{"bundle", "deploy", "--force-lock"}
args = append(args, flags...)
c := internal.NewCobraTestRunnerWithContext(t, ctx, args...)
_, _, err := c.Run()
return err
}
func runResource(t *testing.T, ctx context.Context, path string, key string) (string, error) {
ctx = cmdio.NewContext(ctx, cmdio.Default())